From 355517ff1cb1184a4a3dc348ae966db0593273ff Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Thu, 12 Dec 2013 20:22:24 +0100 Subject: [PATCH] refactor libs into non-gui and gui parts --- .gitignore | 2 +- basics.pri | 37 ++ iface/iface.pri | 11 + iface/iface.pro | 25 ++ iface/libs.pri | 18 + iface/misc/boxwrapper.cpp | 69 ++++ iface/misc/boxwrapper.h | 50 +++ iface/misc/cleanup.h | 37 ++ iface/misc/formula.cpp | 168 ++++++++++ iface/misc/formula.h | 28 ++ iface/misc/misc.cpp | 741 +++++++++++++++++++++++++++++++++++++++++ iface/misc/misc.h | 302 +++++++++++++++++ iface/misc/misc.pri | 11 + iface/msinterface.cpp | 289 ++++++++++++++++ iface/msinterface.h | 139 ++++++++ iface/sslexception.cpp | 117 +++++++ iface/sslexception.h | 62 ++++ iface/templates/templates.cpp | 423 +++++++++++++++++++++++ iface/templates/templates.h | 186 +++++++++++ iface/templates/templates.pri | 7 + iface/wext/MOAddress | 1 + iface/wext/MOCustomer | 1 + iface/wext/MOCustomerInfo | 1 + iface/wext/MOEvent | 1 + iface/wext/MOOrder | 1 + iface/wext/MOOrderInfo | 1 + iface/wext/MOTicket | 1 + iface/wext/MOVoucher | 1 + iface/wext/MTransaction | 1 + iface/wext/address.cpp | 46 +++ iface/wext/address.h | 41 +++ iface/wext/customer.cpp | 63 ++++ iface/wext/customer.h | 52 +++ iface/wext/customerinfo.cpp | 36 ++ iface/wext/customerinfo.h | 39 +++ iface/wext/event.cpp | 79 +++++ iface/wext/event.h | 61 ++++ iface/wext/order.cpp | 136 ++++++++ iface/wext/order.h | 119 +++++++ iface/wext/orderinfo.h | 52 +++ iface/wext/ticket.cpp | 55 +++ iface/wext/ticket.h | 64 ++++ iface/wext/transaction.cpp | 46 +++ iface/wext/transaction.h | 40 +++ iface/wext/voucher.h | 47 +++ iface/wext/wext.pri | 21 ++ mainapp/mainapp.pro | 23 +- pack | 2 +- src/iface/iface.pri | 9 - src/iface/msinterface.cpp | 241 ------------- src/iface/msinterface.h | 123 ------- src/iface/sslexception.cpp | 117 ------- src/iface/sslexception.h | 58 ---- src/libs.pri | 22 +-- src/main.cpp | 89 +++--- src/misc/cleanup.h | 33 -- src/misc/formula.cpp | 168 ---------- src/misc/formula.h | 24 -- src/misc/misc.cpp | 741 ----------------------------------------- src/misc/misc.h | 298 ----------------- src/misc/misc.pri | 4 - src/misc/waitcursor.cpp | 13 +- src/smoke.pro | 26 +-- src/templates/templatedlg.cpp | 37 +- src/templates/templatedlg.h | 6 +- src/templates/templates.cpp | 426 ----------------------- src/templates/templates.h | 174 ---------- src/templates/templates.pri | 2 - src/wext/MOAddress | 1 - src/wext/MOCustomer | 1 - src/wext/MOCustomerInfo | 1 - src/wext/MOEvent | 1 - src/wext/MOOrder | 1 - src/wext/MOOrderInfo | 1 - src/wext/MOTicket | 1 - src/wext/MOVoucher | 1 - src/wext/MTransaction | 1 - src/wext/address.cpp | 46 --- src/wext/address.h | 37 -- src/wext/customer.cpp | 63 ---- src/wext/customer.h | 48 --- src/wext/customerinfo.cpp | 36 -- src/wext/customerinfo.h | 34 -- src/wext/event.cpp | 79 ----- src/wext/event.h | 56 --- src/wext/order.cpp | 136 -------- src/wext/order.h | 114 ------- src/wext/orderinfo.h | 47 --- src/wext/ticket.cpp | 55 --- src/wext/ticket.h | 59 ---- src/wext/transaction.cpp | 26 -- src/wext/transaction.h | 30 -- src/wext/voucher.h | 42 --- src/wext/wext.pri | 21 -- wob/magicsmoke.wolf | 4 +- 95 files changed, 3819 insertions(+), 3487 deletions(-) create mode 100644 basics.pri create mode 100644 iface/iface.pri create mode 100644 iface/iface.pro create mode 100644 iface/libs.pri create mode 100644 iface/misc/boxwrapper.cpp create mode 100644 iface/misc/boxwrapper.h create mode 100644 iface/misc/cleanup.h create mode 100644 iface/misc/formula.cpp create mode 100644 iface/misc/formula.h create mode 100644 iface/misc/misc.cpp create mode 100644 iface/misc/misc.h create mode 100644 iface/misc/misc.pri create mode 100644 iface/msinterface.cpp create mode 100644 iface/msinterface.h create mode 100644 iface/sslexception.cpp create mode 100644 iface/sslexception.h create mode 100644 iface/templates/templates.cpp create mode 100644 iface/templates/templates.h create mode 100644 iface/templates/templates.pri create mode 100644 iface/wext/MOAddress create mode 100644 iface/wext/MOCustomer create mode 100644 iface/wext/MOCustomerInfo create mode 100644 iface/wext/MOEvent create mode 100644 iface/wext/MOOrder create mode 100644 iface/wext/MOOrderInfo create mode 100644 iface/wext/MOTicket create mode 100644 iface/wext/MOVoucher create mode 100644 iface/wext/MTransaction create mode 100644 iface/wext/address.cpp create mode 100644 iface/wext/address.h create mode 100644 iface/wext/customer.cpp create mode 100644 iface/wext/customer.h create mode 100644 iface/wext/customerinfo.cpp create mode 100644 iface/wext/customerinfo.h create mode 100644 iface/wext/event.cpp create mode 100644 iface/wext/event.h create mode 100644 iface/wext/order.cpp create mode 100644 iface/wext/order.h create mode 100644 iface/wext/orderinfo.h create mode 100644 iface/wext/ticket.cpp create mode 100644 iface/wext/ticket.h create mode 100644 iface/wext/transaction.cpp create mode 100644 iface/wext/transaction.h create mode 100644 iface/wext/voucher.h create mode 100644 iface/wext/wext.pri delete mode 100644 src/iface/iface.pri delete mode 100644 src/iface/msinterface.cpp delete mode 100644 src/iface/msinterface.h delete mode 100644 src/iface/sslexception.cpp delete mode 100644 src/iface/sslexception.h delete mode 100644 src/misc/cleanup.h delete mode 100644 src/misc/formula.cpp delete mode 100644 src/misc/formula.h delete mode 100644 src/misc/misc.cpp delete mode 100644 src/misc/misc.h delete mode 100644 src/templates/templates.cpp delete mode 100644 src/templates/templates.h delete mode 100644 src/wext/MOAddress delete mode 100644 src/wext/MOCustomer delete mode 100644 src/wext/MOCustomerInfo delete mode 100644 src/wext/MOEvent delete mode 100644 src/wext/MOOrder delete mode 100644 src/wext/MOOrderInfo delete mode 100644 src/wext/MOTicket delete mode 100644 src/wext/MOVoucher delete mode 100644 src/wext/MTransaction delete mode 100644 src/wext/address.cpp delete mode 100644 src/wext/address.h delete mode 100644 src/wext/customer.cpp delete mode 100644 src/wext/customer.h delete mode 100644 src/wext/customerinfo.cpp delete mode 100644 src/wext/customerinfo.h delete mode 100644 src/wext/event.cpp delete mode 100644 src/wext/event.h delete mode 100644 src/wext/order.cpp delete mode 100644 src/wext/order.h delete mode 100644 src/wext/orderinfo.h delete mode 100644 src/wext/ticket.cpp delete mode 100644 src/wext/ticket.h delete mode 100644 src/wext/transaction.cpp delete mode 100644 src/wext/transaction.h delete mode 100644 src/wext/voucher.h delete mode 100644 src/wext/wext.pri diff --git a/.gitignore b/.gitignore index b1d7698..8aa7caa 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ object_script* #generated sources, translations, docu doc/wob -src/wob +iface/wob www/inc/wob *.qm doc/source-cpp/ diff --git a/basics.pri b/basics.pri new file mode 100644 index 0000000..b014e21 --- /dev/null +++ b/basics.pri @@ -0,0 +1,37 @@ +#basic compile settings + +#put everything here: +DESTDIR = $$PWD/bin + +#hide classes that are not explicitly exported +# this is default on Windows, we have it here to have all systems behave the same way +CONFIG += hide_symbols +#use PRL files (link info) +CONFIG += create_prl link_prl +#put debug symbols in separate file (on linux) +CONFIG += separate_debug_info +#enable C++-11 features +CONFIG += c++11 + +#compilation output: +OBJECTS_DIR = .ctmp +MOC_DIR = .ctmp +RCC_DIR = .ctmp + +#make sure libs are found +LIBS += -L$$PWD/bin + +#protect the stack +QMAKE_CFLAGS += -fstack-protector-all -Wstack-protector +QMAKE_CXXFLAGS += -fstack-protector-all -Wstack-protector + +#ASLR for windows +win32 { + QMAKE_LFLAGS += -Wl,--nxcompat -Wl,--dynamicbase + LIBS += -lssp +} + +linux-g++* { + #make sure we find our libs + QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN\' +} diff --git a/iface/iface.pri b/iface/iface.pri new file mode 100644 index 0000000..5036fe0 --- /dev/null +++ b/iface/iface.pri @@ -0,0 +1,11 @@ +#Include PRI for the interface library non-GUI parts + +LIBS += -lmagicsmoke-iface +INCLUDEPATH += \ + $$PWD/../iface/wob \ + $$PWD/../iface/wext \ + $$PWD/../iface/misc \ + $$PWD/../iface/templates \ + $$PWD/../iface + +include ($$PWD/libs.pri) diff --git a/iface/iface.pro b/iface/iface.pro new file mode 100644 index 0000000..bf315e2 --- /dev/null +++ b/iface/iface.pro @@ -0,0 +1,25 @@ +TEMPLATE = lib +TARGET = magicsmoke-iface +VERSION = +QT-=gui + +#make sure exports are ok +DEFINES += MSIFACE_EXPORT=Q_DECL_EXPORT + +include (../basics.pri) +include (libs.pri) + +include (wob/wob.pri) +include (wext/wext.pri) +include (misc/misc.pri) +include (templates/templates.pri) + +HEADERS += \ + msinterface.h \ + sslexception.h + +SOURCES += \ + msinterface.cpp \ + sslexception.cpp + +INCLUDEPATH += $$PWD \ No newline at end of file diff --git a/iface/libs.pri b/iface/libs.pri new file mode 100644 index 0000000..1cd0c66 --- /dev/null +++ b/iface/libs.pri @@ -0,0 +1,18 @@ +# Libraries for Magic Smoke by (c) Konrad Rosenbaum, 2007-2013 + +# PACK library +LIBS += -lqwbase +INCLUDEPATH += $$PWD/../pack/qtbase/include + +# Time Zone DB library +LIBS += -lQtTzData +INCLUDEPATH += $$PWD/../tzone/include + +# ELAM library +include($$PWD/../taurus/elam.pri) + +# Chester DPtr library +include($$PWD/../taurus/chester.pri) + +#make sure the correct Qt DLLs are used +QT += xml network script diff --git a/iface/misc/boxwrapper.cpp b/iface/misc/boxwrapper.cpp new file mode 100644 index 0000000..8b26a3e --- /dev/null +++ b/iface/misc/boxwrapper.cpp @@ -0,0 +1,69 @@ +// +// C++ Implementation: Message Box Wrapper +// +// Author: Konrad Rosenbaum , (C) 2013 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "boxwrapper.h" +#include + +MBoxWrapper::Wrapper MBoxWrapper::mwarn=nullptr; + +void MBoxWrapper::warning(QString title, QString text) +{ + if(mwarn!=nullptr) + mwarn(title,text); + else + qDebug()<<"Hidden Box Warning:"<max)min=max; + setValue(val); + } + virtual void setValue(int v) + { + int old=val; + val=v; + if(valmax)val=max; + if(val!=old)output(); + } +}; + + +MProgressWrapper* MProgressWrapper::create(QString label, QString buttonlabel) +{ + if(prgfac==nullptr)return new MProgressWrapperDebug(label); + else return prgfac(label,buttonlabel); +} + +void MProgressWrapper::setFactory(Factory f) +{ + prgfac=f; +} diff --git a/iface/misc/boxwrapper.h b/iface/misc/boxwrapper.h new file mode 100644 index 0000000..56fbf9c --- /dev/null +++ b/iface/misc/boxwrapper.h @@ -0,0 +1,50 @@ +// +// C++ Interface: Message Box Wrapper +// +// Author: Konrad Rosenbaum , (C) 2013 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MSINTERFACE_BOXWRAPPER_H +#define MSINTERFACE_BOXWRAPPER_H + +#include +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MBoxWrapper +{ + public: + typedef std::functionWrapper; + + static void warning(QString title,QString text); + static void setWarning(Wrapper); + private: + static Wrapper mwarn; + MBoxWrapper()=default; +}; + +class MSIFACE_EXPORT MProgressWrapper:public QObject +{ + Q_OBJECT + public: + typedef std::functionFactory; + static void setFactory(Factory); + + static MProgressWrapper* create(QString label,QString buttonlabel=QString()); + public slots: + virtual void setLabelText(QString)=0; + virtual void setCancelButtonText(QString)=0; + virtual void cancel()=0; + virtual void setRange(int,int)=0; + virtual void setValue(int)=0; +}; + +#endif diff --git a/iface/misc/cleanup.h b/iface/misc/cleanup.h new file mode 100644 index 0000000..d7a6f39 --- /dev/null +++ b/iface/misc/cleanup.h @@ -0,0 +1,37 @@ +// +// C++ Interface: misc +// +// Description: miscellaneous helper functions +// +// +// Author: Konrad Rosenbaum , (C) 2012 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_LAMBDACLEAN_H +#define MAGICSMOKE_LAMBDACLEAN_H + +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +///clean-up function: executes a lambda expression when it is destructed (i.e. when the instance leaves its scope +class MSIFACE_EXPORT MCleanup +{ + std::functionm_ptr; + public: + ///instantiates a new cleanup object and remembers the given function for later execution + MCleanup(const std::function&f):m_ptr(f){} + + ///sets a new cleanup function, removing the old one + void setFunction(const std::function&f){m_ptr=f;} + + ///destructs the object and executes the cleanup function + ~MCleanup(){if(m_ptr)m_ptr();} +}; + +#endif diff --git a/iface/misc/formula.cpp b/iface/misc/formula.cpp new file mode 100644 index 0000000..98fa79c --- /dev/null +++ b/iface/misc/formula.cpp @@ -0,0 +1,168 @@ +// +// C++ Implementation: magicsmoke ELAM adaptation +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "formula.h" +#include "misc.h" + +#include +#include + +#include +#include +#include +#include + +using namespace ELAM; + +inline static QVariant toMoneyFunc(const QList&lf,bool local) +{ + if(lf.size()!=1) + return Exception(Exception::ArgumentListError, "expecting exactly one argument"); + if(!lf[0].canConvert()) + return Exception(Exception::TypeMismatchError,"cannot convert to int"); + return cent2str(lf[0].toLongLong(),local); +} +static QVariant toMoneyFuncLoc(const QList&lf,Engine&){return toMoneyFunc(lf,true);} +static QVariant toMoneyFuncNLoc(const QList&lf,Engine&){return toMoneyFunc(lf,false);} + +inline static QVariant fromMoneyFunc(const QList&lf,bool local) +{ + if(lf.size()!=1) + return Exception(Exception::ArgumentListError, "expecting exactly one argument"); + if(!lf[0].canConvert()) + return Exception(Exception::TypeMismatchError,"cannot convert to string"); + return str2cent(lf[0].toString(),local); +} +static QVariant fromMoneyFuncLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,true);} +static QVariant fromMoneyFuncNLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,false);} + +inline static QVariant unix2DTFunc(const QList&args,int mode) +{ + if(args.size()<1 || args.size()>2) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 or 2 arguments"); + if(!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 1 must be int"); + qint64 tm=args[0].toLongLong(); + bool loc=true; + if(args.size()>1){ + if(!args[1].canConvert()) + return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 2 must be boolean"); + loc=args[1].toBool(); + } + switch(mode){ + case 0:return unix2date(tm,loc); + case 1:return unix2time(tm,loc); + default:return unix2dateTime(tm,loc); + } +} +static QVariant unix2DateFunc(const QList&args,Engine&){return unix2DTFunc(args,0);} +static QVariant unix2TimeFunc(const QList&args,Engine&){return unix2DTFunc(args,1);} +static QVariant unix2DateTimeFunc(const QList&args,Engine&){return unix2DTFunc(args,2);} + +static QVariant nullintCast(const QVariant&orig,const Engine&) +{ + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return (qlonglong)ni.value(); + } + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return (qlonglong)ni.value(); + } + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return (qlonglong)ni.value(); + } + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return (qlonglong)ni.value(); + } + return orig; +} + +static QVariant nullstrCast(const QVariant&orig,const Engine&) +{ + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return ni.value(); + } + return orig; +} + +static QVariant nullboolCast(const QVariant&orig,const Engine&) +{ + if(orig.userType()==qMetaTypeId >()){ + Nullable ni=orig.value >(); + if(ni.isNull())return QVariant(); + else return ni.value(); + } + return orig; +} + +MElamEngine::MElamEngine(QObject* parent): Engine(parent) +{ + //configure character classes + QString alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; + characterClasses().setNameClass(alpha,alpha+"0123456789.:"); + QString oc=characterClasses().operatorClass(); + characterClasses().setOperatorClass(oc.remove('.').remove(':')); + characterClasses().setAssignmentChars('\0','='); + if(!characterClasses().isConsistent()) + qDebug()<<"Warning: built-in calculator is inconsistent."; + //load default engines + IntEngine::configureIntEngine(*this); + FloatEngine::configureFloatEngine(*this); + BoolEngine::configureBoolEngine(*this); + BoolEngine::configureLogicEngine(*this); + StringEngine::configureStringEngine(*this); + configureReflection(*this); + //add money class + setFunction("toMoney",toMoneyFuncLoc); + setFunction("toMoneyLocal",toMoneyFuncLoc); + setFunction("toMoneyNL",toMoneyFuncNLoc); + setFunction("fromMoney",fromMoneyFuncLoc); + setFunction("fromMoneyLocal",fromMoneyFuncLoc); + setFunction("fromMoneyNL",fromMoneyFuncNLoc); + //add datetime conversion + setFunction("unix2date",unix2DateFunc); + setFunction("unix2time",unix2TimeFunc); + setFunction("unix2datetime",unix2DateTimeFunc); + //legacy functions for ODF renderer + setFunction("cent2str",[](const QList&args,Engine&)->QVariant{ + if(args.size()!=1) + return Exception(Exception::ArgumentListError,"expected one argument to cent2str"); + else + return cent2str(args[0].toInt()); + }); + setFunction("str2cent",[](const QList&args,Engine&)->QVariant{ + if(args.size()!=1) + return Exception(Exception::ArgumentListError,"expected one argument to str2cent"); + else + return str2cent(args[0].toString()); + }); + //register casts for nullable + setAutoCast(qMetaTypeId(), + QList() + < >() + < >() + < >() + < >(), + nullintCast + ); + setAutoCast(qMetaTypeId(),QList()< >(), nullstrCast); + setAutoCast(qMetaTypeId(),QList()< >(), nullboolCast); +} diff --git a/iface/misc/formula.h b/iface/misc/formula.h new file mode 100644 index 0000000..7241b47 --- /dev/null +++ b/iface/misc/formula.h @@ -0,0 +1,28 @@ +// +// C++ Interface: magicsmoke ELAM adaptation +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_ELAM_H +#define MAGICSMOKE_ELAM_H + +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +class MSIFACE_EXPORT MElamEngine:public ELAM::Engine +{ + public: + MElamEngine(QObject*parent=0); +}; + +#endif diff --git a/iface/misc/misc.cpp b/iface/misc/misc.cpp new file mode 100644 index 0000000..572385c --- /dev/null +++ b/iface/misc/misc.cpp @@ -0,0 +1,741 @@ +// +// C++ Implementation: misc +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "misc.h" + +#include + +#include + +#include "MOServerFormat" + +#include +#include +#include +#include +#include + +QString htmlize(QString str) +{ + QString out; + for(int i=0;i')out+=">";else + if(c=='&')out+="&";else + if(c=='\n')out+="
\n";else + if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c; + else out+="&#"+QString::number(ci)+";"; + } + return out; +} + +QString xmlize(QString str,QString newline) +{ + QString out; + for(int i=0;i')out+=">";else + if(c=='&')out+="&";else + if(c=='\n')out+=newline;else + if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c; + else out+="&#"+QString::number(ci)+";"; + } + return out; +} +QByteArray xmlize(QByteArray str,QString newline) +{ + QByteArray out; + for(int i=0;i')out+=">";else + if(c=='&')out+="&";else + if(c=='\n')out+=newline;else + if(QChar(c).isSpace()||(c>=32 && static_cast(c)<=0x7f))out+=c; + else out+="&#"+QString::number((unsigned char)c)+";"; + } + return out; +} + +QString cent2str(qint64 c,bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.formatMoney(c); +} + +qint64 str2cent(QString s,bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.scanMoney(s); +} + +QRegExp priceRegExp(bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.moneyRegExp(false,false); +} + +QString unix2date(qint64 tm,bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.formatDate(tm); +} + +QString unix2time(qint64 tm,bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.formatTime(tm); +} + +QString unix2dateTime(qint64 tm,bool localize) +{ + MLocalFormat mf; + if(!localize)mf.setNonLocalized(); + return mf.formatDateTime(tm); +} + +// ///////////////////////////////////// +// local formatting class +#include +class MLocalFormat::Private:public SharedDPtr +{ + public: + QStringList m_day,m_sday,m_month,m_smonth; + QString m_am,m_pm,m_timezone,m_dateformat,m_timeformat,m_datetimeformat; + QChar m_decimal,m_thousand; + + QString m_currency,m_moneyneg,m_moneypos; + int m_moneydecimals,m_thousanddigits; + bool m_moneysymbehind; + MOServerFormat::MoneyPos m_moneynegpos,m_moneypospos; +}; +DEFINE_SHARED_DPTR(MLocalFormat); + +//static +MLocalFormat MLocalFormat::defaultformat((int)1); + +MLocalFormat::MLocalFormat(int) +{ + d->m_moneydecimals=2; + d->m_thousanddigits=3; + d->m_timezone="UTC"; + d->m_am="AM"; + d->m_pm="PM"; + //set defaults + setWeekDays();setShortWeekDays(); + setMonths();setShortMonths(); + setMoneyFormat();setNumberFormat(); + setDateTimeFormat(); +} + +MLocalFormat::MLocalFormat(const MOServerFormat& s) +{ + //init from current default + operator=(defaultformat); + //overwrite with new settings + QStringList sl; + sl=s.weekdays();if(sl.size()==7)setWeekDays(sl);else setWeekDays(); + sl=s.shortweekdays();if(sl.size()==7)setShortWeekDays(sl);else setShortWeekDays(); + sl=s.months();if(sl.size()==12)setMonths(sl);else setMonths(); + sl=s.shortmonths();if(sl.size()==12)setShortMonths(sl);else setShortMonths(); + setMoneyFormat(s.currencysymbol(),s.moneydecimals(),s.currencysymbolpos()); + setMoneySign(s.moneynegative(),s.moneypositive(),s.moneynegativepos(),s.moneypositivepos()); + setNumberFormat(s.decimaldot().value().at(0), s.thousandseparator().value().at(0), s.thousanddigits().value()); + setAP(s.amtext(),s.pmtext()); + setTimeZone(s.timezone()); + setDateTimeFormat(s.dateformat(),s.timeformat(),s.datetimeformat()); +} + +QStringList MLocalFormat::weekDayNames()const{return d->m_day;} +QStringList MLocalFormat::shortWeekDayNames()const{return d->m_sday;} +QStringList MLocalFormat:: monthNames()const{return d->m_month;} +QStringList MLocalFormat::shortMonthNames()const{return d->m_smonth;} +QString MLocalFormat::currency()const{return d->m_currency;} +QChar MLocalFormat::decimalDot()const{return d->m_decimal;} +QString MLocalFormat::thousandSeparator()const +{ + if(d->m_thousanddigits>0) + return d->m_thousand; + else return ""; +} +int MLocalFormat::thousandDigits()const{return d->m_thousanddigits;} +int MLocalFormat::moneyDecimals()const{return d->m_moneydecimals;} +QString MLocalFormat::amText()const{return d->m_am;} +QString MLocalFormat::pmText()const{return d->m_pm;} +QString MLocalFormat::moneyNegativeSign()const{return d->m_moneyneg;} +QString MLocalFormat::moneyPositiveSign()const{return d->m_moneypos;} +QString MLocalFormat::dateFormat()const{return d->m_dateformat;} +QString MLocalFormat::timeFormat()const{return d->m_timeformat;} +QString MLocalFormat::dateTimeFormat()const{return d->m_datetimeformat;} +QString MLocalFormat::timeZone()const{return d->m_timezone;} + +//static +void MLocalFormat::setDefaultFormat(const MLocalFormat& f) +{ + defaultformat=f; + TimeStamp::setDefaultZone(f.d->m_timezone); +} + + +MLocalFormat::MLocalFormat() +{ + operator=(defaultformat); +} + + +void MLocalFormat::setWeekDays(const QStringList&w) +{ + d.decouple(); + if(w.size()==0){ + d->m_day=QStringList() + <m_day=w; +} +void MLocalFormat::setShortWeekDays(const QStringList&w) +{ + d.decouple(); + if(w.size()==0){ + d->m_sday=QStringList() + <m_sday=w; +} +void MLocalFormat::setMonths(const QStringList&m) +{ + d.decouple(); + if(m.size()==0){ + d->m_month=QStringList() + <m_month=m; +} +void MLocalFormat::setShortMonths(const QStringList&m) +{ + d.decouple(); + if(m.size()==0){ + d->m_smonth=QStringList() + <m_smonth=m; +} + +void MLocalFormat::setDateTimeFormat(QString dateformat, QString timeformat, QString datetimeformat) +{ + d.decouple(); + if(dateformat=="")d->m_dateformat=QCoreApplication::translate("MLocalFormat","%Y-%M-%D","date format"); + else d->m_dateformat=dateformat; + if(timeformat=="")d->m_timeformat=QCoreApplication::translate("MLocalFormat","%h:%I","time format"); + else d->m_timeformat=timeformat; + if(datetimeformat=="")d->m_datetimeformat=QCoreApplication::translate("MLocalFormat","%Y-%M-%D %h:%I","date and time format"); + else d->m_datetimeformat=datetimeformat; +} + + +void MLocalFormat::setMoneyFormat(QString c,int n,bool s) +{ + d.decouple(); + d->m_currency=c; + d->m_moneydecimals=n; + d->m_moneysymbehind=s; +} + +void MLocalFormat::setMoneySign(QString n,QString p, MOServerFormat::MoneyPos np, MOServerFormat::MoneyPos pp) +{ + d.decouple(); + d->m_moneyneg=n;d->m_moneypos=p; + d->m_moneynegpos=np;d->m_moneypospos=pp; +} + +void MLocalFormat::setAP(QString am,QString pm) +{ + d.decouple(); + + if(am=="--")d->m_am=QCoreApplication::translate("MLocalFormat","am","AM/PM time component"); + else d->m_am=am; + if(pm=="--")d->m_pm=QCoreApplication::translate("MLocalFormat","pm","AM/PM time component"); + else d->m_pm=pm; +} + +void MLocalFormat::setNumberFormat(QChar dec,QChar thou,int dig) +{ + d.decouple(); + + if(dec.isNull())d->m_decimal=QCoreApplication::translate("MLocalFormat",".","decimal dot")[0]; + else d->m_decimal=dec; + + if(thou.isNull())d->m_thousand=QCoreApplication::translate("MLocalFormat",",","thousand division character")[0]; + else d->m_thousand=thou; + + if(dig<0)d->m_thousanddigits=QCoreApplication::translate("MLocalFormat","0","digits between thousand division chars, <=0 means none").toInt(); + else d->m_thousanddigits=dig; +} + +void MLocalFormat::setNonLocalized() +{ + d.decouple(); + //reset number format + d->m_decimal='.';d->m_thousanddigits=0; + //reset money signs + setMoneyFormat();setMoneySign(); +} + + +QString MLocalFormat::formatDate(const QDate&date,QString format)const +{ + return formatDate(TimeStamp(date,d->m_timezone),format); +} +QString MLocalFormat::formatDate(const TimeStamp& date, QString format) const +{ + if(format=="")format=d->m_dateformat; + return formatDateTime(date,format); +} +QString MLocalFormat::formatDate(qint64 date,QString format)const +{ + return formatDate(TimeStamp(date,d->m_timezone),format); +} +QString MLocalFormat::formatTime(const TimeStamp& time, QString format) const +{ + if(format=="")format=d->m_timeformat; + return formatDateTime(time,format); +} +QString MLocalFormat::formatTime(const QTime&time,QString format)const +{ + return formatTime(TimeStamp(time,d->m_timezone),format); +} +QString MLocalFormat::formatTime(qint64 time,QString format)const +{ + return formatTime(TimeStamp(time,d->m_timezone),format); +} +QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const +{ + return formatDateTime(TimeStamp(time,d->m_timezone),format); +} +QString MLocalFormat::formatDateTime(const TimeStamp& ts, QString format) const +{ + if(format=="")format=d->m_datetimeformat; + //parse + TimeStamp time=ts.toZone(d->m_timezone); + QString out; + bool inp=false; + for(int i=0;im_smonth.value(time.month()-1);break; + case 'N':out+=d->m_month.value(time.month()-1);break; + case 'd':out+=QString::number(time.day());break; + case 'D':{ + QString m=QString::number(time.day()); + if(m.size()<2)m="0"+m; + out+=m; + break; + } + case 'w':out+=d->m_sday.value(time.weekDay());break; + case 'W':out+=d->m_day.value(time.weekDay());break; + //time formats + case 'h':out+=QString::number(time.hour());break; + case 'H':{ + QString t=QString::number(time.hour()); + if(t.size()<2)t="0"+t; + out+=t; + break; + } + case 'i':out+=QString::number(time.minute());break; + case 'I':{ + QString t=QString::number(time.minute()); + if(t.size()<2)t="0"+t; + out+=t; + break; + } + case 's':out+=QString::number(time.second());break; + case 'S':{ + QString t=QString::number(time.second()); + if(t.size()<2)t="0"+t; + out+=t; + break; + } + case 'z':out+=QString::number(time.msecs());break; + case 'Z':{ + QString t=QString::number(time.msecs()); + while(t.size()<3)t="0"+t; + out+=t; + break; + } + case 'a':{ + int t=time.hour()%12;if(t==0)t=12; + out+=QString::number(t); + break; + } + case 'A':{ + int th=time.hour()%12;if(th==0)th=12; + QString t=QString::number(th); + if(t.size()<2)t="0"+t; + out+=t; + break; + } + case 'p':{ + int t=time.hour(); + if(t>=1 && t<=12)out+=d->m_am.toLower(); + else out+=d->m_pm.toLower(); + break; + } + case 'P':{ + int t=time.hour(); + if(t>=1 && t<=12)out+=d->m_am; + else out+=d->m_pm; + break; + } + case 't': + case 'T':{ + //get diff from UTC + int d=time.offsetFromUTC()/60; + //west(-) or east(+)? + QString t; + if(d<0){t="-";d*=-1;}else t="+"; + //append + out+=QString("%1%2:%3") + .arg(t) + .arg(int(d/60),2,10,QChar('0')) + .arg(int(d%60),2,10,QChar('0')); + break; + } + case 'o':out+=time.zoneAbbreviation();break; + case 'O':out+=d->m_timezone;break; + // % sign + case '%':out+="%";break; + //mistakes + default:out+="%"+format[i];break; + } + inp=false; + }else{ + if(format[i]=='%')inp=true; + else out+=format[i]; + } + } + //catch mistaken % at end + if(inp)out+="%"; + //return result + return out; +} + +QString MLocalFormat::formatDateTime(qint64 time,QString format)const +{ + return formatDateTime(TimeStamp(time,d->m_timezone),format); +} + +QString MLocalFormat::formatNumber(qint64 n)const +{ + //shortcut if we use standard format anyway + if(d->m_thousanddigits<=0)return QString::number(n); + //convert number to decimals + bool neg=false; + if(n<0){n*=-1;neg=true;} + QString s=QString::number(n); + //insert dividers + QString r; + int l=s.size(); + for(int i=0;i0 && ((l-i)%d->m_thousanddigits)==0)r+=d->m_thousand; + r+=s[i]; + } + if(neg)r="-"+r; + return r; +} + +QString MLocalFormat::formatNumber(double num,uint decimals)const +{ + //check negative + bool neg=false; + if(num<0.){num*=-1.;neg=true;} + //before the dot + qint64 be=floorl(num); + QString r=formatNumber(be); + //fractions + if(decimals>0){ + r+=d->m_decimal; + num-=be; + for(int i=0;i<(int)decimals;i++){ + num*=10.; + int d=floorl(num); + r+=QString::number(d); + num-=d; + } + } + //add negative sign + if(neg)r="-"+r; + //result + return r; +} + +QString MLocalFormat::formatMoney(qint64 num,bool usethousand)const +{ + return formatMoney(num,(usethousand?UseThousand:0)|ShowCurrencySymbol); +} + + +QString MLocalFormat::formatMoney(qint64 num, MLocalFormat::MoneyFlags flags) const +{ + //check value + bool neg=false; + if(num<0){num*=-1;neg=true;} + //split main and fraction + qint64 mod=1;for(int i=0;im_moneydecimals;i++)mod*=10; + qint64 frac=num%mod; + num/=mod; + //create main unit + QString ms; + if(flags&UseThousand)ms=formatNumber(num); + else ms=QString::number(num); + //create fractional unit + QString fs=QString::number(frac); + for(int i=fs.size();im_moneydecimals;i++)fs="0"+fs; + //combine and get currency symbol + QString r=ms+d->m_decimal+fs; + QString curr; + if(flags&ShowCurrencySymbol)curr=d->m_currency; + //add sign + QString sign; + if(neg)sign=d->m_moneyneg; + else sign=d->m_moneypos; + switch(neg?d->m_moneynegpos:d->m_moneypospos){ + case MOServerFormat::NoSign:break; + case MOServerFormat::SignParen:r="("+r+")";break; + case MOServerFormat::SignAfterSym:curr+=sign;break; + case MOServerFormat::SignBeforeSym:curr=sign+curr;break; + case MOServerFormat::SignAfterNum:r+=sign;break; + case MOServerFormat::SignBeforeNum: + default: + r=sign+r; + break; + } + //add currency + if(!curr.isEmpty()){ + if(d->m_moneysymbehind)r+=" "+curr; + else r=curr+" "+r; + } + //return result + return r; +} + +qint64 MLocalFormat::scanInt(QString num)const +{ + num=num.trimmed(); + qint64 r=0; + bool neg=false; + for(int i=0;im_thousand)continue; + //non-numericals break + else break; + } + if(neg)r*=-1; + return r; +} +qint64 MLocalFormat::scanMoney(QString num)const +{ + //init + num=num.trimmed(); + qint64 r=0,dd=0,nd=0; + bool neg=false,frc=false; + //scan string; r=main unit; d=fractions + for(int i=0;im_moneyneg.contains(c) || c=='-')neg=true;else + //decimal dot + if(c==d->m_decimal)frc=true;else + //digits + if(c.isDigit()){ + if(frc){ + if(nd>=d->m_moneydecimals)break; + dd*=10;dd+=c.digitValue(); + nd++; + }else{ + r*=10;r+=c.digitValue(); + } + }else + //ignore thousand divider + if(c==d->m_thousand)continue; + //non-numericals break + else break; + } + //move main to left + for(int i=0;im_moneydecimals;i++)r*=10; + //add fractions + for(;ndm_moneydecimals;nd++)dd*=10; + r+=dd; + //negative? + if(neg)r*=-1; + //result + return r; +} + +double MLocalFormat::scanFloat(QString num)const +{ + //init + num=num.trimmed(); + double r=0.; + double ff=1.; + bool neg=false,frc=false; + //scan + for(int i=0;im_decimal)frc=true;else + //digits + if(c.isDigit()){ + if(frc){ + ff/=10.; + r+=c.digitValue()*ff; + }else{ + r*=10.; + r+=c.digitValue(); + } + }else + //ignore thousand divider + if(c==d->m_thousand)continue; + //non-numericals break + else break; + } + //return + if(neg)r*=-1.; + return r; +} + +QRegExp MLocalFormat::moneyRegExp(bool allownegative,bool allowcurrency)const +{ + //main unit + QString r="[\\d"+QRegExp::escape(d->m_thousand)+"]+"; + //fractions + if(d->m_moneydecimals>0){ + r+=QRegExp::escape(d->m_decimal); + r+="\\d{"+QString::number(d->m_moneydecimals)+"}"; + } + //negative + if(allownegative){ + //front + QString f="[-"; + if(d->m_moneyneg.size()>0) + if(d->m_moneyneg[0]!='\n' && d->m_moneyneg[0]!='-') + f+=QRegExp::escape(d->m_moneyneg[0]); + f+="]?"; + r=f+r; + //back + if(d->m_moneyneg.size()>1) + r+=QRegExp::escape(d->m_moneyneg[1])+"?"; + } + //currency + if(allowcurrency && d->m_currency!="") + r+="("+QRegExp::escape(d->m_currency)+")?"; + //return + return QRegExp(r); +} + +void MLocalFormat::setTimeZone(QString olsonname) +{ + d.decouple(); + if(TimeStamp::loadZone(olsonname)) + d->m_timezone=olsonname; +} + +QString currentDir() +{ + return QSettings().value("lastUsedDirectory",".").toString(); +} + +void setCurrentDir(QString fn) +{ + if(fn.isEmpty())return; + QFileInfo fi(fn); + //it is already a directory + if(fi.isDir())QSettings().setValue("lastUsedDirectory",fi.absoluteFilePath()); + //it is probably a file + else { + //get parent directory name + fn=fi.dir().absolutePath(); + if(QFileInfo(fn).isDir()) + QSettings().setValue("lastUsedDirectory",fn); + //abort if not found by now, this was bogus + } +} diff --git a/iface/misc/misc.h b/iface/misc/misc.h new file mode 100644 index 0000000..685456a --- /dev/null +++ b/iface/misc/misc.h @@ -0,0 +1,302 @@ +// +// C++ Interface: misc +// +// Description: miscellaneous helper functions +// +// +// Author: Konrad Rosenbaum , (C) 2008-2012 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MISC_H +#define MAGICSMOKE_MISC_H + +#include +#include +#include +#include + +class TimeStamp; +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +/**converts special HTML characters into harmless &-codes, so the text can be included*/ +QString MSIFACE_EXPORT htmlize(QString str); + +/**converts special XML characters into harmless &-codes, so the text can be included*/ +QString MSIFACE_EXPORT xmlize(QString str,QString newline="\n"); +/**converts special XML characters into harmless &-codes, so the text can be included*/ +QByteArray MSIFACE_EXPORT xmlize(QByteArray str,QString newline="\n"); + +/**converts a cent value into a (localized) string*/ +QString MSIFACE_EXPORT cent2str(qint64 cent,bool localize=true); + +/**converts a (localized) string back into a cent value (must not contain spaces or extra dots)*/ +qint64 MSIFACE_EXPORT str2cent(QString s,bool fromlocal=true); + +/**converts a unix timestamp into a date*/ +QString MSIFACE_EXPORT unix2date(qint64,bool localize=true); + +/**converts a unix timestamp into a time (ommitting the date)*/ +QString MSIFACE_EXPORT unix2time(qint64,bool localize=true); + +/**converts a unix timestamp into a date-time-string*/ +QString MSIFACE_EXPORT unix2dateTime(qint64,bool localize=true); + +/**return a (localized) regular expression that validates prices*/ +QRegExp MSIFACE_EXPORT priceRegExp(bool localize=true); + +///returns the current directory (the one last used in a file dialog) +QString MSIFACE_EXPORT currentDir(); + +///sets a new current directory (transparently handles files and directories) +void MSIFACE_EXPORT setCurrentDir(QString); + +/**localized formatter class for timestamps, numbers and money; +per default it uses the local translation to format data, but can be overidden; + +date values can be formatted with the following variables: + + + + + + + + + + + +
%%ytwo-digit year (eg. 08)
%%Yfour-digit year (eg. 1908)
%%mmonth as simple number (eg. 7)
%%Mmonth as two digit number (eg. 07)
%%nshort name of the month (eg. Jul)
%%Nlong name of the month (eg. July)
%%dday of the month as simple number (eg. 5)
%%Dday of the month as two digit number (eg. 05)
%%wday of the week as short name (eg. Wed)
%%Wday of the week as long name (eg. Wednesday)
+ +time values can be formatted with the following variables: + + + + + + + + + + + + + + + + + +
%%hhour as simple number (eg. 7) in 24-hour format
%%Hhour as two digit number (eg. 07) in 24-hour format
%%ahour as simple number (eg. 7) in 12-hour format
%%Ahour as two digit number (eg. 07) in 12-hour format
%%iminute as simple number (eg. 7)
%%Iminute as two digit number (eg. 07)
%%ssecond as simple number (eg. 7)
%%Ssecond as two digit number (eg. 07)
%%zmilli-seconds as simple number (eg. 7)
%%Zmilli-seconds as three digit number (eg. 007)
%%p"am" or "pm" according to current time, this is the one set with setAP
%%P"AM" or "PM" according to current time, this is toUpper executed on the one set with setAP
%%TISO timezone as +/-hhmm (eg. -0100 or +0100)
%%tISO timezone as +/-hh:mm (eg. -01:00 or +01:00)
%%otimezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET")
%%Otimezone as Olson name (eg. "Europe/Berlin")
+ +Any occurrence of "%%" will be translated to a literal "%" sign. + +For example "%w the %d'th of %N in the year of the lord %Y at %a:%I %P" will be formatted as "Sat 19'th of June in the year of the lord 2010 at 8:29 AM". +*/ +class MSIFACE_EXPORT MLocalFormat +{ + DECLARE_SHARED_DPTR(d); + public: + /**constructs a formatter object that corresponds to the default*/ + MLocalFormat(); + /**copies a formatter object inheriting its overrides*/ + MLocalFormat(const MLocalFormat&)=default; + /**initializes the formatter object from a server format object*/ + MLocalFormat(const MOServerFormat&); + /**deletes the formatter object*/ + virtual ~MLocalFormat(){} + + /**sets a new default format*/ + static void setDefaultFormat(const MLocalFormat&); + + /**copies a formatter object*/ + virtual MLocalFormat& operator=(const MLocalFormat&)=default; + + /**overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday*/ + virtual void setWeekDays(const QStringList&l=QStringList()); + /**overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday (Sun)*/ + virtual void setShortWeekDays(const QStringList&l=QStringList()); + + /**overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January*/ + virtual void setMonths(const QStringList&l=QStringList()); + /**overrides the short names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January (Jan)*/ + virtual void setShortMonths(const QStringList&l=QStringList()); + + /**overrides the formatting of money - the settings of numbers are re-used + \param digitsCents defines how many digits are used for sub-amounts (cents), if zero no cents are used, normal are the values 0, 2 and 3; the default is 2 + \param currency defines the symbol of the currency used, the default is an empty string + \param symbolBehind defines whether the currency symbol is shown before (false) or behind (true) the numeric value + */ + virtual void setMoneyFormat(QString currency=QString(),int digitsCents=2, bool symbolBehind=true); + /**overrides the formatting of money - the settings of numbers are re-used + \param negative defines the sign for negative values, the default is "-" + \param positive defines the sign for positive values, the default is an empty string + \param negativePos defines where the negative sign is printed + \param positivePos defines where the positive sign is printed + */ + virtual void setMoneySign(QString negative="-",QString positive=QString(), MOServerFormat::MoneyPos negativePos=MOServerFormat::SignBeforeNum, MOServerFormat::MoneyPos positivePos=MOServerFormat::NoSign); + + /**overrides the formatting of numbers and money; + \param decimal defines the character used to separate decimals from the main body, if QChar() is used it returns to the translation default (a dot "." in default localization) + \param thousandDiv defines the character used to separate blocks of digits, if QChar() is used it returns to the translation default (comma "," in default) + \param digitsDiv defines the amount of digits in a block, eg. the value 3 will format 1000 as 1,000 (none per default)*/ + virtual void setNumberFormat(QChar decimal=QChar(),QChar thousandDiv=QChar(),int digitsDiv=-1); + + /**overrides the formatting of the AM/PM part of time display, resets to the localization if none given*/ + virtual void setAP(QString am="--",QString pm="--"); + + /**overrides the local time zone + \param olsonname the name of the local timezone in Olson notation, eg. "Europe/Berlin"*/ + virtual void setTimeZone(QString olsonname); + + /**overrides the default formatting of date and time, if empty the translation default is used*/ + virtual void setDateTimeFormat(QString dateformat=QString(),QString timeformat=QString(),QString datetimeformat=QString()); + + /**returns the currently set time zone of this formatter*/ + virtual QString timeZone()const; + + /**overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str*/ + virtual void setNonLocalized(); + + /**formats a date according to the given format, if none is given, the translation default is used + \param date a QDate used as input, it is assumed to be local + \param format a format string */ + virtual QString formatDate(const QDate&date,QString format=QString())const; + /**formats a date according to the given format, if none is given, the translation default is used + \param date a unix timestamp, it is converted to the local time of this local format object + \param format a format string */ + virtual QString formatDate(qint64 date,QString format=QString())const; + /**formats a date according to the given format, if none is given, the translation default is used + \param date a timestamp, it is converted to the local time of this local format object + \param format a format string */ + virtual QString formatDate(const TimeStamp& date,QString format=QString())const; + + /**formats a time according to the given format, if none is given, the translation default is used + \param time a QTime used as input, it is assumed to be local + \param format a format string */ + virtual QString formatTime(const QTime&time,QString format=QString())const; + /**formats a time according to the given format, if none is given, the translation default is used + \param time a unix timestamp, it is converted to local time + \param format a format string */ + virtual QString formatTime(qint64 time,QString format=QString())const; + /**formats a time according to the given format, if none is given, the translation default is used + \param time a timestamp, it is converted to the local time of this local format object + \param format a format string */ + virtual QString formatTime(const TimeStamp& time,QString format=QString())const; + + /**formats a date and time according to the given format, if none is given, the translation default is used + \param time a QDateTime used as input, it is assumed to be local + \param format a format string as specified by QDateTime::toString */ + virtual QString formatDateTime(const QDateTime&time,QString format=QString())const; + /**formats a date and time according to the given format, if none is given, the translation default is used + \param time a unix timestamp, it is converted to local time + \param format a format string as specified by QDateTime::toString */ + virtual QString formatDateTime(qint64 time,QString format=QString())const; + /**formats a date and time according to the given format, if none is given, the translation default is used + \param time a TimeStamp used as input, it is converted to the local time of this local format object + \param format a format string as specified by QDateTime::toString */ + virtual QString formatDateTime(const TimeStamp&time,QString format=QString())const; + + + /**formats an integer number*/ + virtual QString formatNumber(qint64)const; + /**formats an integer number*/ + virtual QString formatNumber(int n)const{return formatNumber(qint64(n));} + /**formats an integer number*/ + virtual QString formatNumber(uint n)const{return formatNumber(qint64(n));} + + /**formats a floating point number, this version does not use exponential display, but adheres to the settings of local decimal dot and thousands block division + \param num the number to be formatted + \param decimals the maximum number of digits after the decimal dot*/ + virtual QString formatNumber(double num,uint decimals=4)const; + + enum MoneyFlag { + PlainMoneyFormat=0, + UseThousand=1, + ShowCurrencySymbol=2, + + DefaultFormat=UseThousand|ShowCurrencySymbol + }; + Q_DECLARE_FLAGS(MoneyFlags,MoneyFlag); + + /**formats a money value + \param num the amount in cents + \param flags determines how the string will be formatted */ + virtual QString formatMoney(qint64 num,MoneyFlags flags=DefaultFormat)const; + /**formats a money value + \param num the amount in cents + \param usethousand if true the thousand block division is inserted */ + virtual QString formatMoney(qint64 num,bool usethousand)const; + + /**scans an integer number and returns the value, non-numerical chars are ignored*/ + virtual qint64 scanInt(QString)const; + + /**scans a money value and returns it in cents, non-numerical chars are ignored*/ + virtual qint64 scanMoney(QString)const; + + /**scans a floating point number and returns it, non-numerical chars are ignored*/ + virtual double scanFloat(QString)const; + + /**returns the names used for week days*/ + QStringList weekDayNames()const; + /**returns the abbreviations used for week days*/ + QStringList shortWeekDayNames()const; + + /**returns the names used for months*/ + QStringList monthNames()const; + /**returns the names used for months*/ + QStringList shortMonthNames()const; + + /**returns the currency symbol*/ + QString currency()const; + + /**returns the decimal dot symbol*/ + QChar decimalDot()const; + + /**returns the thousand separator if used, otherwise an empty string*/ + QString thousandSeparator()const; + + /**returns the amount of digits between thousand separators*/ + int thousandDigits()const; + + /**returns the amount of decimals in a money value*/ + int moneyDecimals()const; + + /**returns the text for AM in 12-hour clock format*/ + QString amText()const; + /**returns the text for PM in 12-hour clock format*/ + QString pmText()const; + + /**returns the negative sign for money values*/ + QString moneyNegativeSign()const; + /**returns the positive sign for money values*/ + QString moneyPositiveSign()const; + + /**returns a regular expression matching money values + \param allownegative if given the resulting RegExp allows to use negative values + \param allowcurrency if given the resulting RegExp allows to use the currency symbol */ + QRegExp moneyRegExp(bool allownegative=false,bool allowcurrency=false)const; + + /**returns the default format for dates*/ + QString dateFormat()const; + + /**returns the default format for times*/ + QString timeFormat()const; + + /**returns the default format for date/time*/ + QString dateTimeFormat()const; + protected: + /** \internal constructs the default object from the translation*/ + MLocalFormat(int); + /** \internal default format*/ + static MLocalFormat defaultformat; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(MLocalFormat::MoneyFlags); + +#endif diff --git a/iface/misc/misc.pri b/iface/misc/misc.pri new file mode 100644 index 0000000..cbf78ea --- /dev/null +++ b/iface/misc/misc.pri @@ -0,0 +1,11 @@ +HEADERS += \ + $$PWD/misc.h \ + $$PWD/boxwrapper.h \ + $$PWD/formula.h + +SOURCES += \ + $$PWD/misc.cpp \ + $$PWD/boxwrapper.cpp \ + $$PWD/formula.cpp + +INCLUDEPATH += $$PWD diff --git a/iface/msinterface.cpp b/iface/msinterface.cpp new file mode 100644 index 0000000..43f9370 --- /dev/null +++ b/iface/msinterface.cpp @@ -0,0 +1,289 @@ +// +// C++ Implementation: msinterface +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "msinterface.h" +#include "sslexception.h" +#include "templates.h" +#include "misc.h" +#include "boxwrapper.h" + +#include "MTGetMyRights" +#include "MTGetMyRoles" +#include "MTServerInfo" +#include "MTLogout" +#include "MTGetLanguage" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static QString dataDir; + +#include + +#ifdef Q_OS_WIN32 +#define BASEDIRVAR "APPDATA" +#else +#define BASEDIRVAR "HOME" +#endif + +QString MSInterface::resolveDir(const QString &dirspec) +{ + //resolve pattern + const QStringList dirspecl=dirspec.split('/',QString::KeepEmptyParts); + bool notfirst=false; + QString rdir; + for(QString dcom:dirspecl){ + if(dcom=="$BASE"){ + dcom=getenv(BASEDIRVAR); + if(dcom.isEmpty()) + qFatal("Cannot determine base application data directory. While resolving %s",dirspec.toLatin1().data()); + }else if(dcom=="$APP") + dcom=qApp->applicationDirPath(); + else if(dcom.startsWith("$")) + dcom=getenv(dcom.mid(1).toLatin1().data()); + //append component + if(notfirst)rdir+="/"; + else notfirst=true; + rdir+=dcom; + } + //make sure it exists + if(!QDir::current().mkpath(rdir)) + qFatal("Unable to create path '%s' for spec '%s'.",rdir.toLatin1().data(),dirspec.toLatin1().data()); + //return it + return rdir; +} + +MSInterface::MSInterface(QString pid) + :MInterface() +{ + profileid=pid; + QSettings set; + set.beginGroup("profiles/"+pid); + setUrl("https://"+set.value("serverurl","my.host.com/path/machine.php").toString()); + bool useproxy=set.value("useproxy",false).toBool(); + if(useproxy) + setProxy( + set.value("proxyname","proxy").toString(), + set.value("proxyport",74).toInt(), + set.value("proxyuser").toString(), + set.value("proxypass").toString() + ); + m_host=set.value("hostname").toString(); + m_hostkey=set.value("hostkey").toString(); + setLogLevel((LogLevel)set.value("webloglevel",LogOnError).toInt()); + setWebTimeout(set.value("webtimeout",30).toInt()*1000); + sslexcept=new MSslExceptions(dataDir()+"/sslexceptions.xml"); + temp=new MTemplateStore(pid); +} + +MSInterface::~MSInterface() +{ + logout(); + if(sslexcept)delete sslexcept; + sslexcept=0; + if(temp)delete temp; + temp=0; +} + +bool MSInterface::login(QString username,QString passwd) +{ + m_uname=username;m_passwd=passwd; + MTLogin lg=MTLogin::query(username,passwd,m_host,m_hostkey); + if(lg.stage()==lg.Error) + MBoxWrapper::warning(tr("Warning"),tr("Login failed: %1").arg(tr(lg.errorString().toLatin1()))); + else + setSessionId(lg.getsessionid()); + if(lg.stage()!=lg.Success)return false; + //schedule re-login before session times out + int msecs=QDateTime::currentDateTime().msecsTo(QDateTime::fromTime_t(lg.getvalidtill())); + msecs-=120000;//do it 2 min before session runs out + if(msecs>100000)//but only if it does not become annoying... + QTimer::singleShot(msecs,this,SLOT(relogin())); + //get rights and roles + MTGetMyRights mrt=MTGetMyRights::asyncQuery(); + MTGetMyRoles mrl=MTGetMyRoles::asyncQuery(); + WTransaction::WaitForAll()<commVersion()){ + MBoxWrapper::warning(tr("Error"),tr("This client is too old for the server, please upgrade.")); + return false; + } + //we are ok + return true; +} + +void MSInterface::logout() +{ + if(m_sessid!="")queryLogout(); + m_sessid=""; +} +bool MSInterface::relogin() +{ + logout(); + return login(m_uname,m_passwd); +} + +QMap MSInterface::headers(QString s)const +{ + QMap ret=WInterface::headers(s); + ret.insert("Wob-SessionId",m_sessid); + return ret; +} + +QString MSInterface::dataDir()const +{ + QString dd="profile."+profileid; + QDir dir(appDataDir()); + if(!dir.exists(dd)) + if(!dir.mkpath(dd)) + qDebug("Warning: oh dir! Can't create my data directory!"); + return appDataDir()+"/"+dd; +} + +QString MSInterface::appDataDir() +{ + return ::dataDir; +} + +void MSInterface::setAppDataDir(QString d) +{ + ::dataDir=resolveDir(d); + qDebug()<<"Setting the data directory to"<<::dataDir<<"from"<load((const uchar*)servertranslation.data(),servertranslation.size()); + qApp->installTranslator(trn); + qDebug("MSInterface: successfully loaded server language %s",lang.toLatin1().data()); + MLocalFormat::setDefaultFormat(gl.getformats().value()); + } +} + +void MSInterface::sslErrors(QNetworkReply *src,const QList&errs) +{ + //get source of error + if(!src)return; + //check against known exceptions + if(sslexcept->checksslexcept(errs)){ + src->ignoreSslErrors(); + return; + } + //message box + if(!didsslerror){ + MBoxWrapper::warning(tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration.")); + } +} + +void MSInterface::updateTemplates() +{ + if(temp)temp->updateTemplates(true); +} + +bool MSInterface::checkFlags(const QStringList& fl) const +{ + //shortcut for admins + if(userflags.contains("_admin") || userroles.contains("_admin")) + return true; + //check actual flags + foreach(QString f,fl){ + f=f.trimmed(); + if(f.isEmpty())continue; + if(f[0]=='+'){ + if(!userflags.contains(f.mid(1)))return false; + }else if(f[0]=='-'){ + if(userflags.contains(f.mid(1)))return false; + }else //ooops! invalid flag spec + return false; + } + //survived all tests + return true; +} diff --git a/iface/msinterface.h b/iface/msinterface.h new file mode 100644 index 0000000..f271ab6 --- /dev/null +++ b/iface/msinterface.h @@ -0,0 +1,139 @@ +// +// C++ Interface: msinterface +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MSINTERFACE_H +#define MAGICSMOKE_MSINTERFACE_H + +#include "MInterface" + +#define req (MSInterface::instance()) + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSslExceptions; +class MTemplateStore; + +/**the MagicSmoke specific interface class - enhances the basic interface by some functionality needed in the MagicSmoke context*/ +class MSIFACE_EXPORT MSInterface:public MInterface +{ + Q_OBJECT + Q_PROPERTY(QString currentUser READ currentUser) + Q_PROPERTY(QString hostName READ hostName) + Q_PROPERTY(QString dataDir READ dataDir) + Q_PROPERTY(QString settingsGroup READ settingsGroup) + Q_PROPERTY(QString sessionId READ sessionId) + Q_PROPERTY(QString profileId READ profileId) + public: + /**creates the interface object, expects the profile ID as parameter*/ + MSInterface(QString); + /**deletes the interface*/ + ~MSInterface(); + + /**returns the singleton instance of the interface*/ + static MSInterface* instance(){return qobject_cast(MInterface::instance());} + + /**returns the name of the current user*/ + Q_INVOKABLE QString currentUser()const{return m_uname;} + + /**returns the name used for the host in this session*/ + Q_INVOKABLE QString hostName()const{return m_host;} + + /**returns whether the user is part of this role*/ + Q_INVOKABLE bool hasRole(QString s)const{return userroles.contains(s);} + + /**returns whether the user has a particular right*/ + Q_INVOKABLE bool hasRight(Right)const; + + ///returns whether the user has a particular flag + Q_INVOKABLE bool hasFlag(QString f)const{return userflags.contains(f);} + + ///checks the flags in the string list and returns true if all of them match + Q_INVOKABLE bool checkFlags(const QStringList&)const; + + ///checks the space separeted flags in the string and returns true if all of them match + Q_INVOKABLE bool checkFlags(const QString&s)const{return checkFlags(s.split(" "));} + + /**returns the directory where to store data retrieved from the server*/ + Q_INVOKABLE QString dataDir()const; + /**returns the group in which to find settings in QSettings, this group can be used by any class that accesses the profile*/ + Q_INVOKABLE QString settingsGroup()const; + /**returns the group where central profile settings are stored, this group is read-only for anything but the configuration dialog*/ + Q_INVOKABLE QString configSettingsGroup()const; + + /**checks the server for compatibility*/ + bool checkServer(); + + /**returns the current session ID*/ + Q_INVOKABLE QString sessionId()const{return m_sessid;} + + /**returns default headers, ie. session ID*/ + virtual QMap headers(QString)const; + + /**initializes the interface, ie. retrieves language and scripts*/ + void initialize(); + + /**returns a pointer to the template storage engine*/ + Q_INVOKABLE MTemplateStore* templateStore(){return temp;} + + /**returns the profile ID of this session*/ + QString profileId()const{return profileid;} + + ///return all rights of the current user + QList allRights()const{return userrights;} + + ///return all roles of the current user + QStringList allRoles()const{return userroles;} + + ///return all flags of the current user + QStringList allFlags()const{return userflags;} + + ///return application main data directory + static QString appDataDir(); + + ///override the application main data directory + static void setAppDataDir(QString); + + ///helper function to resolve directory names with patterns + ///the string $BASE is resolved as the content of the environment variable Unix: $HOME or Windows: %APPDIR% + ///the string $APP is resolved as the directory the application is installed in + ///any other component starting with $ resolves to the environment variable of the same name + static QString resolveDir(const QString&dir); + + public slots: + /**logs into the server, returns true on success*/ + bool login(QString username,QString passwd); + /**logs out of the server*/ + void logout(); + /**refreshes the login*/ + bool relogin(); + /**sets the session id to be transmitted*/ + void setSessionId(QString sid){m_sessid=sid;} + /**handles SSL errors*/ + virtual void sslErrors(QNetworkReply *,const QList&); + /**force template store to update its templates*/ + void updateTemplates(); + + private: + QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey; + mutable QListuserrights; + mutable QStringList userroles,userflags; + QByteArray servertranslation; + MSslExceptions*sslexcept; + bool didsslerror; + MTemplateStore *temp; +}; + + +#endif diff --git a/iface/sslexception.cpp b/iface/sslexception.cpp new file mode 100644 index 0000000..eb1d578 --- /dev/null +++ b/iface/sslexception.cpp @@ -0,0 +1,117 @@ +// +// C++ Implementation: sslexception +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "sslexception.h" + +#include +// #include +#include +#include +#include +#include + +MSslExceptions::MSslExceptions(QString p) +{ + path=p; + //load... + QFile fd(p); + qDebug()<<"loading SSL Exceptions"<(c,e)); + qDebug()<<"Note: will ignore SSL exception of type"<&errs) +{ + //stage 1: record unknown exceptions + for(int i=0;ip(errs[i].certificate(),errs[i].error()); + bool known=false; + for(int j=0;jp(errs[i].certificate(),errs[i].error()); + bool known=false; + for(int j=0;j, (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_SSLEXCEPTION_H +#define MAGICSMOKE_SSLEXCEPTION_H + +#include +#include +#include +#include +#include +#include +#include + +class QWidget; + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +/**Helper class: stores and compares SSL-Exceptions*/ +class MSIFACE_EXPORT MSslExceptions +{ + public: + /**create instance from file in path*/ + MSslExceptions(QString path); + + /**saves the exceptions to config file for next session*/ + void savesslexcept(); + /**checks errors against the exception list, records all exceptions*/ + bool checksslexcept(const QList&); + + /**returns the current list of acceptable exceptions*/ + QList > nonFatalExceptions()const{return sslexcept;} + + /**returns the list of collected exceptions*/ + QList > collectedExceptions()const{return sslrecord;} + + /**clears the internal lists of exceptions*/ + void clear(); + + /**clears the list of recorded exceptions*/ + void clearRecorded(){sslrecord.clear();} + + /**accepts the recorded exceptions*/ + void acceptRecorded(); + + private: + QList > sslexcept,sslrecord; + QString path; +}; + +#endif diff --git a/iface/templates/templates.cpp b/iface/templates/templates.cpp new file mode 100644 index 0000000..e3f7773 --- /dev/null +++ b/iface/templates/templates.cpp @@ -0,0 +1,423 @@ +// +// C++ Implementation: templates +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +/***************************** + * Settings hierarchy for templates: + * + * /templates/$PROFILEID -> template settings for this profile + * .../$TEMPLATENAME -> the settings for a template, uses the complete name (eg. bill.odtt,2) + * ....../checksum -> key that stores the checksum (calculated by server!!) + * ....../description -> key that stores the description (as received from server) + * + * + * Template buffer on disk: + * + * req->dataDir()/templates -> directory for template files; + * each file is stored with complete name, no meta-info + ***************************/ + +#include "templates.h" +#include "msinterface.h" +#include "boxwrapper.h" + +#include "MTGetTemplateList" +#include "MTGetTemplate" +#include "MTSetTemplate" +#include "MTDeleteTemplate" +#include "MTSetTemplateDescription" +#include "MTSetTemplateFlags" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static MTemplate::TemplateChoserFunction templaceChoser(MTemplate::TemplateChoserFunction f=nullptr) +{ + static MTemplate::TemplateChoserFunction rf=nullptr; + if(f)rf=f; + if(rf)return rf; + else return [](const QList&tl){return tl.value(0);}; +} + + +MTemplateStore::MTemplateStore(QString p) +{ + profileid=p; +} + +MTemplate MTemplateStore::getTemplate(QString f) +{ + //syntax check + f=f.toLower(); + QRegExp fregexp("[a-z0-9_]+"); + if(!fregexp.exactMatch(f))return MTemplate(); + //update directory (no force) + updateTemplates(false); + //find files matching the pattern + //basics + QString dname=req->dataDir()+"/templates/"; + QSettings set; + set.beginGroup("templates/"+profileid); + //get directory + QStringList dir=set.childGroups(); + QStringList tdir; + MSInterface*ifc=MSInterface::instance(); + for(int i=0;icheckFlags(set.value(dir[i]+"/flags").toString())) + tdir<templst; + for(const QString&td:tdir) + templst<dataDir()+"/templates/"; + QSettings set; + set.beginGroup("templates/"+profileid); + //check directory + if(!set.childGroups().contains(f))return MTemplate(); + //return if found + return MTemplate(dname+"/"+f, set.value(f+"/checksum").toString(), set.value(f+"/description").toString(), set.value(f+"/flags").toString()); +} + +void MTemplateStore::updateTemplates(bool force) +{ + //basics + QString dname=req->dataDir()+"/templates/"; + QSettings set; + set.beginGroup("templates/"+profileid); + //make sure directory exists + QDir(req->dataDir()).mkpath("templates"); + //do we need an update yet? + QDateTime last=QDateTime::fromTime_t(set.value("lastupdate",0).toInt()+300); + if(last>=QDateTime::currentDateTime() && !force)return; + + //get local info + QStringList files=set.childGroups(); + QMap fmap; + for(int i=0;isetRange(0,1); + progress->setValue(0); + QObject progparent;progress->setParent(&progparent); + + //get remote info, assume it is still valid if unable to retrieve it + MTGetTemplateList gtl=req->queryGetTemplateList(); + if(gtl.hasError())return; + //remember update time + set.setValue("lastupdate",QDateTime::currentDateTime().toTime_t()); + //scan and create new list + QListnf=gtl.gettemplates(); + QMapnfmap; + for(int i=0;isetRange(0,nfiles.size()); + for(int i=0;isetValue(i); + if(!files.contains(nfiles[i])){ + //file is not in current cache (or was outdated) + if(retrieveFile(dname,nfiles[i])) + fmap.insert(nfiles[i],nfmap[nfiles[i]]); + }else{ + //file is already up to date, still copy the current description and flags + fmap[nfiles[i]].setdescription(nfmap[nfiles[i]].description()); + fmap[nfiles[i]].setflags(nfmap[nfiles[i]].flags()); + } + } + files=fmap.keys(); + + //clean up directory + QDir dir(dname); + QStringList dfiles=dir.entryList(QDir::Files); + for(int i=0;iqueryGetTemplate(fn); + if(gt.hasError())return false; + //store + QFile f(dname+"/"+fn); + if(!f.open(QIODevice::WriteOnly|QIODevice::Truncate))return false; + f.write(gt.gettemplatefile().value().content()); + return true; +} + +bool MTemplateStore::setTemplate(QString n,QString f) +{ + //very rough sanity check + QRegExp fregexp("[a-z0-9_\\.,]+"); + if(!fregexp.exactMatch(n))return false; + //get content + QFile fl(f); + if(!fl.open(QIODevice::ReadOnly)) + return false; + QByteArray ba=fl.readAll(); + fl.close(); + //send to server + MTSetTemplate st=req->querySetTemplate(n,ba,""); + if(st.hasError()) + return false; + //delete it from cache, so it is retrieved again; force retrieval + //TODO: the server returns the hash (since dec08), use it and update the cache without retrieval + QSettings set; + set.remove("templates/"+profileid+"/"+n); + set.setValue("templates/"+profileid+"/lastupdate",0); + QFile(req->dataDir()+"/templates/"+n).remove(); + //return success + return true; +} + +bool MTemplateStore::deleteTemplate(QString n) +{ + //very rough sanity check + QRegExp fregexp("[a-z0-9_\\.,]+"); + if(!fregexp.exactMatch(n))return false; + //send to server + MTDeleteTemplate dt=req->queryDeleteTemplate(n); + if(dt.hasError()) + return false; + //delete it from cache + QSettings set; + set.remove("templates/"+profileid+"/"+n); + QFile(req->dataDir()+"/templates/"+n).remove(); + return true; +} + +bool MTemplateStore::setTemplateDescription(QString n,QString d) +{ + //very rough sanity check + QRegExp fregexp("[a-z0-9_\\.,]+"); + if(!fregexp.exactMatch(n))return false; + //check that we have a real change + QSettings set; + set.beginGroup("templates/"+profileid+"/"+n); + QString o=set.value("description").toString(); + qDebug("setting %s '%s' -> '%s'",n.toLatin1().data(),o.toLatin1().data(),d.toLatin1().data()); + if(o==d)return true; + //send to server + MTSetTemplateDescription std=req->querySetTemplateDescription(n,d); + if(std.hasError()) + return false; + //update internal description + set.setValue("description",d); + //return success + return true; +} + +bool MTemplateStore::setTemplateFlags(QString n, QString flags) +{ + //check that we have a real change + QSettings set; + set.beginGroup("templates/"+profileid+"/"+n); + QString o=set.value("flags").toString(); + qDebug("setting %s '%s' -> '%s'",n.toLatin1().data(),o.toLatin1().data(),flags.toLatin1().data()); + if(o==flags)return true; + //send to server + MTSetTemplateFlags std=req->querySetTemplateFlags(n,flags); + if(std.hasError()) + return false; + //update internal description + set.setValue("flags",flags); + //return success + return true; +} + +QList MTemplateStore::allTemplates() +{ + updateTemplates(false); + QString dname=req->dataDir()+"/templates/"; + QSettings set; + set.beginGroup("templates/"+profileid); + QStringList names=set.childGroups(); + QList ret; + for(int i=0;i1)return lst[1]; + return ""; +} + +QString MTemplate::checksum()const{return m_checksum;} + +bool MTemplate::isValid()const{return m_fname!="";} + +QString MTemplate::targetExtension()const +{ + QString x=extension(); + //ODF file? + if(QRegExp("od.t").exactMatch(x))return x.left(3); + //all else: not storable + return ""; +} + +bool MTemplate::isOdf()const{return (type()&OdfTemplateMask)!=0;} + +bool MTemplate::isLabel()const{return type()==LabelTemplate;} +MTemplate::Type MTemplate::type()const +{ + QString x=extension(); + //ODF file? + if(x=="odtt")return OdtTemplate; + if(x=="odst")return OdsTemplate; + if(x=="odpt")return OdpTemplate; + if(x=="odgt")return OdgTemplate; + if(x=="odbt")return OdbTemplate; + //label? + if(x=="xtt")return LabelTemplate; + //script? + if(x=="zip")return ZipTemplate; + //hmm, unknown one + return UnknownTemplate; +} + +QString MTemplate::description()const{return m_descr;} + + +static QStringList tempBaseNames; +//static +QStringList MTemplate::legalBaseNames() +{ + if(tempBaseNames.size()==0){ + tempBaseNames<<"ticket"<<"voucher"<<"bill"<<"eventsummary"<<"scripts"; + } + return tempBaseNames; +} + +//static +MTemplate::Types MTemplate::legalTypes(QString bn) +{ + if(bn=="ticket" || bn=="voucher") + return LabelTemplate; + if(bn=="bill" || bn=="eventsummary") + return OdfTemplateMask; + if(bn=="scripts") + return ZipTemplate; + 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(); +} diff --git a/iface/templates/templates.h b/iface/templates/templates.h new file mode 100644 index 0000000..b5b1396 --- /dev/null +++ b/iface/templates/templates.h @@ -0,0 +1,186 @@ +// +// C++ Interface: templates +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_TEMPLATES_H +#define MAGICSMOKE_TEMPLATES_H + +#include +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +/**this class wraps a single template*/ +class MSIFACE_EXPORT MTemplate +{ + public: + /**creates an invalid template*/ + MTemplate(); + + /**creates a temporary template by a physical file name*/ + MTemplate(QString fn); + + /**copies a template*/ + MTemplate(const MTemplate&)=default; + + ///copies a template + MTemplate& operator=(const MTemplate&)=default; + + ///reinitializes the template from the given file name + void setFile(const QString&); + + /**returns the name/path of the cache file, if it exists*/ + QString cacheFileName()const; + + /**returns the file name of the template (eg. mytemplate.odtt)*/ + QString fileName()const; + + /**returns the complete encoded name of the template (eg. mytemplate.odtt,v1)*/ + QString completeFileName()const; + + /**returns the base name of the template (eg. mytemplate for mytemplate.odtt)*/ + QString baseName()const; + + /**returns the extension of the template (eg. odtt for mytemplate.odtt)*/ + QString extension()const; + + /**returns the variant ID of the template (warning: it has no meaning outside the template storage system*/ + QString variantID()const; + + /**returns the checksum (calculated by the server)*/ + QString checksum()const; + + /**returns the description*/ + QString description()const; + + /**returns whether this is a valid template*/ + bool isValid()const; + + /**returns the extension of the target document if it is saved (empty if the template cannot be saved)*/ + QString targetExtension()const; + + /**returns whether this is an ODF template*/ + bool isOdf()const; + + /**returns whether this is a label template*/ + bool isLabel()const; + + ///returns the flags of this template + QString flags()const{return m_flags;} + + /**template type; currently only ODF and Labels are known*/ + enum Type{ + /**uninitialized or unknown label type*/ + UnknownTemplate=0, + /**ODF Text template*/ + OdtTemplate=1, + /**ODF SpreadSheet template*/ + OdsTemplate=2, + /**ODF Presentation*/ + OdpTemplate=4, + /**ODF Drawing*/ + OdgTemplate=8, + /**ODF DataBase*/ + OdbTemplate=0x10, + /**ODF template*/ + OdfTemplateMask=0xff, + /**Label template*/ + LabelTemplate=0x100, + /**Script-Zip template*/ + ZipTemplate=0x200 + }; + Q_DECLARE_FLAGS(Types,Type) + + /**returns the template type*/ + Type type()const; + + /**returns the currently known (by the client) template base names*/ + static QStringList legalBaseNames(); + + /**returns the legal file types (as understood by the client) for a template base name; returns UnknownTemplate if none is legal*/ + static Types legalTypes(QString); + + /**returns the legal template file suffixes (as understood by the client) for a template base name; returns empty if none is legal*/ + static QStringList legalSuffixes(QString); + + typedef std::function&)>TemplateChoserFunction; + + ///set a function to handle multiple template choices, + ///the default is a function that choses the first one + static void setTemplateChoiceFunction(const TemplateChoserFunction&); + + protected: + friend class MTemplateStore; + friend class MTemplateChoice; + /**creates a template wrapper from a cache file name; this constructor is used internally in the storage system + \param fn physical file name of the template + \param chk server side check sum of the template + \param dsc description of the template + \param flg flags of the template + */ + MTemplate(QString fn,QString chk,QString dsc,QString flg); + private: + QString m_fname,m_checksum,m_descr,m_flags; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(MTemplate::Types) + +/**this class implements the storage end of the template subsystem, its only instance exists in the webrequest*/ +class MSIFACE_EXPORT MTemplateStore +{ + protected: + friend class MSInterface; + friend class MTemplateEditor; + /**instantiates the template subsystem*/ + MTemplateStore(QString); + + /**stores a specific template*/ + bool setTemplate(QString templatename,QString localfile); + + /**stores a new description for a template*/ + bool setTemplateDescription(QString templatename,QString description); + + ///stores a change of flags for a template + bool setTemplateFlags(QString templatename,QString flags); + + /**deletes a template (requires full name), used by MTemplateEditor*/ + bool deleteTemplate(QString); + + /**updates the template directory, does not do anything if force==false and the last update was less than 5min ago*/ + void updateTemplates(bool force); + + /**returns all templates (for MTemplateEditor)*/ + QList allTemplates(); + + private: + /**unused, just here to remove it from accessability*/ + MTemplateStore(){} + + /**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); + /**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); + + + + private: + QString profileid; +}; + +#endif diff --git a/iface/templates/templates.pri b/iface/templates/templates.pri new file mode 100644 index 0000000..c7cf1e3 --- /dev/null +++ b/iface/templates/templates.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/templates.h + +SOURCES += \ + $$PWD/templates.cpp + +INCLUDEPATH += $$PWD \ No newline at end of file diff --git a/iface/wext/MOAddress b/iface/wext/MOAddress new file mode 100644 index 0000000..d85f82c --- /dev/null +++ b/iface/wext/MOAddress @@ -0,0 +1 @@ +#include"address.h" diff --git a/iface/wext/MOCustomer b/iface/wext/MOCustomer new file mode 100644 index 0000000..396763a --- /dev/null +++ b/iface/wext/MOCustomer @@ -0,0 +1 @@ +#include"customer.h" diff --git a/iface/wext/MOCustomerInfo b/iface/wext/MOCustomerInfo new file mode 100644 index 0000000..468bee4 --- /dev/null +++ b/iface/wext/MOCustomerInfo @@ -0,0 +1 @@ +#include"customerinfo.h" diff --git a/iface/wext/MOEvent b/iface/wext/MOEvent new file mode 100644 index 0000000..0da8fbb --- /dev/null +++ b/iface/wext/MOEvent @@ -0,0 +1 @@ +#include"event.h" diff --git a/iface/wext/MOOrder b/iface/wext/MOOrder new file mode 100644 index 0000000..4222ffc --- /dev/null +++ b/iface/wext/MOOrder @@ -0,0 +1 @@ +#include"order.h" diff --git a/iface/wext/MOOrderInfo b/iface/wext/MOOrderInfo new file mode 100644 index 0000000..61ee41e --- /dev/null +++ b/iface/wext/MOOrderInfo @@ -0,0 +1 @@ +#include"orderinfo.h" diff --git a/iface/wext/MOTicket b/iface/wext/MOTicket new file mode 100644 index 0000000..056e50f --- /dev/null +++ b/iface/wext/MOTicket @@ -0,0 +1 @@ +#include"ticket.h" diff --git a/iface/wext/MOVoucher b/iface/wext/MOVoucher new file mode 100644 index 0000000..81cd139 --- /dev/null +++ b/iface/wext/MOVoucher @@ -0,0 +1 @@ +#include"voucher.h" diff --git a/iface/wext/MTransaction b/iface/wext/MTransaction new file mode 100644 index 0000000..1fadece --- /dev/null +++ b/iface/wext/MTransaction @@ -0,0 +1 @@ +#include "transaction.h" diff --git a/iface/wext/address.cpp b/iface/wext/address.cpp new file mode 100644 index 0000000..b707748 --- /dev/null +++ b/iface/wext/address.cpp @@ -0,0 +1,46 @@ +// +// C++ Implementation: MOAddress +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOAddress" + +#include +#include + +WOSCRIPT_IMP(MOAddress) + +static int moaid= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); + +QString MOAddress::fullAddress(QString nm)const +{ + //collect lines + QStringList rl; + if(name().isNull() || name()==""){ + if(nm!="")rl<, (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MADDRESS_H +#define MAGICSMOKE_MADDRESS_H + +#include "MOAddressAbstract" + +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +class MSIFACE_EXPORT MOAddress:public MOAddressAbstract +{ + Q_OBJECT + WOBJECT(MOAddress) + WOSCRIPT(MOAddress) + public: + /**returns the full address, if name is given and the address does not have its own name, it is included as top line*/ + QString fullAddress(QString name=QString())const; + + /**returns true if this is a valid address stored in the DB (ie. it has an address ID)*/ + bool isValid()const{return !addressid().isNull() && addressid().value()>=0;} +}; + +Q_DECLARE_METATYPE(MOAddress) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/customer.cpp b/iface/wext/customer.cpp new file mode 100644 index 0000000..727ab10 --- /dev/null +++ b/iface/wext/customer.cpp @@ -0,0 +1,63 @@ +// +// C++ Implementation: customer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOCustomer" +#include "MOCustomerInfo" +#include "msinterface.h" +#include + +#include "MTGetCustomer" + +static int mymeta= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); + +WOSCRIPT_IMP(MOCustomer) + +MOCustomer::MOCustomer(qint64 i) +{ + MTGetCustomer gc=req->queryGetCustomer(i); + if(gc.stage()==gc.Success) + operator=(gc.getcustomer().value()); +} + +MOCustomer::MOCustomer(const MOCustomerInfo&ci) +{ + MTGetCustomer gc=req->queryGetCustomer(ci.id()); + if(gc.stage()==gc.Success) + operator=(gc.getcustomer().value()); +} + +QString MOCustomer::address(int i) +{ + if(i<0)return ""; + QListadrs=addresses(); + if(i>=adrs.size())return ""; + return adrs[i].fullAddress(fullName()); +} + +QString MOCustomer::fullName()const +{ + QString ret=title().value().trimmed(); + QString s=name().value().trimmed(); + if(s!=""){ + if(ret!="")ret+=" "; + ret+=s; + } + s=firstname().value().trimmed(); + if(s!=""){ + if(ret!="")ret+=", "; + ret+=s; + } + return ret; +} diff --git a/iface/wext/customer.h b/iface/wext/customer.h new file mode 100644 index 0000000..7ac7621 --- /dev/null +++ b/iface/wext/customer.h @@ -0,0 +1,52 @@ +// +// C++ Interface: MOCustomer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOCUSTOMER_H +#define MAGICSMOKE_MOCUSTOMER_H + +#include "MOCustomerAbstract" + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +class MOCustomerInfo; + +class MSIFACE_EXPORT MOCustomer:public MOCustomerAbstract +{ + Q_OBJECT + WOBJECT(MOCustomer) + WOSCRIPT(MOCustomer) + public: + /**shortcut: gets the customer from the DB*/ + MOCustomer(qint64); + /**shortcut: extracts the ID from the info and retrieves the customer from the DB*/ + MOCustomer(const MOCustomerInfo&); + /**returns whether the customer is valid*/ + bool isValid(){return !id().isNull();} + + /**alias for id()*/ + Nullable customerid()const{return id();} + + /**returns the address of the customer*/ + QString address(int i=0); + + /**returns the full name (incl. title)*/ + QString fullName()const; + +}; + +Q_DECLARE_METATYPE(MOCustomer) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/customerinfo.cpp b/iface/wext/customerinfo.cpp new file mode 100644 index 0000000..277b0a0 --- /dev/null +++ b/iface/wext/customerinfo.cpp @@ -0,0 +1,36 @@ +// +// C++ Implementation: MOCustomerInfo +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOCustomerInfo" +#include + +static int mymeta= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); +WOSCRIPT_IMP(MOCustomerInfo) + +QString MOCustomerInfo::fullName()const +{ + QString ret=title().value().trimmed(); + QString s=name().value().trimmed(); + if(s!=""){ + if(ret!="")ret+=" "; + ret+=s; + } + s=firstname().value().trimmed(); + if(s!=""){ + if(ret!="")ret+=", "; + ret+=s; + } + return ret; +} diff --git a/iface/wext/customerinfo.h b/iface/wext/customerinfo.h new file mode 100644 index 0000000..8f635fa --- /dev/null +++ b/iface/wext/customerinfo.h @@ -0,0 +1,39 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOCUSTOMERI_H +#define MAGICSMOKE_MOCUSTOMERI_H + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +#include "MOCustomerInfoAbstract" +class MSIFACE_EXPORT MOCustomerInfo:public MOCustomerInfoAbstract +{ + Q_OBJECT + WOBJECT(MOCustomerInfo) + WOSCRIPT(MOCustomerInfo) + public: + /**returns the full name (incl. title)*/ + QString fullName()const; + + /**alias for customerid()*/ + Nullable id()const{return customerid();} +}; + +Q_DECLARE_METATYPE(MOCustomerInfo) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/event.cpp b/iface/wext/event.cpp new file mode 100644 index 0000000..5a13425 --- /dev/null +++ b/iface/wext/event.cpp @@ -0,0 +1,79 @@ +// +// C++ Implementation: event +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOEvent" + +#include +#include +#include +#include + +#include "msinterface.h" +#include "MTGetEvent" + +#include "misc.h" + +static int mymeta= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); +WOSCRIPT_IMP(MOEvent) + +MOEvent::MOEvent(qint64 i) +{ + MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); + if(ge.stage()==ge.Success) + operator=(ge.getevent().value()); +} + +QRegExp MOEvent::priceRegExp()const +{ + return ::priceRegExp(); +} + +QString MOEvent::priceString()const +{ + qint64 dp=/*defaultprice()*/0; + QString ret=QString::number(dp/100); + ret+=QCoreApplication::translate("MOEvent",".","price decimal dot"); + ret+=QString::number((dp/10)%10); + ret+=QString::number(dp%10); + return ret; +} + +QString MOEvent::startTimeString()const +{ + return unix2dateTime(start()); +} + +QString MOEvent::startDateString()const +{ + return unix2date(start()); +} + +QString MOEvent::endTimeString()const +{ + return unix2dateTime(end()); +} + +QList< MOEventPrice > MOEvent::priceFiltered() const +{ + QList ep=price(); + QList ret; + MSInterface *ifc=MSInterface::instance(); + if(ifc==0)return ep; + foreach(MOEventPrice p,ep){ + if(ifc->checkFlags(p.flags())) + ret<, (C) 2007-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef EVENT_H +#define EVENT_H + +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ +class MSIFACE_EXPORT MOEvent:public MOEventAbstract +{ + Q_OBJECT + WOBJECT(MOEvent) + WOSCRIPT(MOEvent) + public: + /**get event directly from server*/ + MOEvent(qint64); + + /**alias for id()*/ + inline Nullable eventid()const{return id();} + + /**returns the start time of the event as localized string*/ + QString startTimeString()const; + /**returns the start date as localized string*/ + 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; + /**returns the local regular expression for prices*/ + QRegExp priceRegExp()const; + + /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ + bool isValid()const{return !eventid().isNull() && eventid().value()>0;} + + ///returns only the prices that this user can order for + QList priceFiltered()const; +}; + +Q_DECLARE_METATYPE(MOEvent) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/order.cpp b/iface/wext/order.cpp new file mode 100644 index 0000000..424bbbe --- /dev/null +++ b/iface/wext/order.cpp @@ -0,0 +1,136 @@ +// +// C++ Implementation: MOOrder +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOOrder" +#include "MOOrderInfo" +#include "MORole" + +#include "MTGetOrder" + +#include "msinterface.h" +#include + +static int mymeta= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); + +MOOrder::MOOrder(qint64 id) +{ + MTGetOrder go=req->queryGetOrder(id); + if(go.stage()==go.Success) + operator=(go.getorder().value()); +} + +bool MOOrder::needsPayment()const +{ + if(status()==Placed || status()==Sent) + if(amountpaid()0; + if(status()==Placed || status()==Sent) + return amountpaid()>totalprice(); + return false; +} + +int MOOrder::amountToPay()const +{ + if(status()==Placed || status()==Sent) + if(amountpaid()totalprice()) + return amountpaid()-totalprice(); + return 0; +} + +bool MOOrder::isSent()const +{ + //only in placed mode there is a need for action, hence in all other modes we assume sent + return status()!=Placed; +} + +TimeStamp MOOrder::orderDateTime() +{ + if(ordertime().value()==0)return TimeStamp(); + return TimeStamp(ordertime()); +} + +QString MOOrder::orderDateTimeStr() +{ + if(ordertime().value()==0)return ""; + return unix2dateTime(ordertime()); +} + +QString MOOrder::orderDateStr() +{ + if(ordertime().value()==0)return ""; + return unix2date(ordertime()); +} + +TimeStamp MOOrder::sentDateTime() +{ + return TimeStamp(senttime()); +} + +QString MOOrder::sentDateTimeStr() +{ + if(senttime().value()==0)return ""; + return unix2dateTime(senttime()); +} + +QString MOOrder::sentDateStr() +{ + if(senttime().value()==0)return ""; + return unix2date(senttime()); +} + +QString MOOrder::fullInvoiceAddress(bool allowfallback)const +{ + if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) + return invoiceaddress().value().fullAddress(customer().value().fullName()); + //fall back + if(!allowfallback)return ""; + if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) + return deliveryaddress().value().fullAddress(customer().value().fullName()); + //give up + return ""; +} + +QString MOOrder::fullDeliveryAddress(bool allowfallback)const +{ + if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) + return deliveryaddress().value().fullAddress(customer().value().fullName()); + //fall back + if(!allowfallback)return ""; + if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) + return invoiceaddress().value().fullAddress(customer().value().fullName()); + //give up + return ""; +} diff --git a/iface/wext/order.h b/iface/wext/order.h new file mode 100644 index 0000000..bf9d1d0 --- /dev/null +++ b/iface/wext/order.h @@ -0,0 +1,119 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOORDER_H +#define MAGICSMOKE_MOORDER_H + +#include "MOOrderAbstract" +#include "misc.h" + +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +/**this class represents a complete order*/ +class MSIFACE_EXPORT MOOrder:public MOOrderAbstract +{ + Q_OBJECT + WOBJECT(MOOrder) + WOSCRIPT(MOOrder) + Q_PROPERTY(bool isValid READ isValid) + Q_PROPERTY(bool isReservation READ isReservation) + Q_PROPERTY(bool isSent READ isSent) + Q_PROPERTY(QString orderStatusString READ orderStatusString) + Q_PROPERTY(QString totalPriceString READ totalPriceString) + Q_PROPERTY(bool needsPayment READ needsPayment) + Q_PROPERTY(bool needsRefund READ needsRefund) + Q_PROPERTY(int amountToPay READ amountToPay) + Q_PROPERTY(QString amountToPayStr READ amountToPayStr) + Q_PROPERTY(int amountToRefund READ amountToRefund) + Q_PROPERTY(QString amountToRefundStr READ amountToRefundStr) + Q_PROPERTY(QString orderDateTimeStr READ orderDateTimeStr) + Q_PROPERTY(TimeStamp oderDateTime READ orderDateTime) + Q_PROPERTY(TimeStamp sentDateTime READ sentDateTime) + Q_PROPERTY(QString sentDateTimeStr READ sentDateTimeStr) + Q_PROPERTY(QString orderDateStr READ orderDateStr) + Q_PROPERTY(QString sentDateStr READ sentDateStr) + Q_PROPERTY(QString fullInvoiceAddress READ fullInvoiceAddress) + Q_PROPERTY(QString fullDeliveryAddress READ fullDeliveryAddress) + public: + /**create order by id, retrieves it automatically from the database*/ + MOOrder(qint64); + + /**returns whether the order is valid (it comes from the DB and it has been understood by the parser)*/ + bool isValid()const{return !orderid().isNull();} + + /**returns whether this order is a reservation*/ + bool isReservation()const{return status()==Reserved;} + + /**returns whether the tickets of this order have already been shipped*/ + bool isSent()const; + + /**returns the status of the order as localized string*/ + QString orderStatusString()const{return OrderState2locstr(status());} + + /**returns how much money needs to be paid in total for this order, in cents*/ + QString totalPriceString()const{return cent2str(totalprice());} + + /**returns how much money has already been paid for this order, in cents*/ + QString amountPaidString()const{return cent2str(amountpaid());} + + /**returns whether there is anything left to pay*/ + bool needsPayment()const; + + /**returns whether there is anything left to refund*/ + bool needsRefund()const; + + /**returns how much there is to be paid, in cents*/ + int amountToPay()const; + + /**returns how much there is to be paid, as localized string*/ + QString amountToPayStr()const{return cent2str(amountToPay());} + + /**returns how much there is to be refunded, in cents*/ + int amountToRefund()const; + + /**returns how much there is to be refunded, as localized string*/ + QString amountToRefundStr()const{return cent2str(amountToRefund());} + + /**return the order date+time*/ + TimeStamp orderDateTime(); + + /**returns the order date+time as string*/ + QString orderDateTimeStr(); + + /**returns the order date only as string*/ + QString orderDateStr(); + + /**returns the shipping date+time*/ + TimeStamp sentDateTime(); + + /**returns the shipping date+time as string*/ + QString sentDateTimeStr(); + + /**returns the shipping date only as string*/ + QString sentDateStr(); + + /**returns the full invoice address, or delivery address if no explicit invoice address was given and allowfallback==true*/ + QString fullInvoiceAddress(bool allowfallback=true)const; + /**returns the full delivery address, or invoice address if no explicit delivery address was given and allowfallback==true*/ + QString fullDeliveryAddress(bool allowfallback=true)const; +}; + +Q_DECLARE_METATYPE(MOOrder) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/orderinfo.h b/iface/wext/orderinfo.h new file mode 100644 index 0000000..b6505ea --- /dev/null +++ b/iface/wext/orderinfo.h @@ -0,0 +1,52 @@ +// +// C++ Interface: unabstract +// +// Description: removes abstract flag from classes that only need to be abstract in PHP +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOORDERI_H +#define MAGICSMOKE_MOORDERI_H + +#include "MOOrderInfoAbstract" +#include "misc.h" + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOOrderInfo:public MOOrderInfoAbstract +{ + Q_OBJECT + WOBJECT(MOOrderInfo) + WOSCRIPT(MOOrderInfo) + Q_PROPERTY(bool isReservation READ isReservation) + Q_PROPERTY(bool isSent READ isSent) + Q_PROPERTY(bool isCancelled READ isCancelled) + Q_PROPERTY(bool needsPayment READ needsPayment) + Q_PROPERTY(bool needsRefund READ needsRefund) + public: + QString totalPriceString()const{return cent2str(totalprice());} + QString amountPaidString()const{return cent2str(amountpaid());} + QString amountDueString()const{return cent2str(amountdue());} + QString orderStatusString()const{return OrderState2locstr(status());} + + bool needsPayment()const{return amountpaid()totalprice();} + bool isSent()const{return status()==Sent;} + bool isReservation()const{return status()==Reserved;} + bool isCancelled()const{return status()==Cancelled;} + bool isPlaced()const{return status()==Placed;} +}; + +Q_DECLARE_METATYPE(MOOrderInfo) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif \ No newline at end of file diff --git a/iface/wext/ticket.cpp b/iface/wext/ticket.cpp new file mode 100644 index 0000000..0683f47 --- /dev/null +++ b/iface/wext/ticket.cpp @@ -0,0 +1,55 @@ +// +// C++ Implementation: MOTicket +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "MOTicket" +#include "MOVoucher" +#include "msinterface.h" +#include +#include "MTGetEvent" + +static int mymeta= + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >()+ + qRegisterMetaType()+ + qRegisterMetaType >()+ + qRegisterMetaType >(); + +MOEvent MOTicket::event()const +{ + //if I am valid... + if(!ticketid().isNull() && !eventid().isNull()) + //...and the event is not... + if(m_event.eventid().isNull()){ + //...then retrieve the event + MTGetEvent ge=req->queryGetEvent(eventid()); + if(!ge.hasError()) + m_event=ge.getevent(); + } + //return whatever we have by now + return m_event; +} + +void MOTicket::setEvent(const MOEvent& e) +{ + m_event=e; + seteventid(e.eventid()); +} + +QString MOTicket::priceCategoryName()const +{ + return pricecategory().value().name(); +} +QString MOTicket::priceCategoryShort()const +{ + return pricecategory().value().abbreviation(); +} diff --git a/iface/wext/ticket.h b/iface/wext/ticket.h new file mode 100644 index 0000000..eaf6e81 --- /dev/null +++ b/iface/wext/ticket.h @@ -0,0 +1,64 @@ +// +// C++ Interface: MOTicket +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOTICKET_H +#define MAGICSMOKE_MOTICKET_H + +#include "MOTicketAbstract" +#include "misc.h" +#include "MOEvent" + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOTicket:public MOTicketAbstract +{ + Q_OBJECT + WOBJECT(MOTicket) + WOSCRIPT(MOTicket) + Q_PROPERTY(int amountToPay READ amountToPay) + Q_PROPERTY(QString priceString READ priceString) + Q_PROPERTY(QString statusString READ statusString) + Q_PROPERTY(QString priceCategoryName READ priceCategoryName) + Q_PROPERTY(QString priceCategoryShort READ priceCategoryShort) + public: + /**returns the amount to be paid for this ticket; this may be 0 even if there is a price attached*/ + int amountToPay()const{if(status()&MaskPay)return price();else return 0;} + + /**returns the price as string*/ + QString priceString()const{return cent2str(price());} + + /**returns the ticket status as localized string*/ + QString statusString()const{return TicketState2locstr(status());} + + /**returns the full price category name*/ + QString priceCategoryName()const; + /**returns the abbreviation for the price category*/ + QString priceCategoryShort()const; + + /**returns the event that this ticket belongs to - does a roundtrip to the database the first time this is called!*/ + MOEvent event()const; + + /**used by label editor: sets the simulated event*/ + void setEvent(const MOEvent&e); + private: + //this must be mutable, since event() is semantically and technically const + mutable MOEvent m_event; +}; + +Q_DECLARE_METATYPE(MOTicket) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/transaction.cpp b/iface/wext/transaction.cpp new file mode 100644 index 0000000..0dd929c --- /dev/null +++ b/iface/wext/transaction.cpp @@ -0,0 +1,46 @@ +// +// C++ Implementation: MTransaction +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2013 +// +// Copyright: See COPYING.GPL file that comes with this distribution +// +// + +#include "MTransaction" + +#include "cleanup.h" + +static QList& startFunctions() +{ + static QListf; + return f; +} + +static QList& stopFunctions() +{ + static QListf; + return f; +} + +QByteArray MTransaction::executeQuery(QString hreq,QByteArray data) +{ + //show the user we are waiting + for(MTStartStop f:startFunctions())f(); + MCleanup c([]{for(MTStartStop f:stopFunctions())f();}); + //call parent + return WTransaction::executeQuery(hreq,data); +} + +MTransaction::MTransaction(QString iface):WTransaction(iface){} +MTransaction::MTransaction(const WTransaction&t):WTransaction(t){} +MTransaction::MTransaction(const MTransaction&t):WTransaction(t){} + +void MTransaction::setStartStopActions(const MTStartStop& start, const MTStartStop& stop) +{ + startFunctions().append(start); + stopFunctions().append(stop); +} diff --git a/iface/wext/transaction.h b/iface/wext/transaction.h new file mode 100644 index 0000000..e533cdb --- /dev/null +++ b/iface/wext/transaction.h @@ -0,0 +1,40 @@ +// +// C++ Interface: MTransaction +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010-2013 +// +// Copyright: See COPYING.GPL file that comes with this distribution +// +// + +#ifndef MSMOKE_MTRANSACTION_H +#define MSMOKE_MTRANSACTION_H + +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +typedef std::function MTStartStop; + +class MSIFACE_EXPORT MTransaction:public WTransaction{ + public: + ///set actions to be executed at start/stop + static void setStartStopActions(const MTStartStop&start,const MTStartStop&stop); + protected: + /**internal: construct the transaction*/ + MTransaction(QString iface=QString()); + /**internal: copy the transaction*/ + MTransaction(const WTransaction&); + /**internal: copy the transaction*/ + MTransaction(const MTransaction&); + /**internal: extend executeQuery to show a wait cursor*/ + QByteArray executeQuery(QString,QByteArray); +}; + +#endif diff --git a/iface/wext/voucher.h b/iface/wext/voucher.h new file mode 100644 index 0000000..aa93bf8 --- /dev/null +++ b/iface/wext/voucher.h @@ -0,0 +1,47 @@ +// +// C++ Interface: MOVoucher +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MOVOUCHER_H +#define MAGICSMOKE_MOVOUCHER_H + +#include "MOVoucherAbstract" +#include "misc.h" + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOVoucher:public MOVoucherAbstract +{ + Q_OBJECT + WOBJECT(MOVoucher) + WOSCRIPT(MOVoucher) + Q_PROPERTY(QString valueString READ valueString) + Q_PROPERTY(QString statusString READ statusString) + Q_PROPERTY(QString priceString READ priceString) + public: + /**returns whether this is a valid voucher object (ie. it has a voucher ID)*/ + bool isValid()const{return !voucherid().isNull();} + /**returns the current value as string*/ + QString valueString()const{return cent2str(value());} + /**returns the status of the voucher as string*/ + QString statusString()const{return VoucherState2locstr(status());} + /**returns the price as string*/ + QString priceString()const{return cent2str(price());} +}; + +Q_DECLARE_METATYPE(MOVoucher) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(Nullable) + +#endif diff --git a/iface/wext/wext.pri b/iface/wext/wext.pri new file mode 100644 index 0000000..f9f30b6 --- /dev/null +++ b/iface/wext/wext.pri @@ -0,0 +1,21 @@ +INCLUDEPATH += ./wext + +HEADERS += \ + wext/customerinfo.h \ + wext/order.h \ + wext/orderinfo.h \ + wext/ticket.h \ + wext/voucher.h \ + wext/address.h \ + wext/event.h \ + wext/customer.h \ + wext/transaction.h + +SOURCES += \ + wext/customerinfo.cpp \ + wext/order.cpp \ + wext/ticket.cpp \ + wext/address.cpp \ + wext/event.cpp \ + wext/customer.cpp \ + wext/transaction.cpp diff --git a/mainapp/mainapp.pro b/mainapp/mainapp.pro index 5e1ac0c..1b2ba3f 100644 --- a/mainapp/mainapp.pro +++ b/mainapp/mainapp.pro @@ -1,9 +1,8 @@ #Project File for MagicSmoke -# (c) Konrad Rosenbaum, 2007-2011 +# (c) Konrad Rosenbaum, 2007-2013 TEMPLATE = app TARGET = magicsmoke -DESTDIR = $$PWD/../bin #add the icon for windoze win32-* { @@ -11,19 +10,13 @@ win32-* { RC_FILE += win.rc } -#compilation output: -OBJECTS_DIR = .ctmp -MOC_DIR = .ctmp -RCC_DIR = .ctmp - #main source files SOURCES = main.cpp INCLUDEPATH += . ../src #make sure dependencies are found DEPENDPATH += $$INCLUDEPATH -LIBS += -L$$PWD/../bin -lmagicsmoke -include (../src/libs.pri) +LIBS += -lmagicsmoke #security features linux-g++* { @@ -31,15 +24,7 @@ linux-g++* { QMAKE_CFLAGS += -fPIE QMAKE_CXXFLAGS += -fPIE QMAKE_LFLAGS += -pie - #make sure we find our libs - QMAKE_LFLAGS += -Wl,-rpath,\'\$$ORIGIN\' } -#protect the stack -QMAKE_CFLAGS += -fstack-protector-all -Wstack-protector -QMAKE_CXXFLAGS += -fstack-protector-all -Wstack-protector -#ASLR for windows -win32 { - QMAKE_LFLAGS += -Wl,--nxcompat -Wl,--dynamicbase - LIBS += -lssp -} +include (../basics.pri) +include (../src/libs.pri) diff --git a/pack b/pack index de50ef2..e06319c 160000 --- a/pack +++ b/pack @@ -1 +1 @@ -Subproject commit de50ef2ddfebf8bf0dc96540d03c51de0213d2a8 +Subproject commit e06319c7261d4189e8bcef16ed50b9739e6e13a5 diff --git a/src/iface/iface.pri b/src/iface/iface.pri deleted file mode 100644 index 6dfac48..0000000 --- a/src/iface/iface.pri +++ /dev/null @@ -1,9 +0,0 @@ -HEADERS += \ - iface/msinterface.h \ - iface/sslexception.h - -SOURCES += \ - iface/msinterface.cpp \ - iface/sslexception.cpp - -INCLUDEPATH += ./iface \ No newline at end of file diff --git a/src/iface/msinterface.cpp b/src/iface/msinterface.cpp deleted file mode 100644 index 6d1e0af..0000000 --- a/src/iface/msinterface.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// -// C++ Implementation: msinterface -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "msinterface.h" -#include "main.h" -#include "sslexception.h" -#include "templates.h" -#include "misc.h" - -#include "MTGetMyRights" -#include "MTGetMyRoles" -#include "MTServerInfo" -#include "MTLogout" -#include "MTGetLanguage" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -MSInterface::MSInterface(QString pid) - :MInterface() -{ - profileid=pid; - QSettings set; - set.beginGroup("profiles/"+pid); - setUrl("https://"+set.value("serverurl","my.host.com/path/machine.php").toString()); - bool useproxy=set.value("useproxy",false).toBool(); - if(useproxy) - setProxy( - set.value("proxyname","proxy").toString(), - set.value("proxyport",74).toInt(), - set.value("proxyuser").toString(), - set.value("proxypass").toString() - ); - m_host=set.value("hostname").toString(); - m_hostkey=set.value("hostkey").toString(); - setLogLevel((LogLevel)set.value("webloglevel",LogOnError).toInt()); - setWebTimeout(set.value("webtimeout",30).toInt()*1000); - sslexcept=new MSslExceptions(dataDir()+"/sslexceptions.xml"); - temp=new MTemplateStore(pid); -} - -MSInterface::~MSInterface() -{ - logout(); - if(sslexcept)delete sslexcept; - sslexcept=0; - if(temp)delete temp; - temp=0; -} - -bool MSInterface::login(QString username,QString passwd) -{ - m_uname=username;m_passwd=passwd; - MTLogin lg=MTLogin::query(username,passwd,m_host,m_hostkey); - if(lg.stage()==lg.Error) - QMessageBox::warning(0,tr("Warning"),tr("Login failed: %1").arg(tr(lg.errorString().toLatin1()))); - else - setSessionId(lg.getsessionid()); - if(lg.stage()!=lg.Success)return false; - //schedule re-login before session times out - int msecs=QDateTime::currentDateTime().msecsTo(QDateTime::fromTime_t(lg.getvalidtill())); - msecs-=120000;//do it 2 min before session runs out - if(msecs>100000)//but only if it does not become annoying... - QTimer::singleShot(msecs,this,SLOT(relogin())); - //get rights and roles - MTGetMyRights mrt=MTGetMyRights::asyncQuery(); - MTGetMyRoles mrl=MTGetMyRoles::asyncQuery(); - WTransaction::WaitForAll()<commVersion()){ - QMessageBox::warning(0,tr("Error"),tr("This client is too old for the server, please upgrade.")); - return false; - } - //we are ok - return true; -} - -void MSInterface::logout() -{ - if(m_sessid!="")queryLogout(); - m_sessid=""; -} -bool MSInterface::relogin() -{ - logout(); - return login(m_uname,m_passwd); -} - -QMap MSInterface::headers(QString s)const -{ - QMap ret=WInterface::headers(s); - ret.insert("Wob-SessionId",m_sessid); - return ret; -} - -QString MSInterface::dataDir()const -{ - QString dd="profile."+profileid; - QDir dir(MApplication::dataDir()); - if(!dir.exists(dd)) - if(!dir.mkpath(dd)) - qDebug("Warning: oh dir! Can't create my data directory!"); - return MApplication::dataDir()+"/"+dd; -} - -QString MSInterface::settingsGroup()const -{ - return "profsettings/"+profileid; -} -QString MSInterface::configSettingsGroup()const -{ - return "profiles/"+profileid; -} - -bool MSInterface::hasRight(Right r)const -{ - if(userroles.contains("_admin"))return true; - return userrights.contains(r); -} - -void MSInterface::initialize() -{ - //retrieve translation file - if(servertranslation.size()==0){ //can be called only once, make sure it is so - QString lang=QSettings().value("lang","--").toString(); - if(lang=="--"){ - qDebug("MSInterface: no local language is set, so not retrieving any from server."); - return; - } - MTGetLanguage gl=MTGetLanguage::query(lang,"qm"); - if(gl.hasError()){ - qDebug("MSInterface: error while retrieving language %s from server: (%s) %s", - lang.toLatin1().data(), - gl.errorType().toLatin1().data(), - gl.errorString().toLatin1().data()); - //go to fallback - gl=MTGetLanguage::query("C","qm"); - if(gl.hasError()){ - qDebug("MSInterface: cannot retrieve language 'C', giving up on languages."); - return; - } - } - servertranslation=gl.getfile().value(); - QTranslator *trn=new QTranslator(this); - trn->load((const uchar*)servertranslation.data(),servertranslation.size()); - qApp->installTranslator(trn); - qDebug("MSInterface: successfully loaded server language %s",lang.toLatin1().data()); - MLocalFormat::setDefaultFormat(gl.getformats().value()); - } -} - -void MSInterface::sslErrors(QNetworkReply *src,const QList&errs) -{ - //get source of error - if(!src)return; - //check against known exceptions - if(sslexcept->checksslexcept(errs)){ - src->ignoreSslErrors(); - return; - } - //message box - if(!didsslerror){ - QMessageBox::warning(0,tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration.")); - } -} - -void MSInterface::updateTemplates() -{ - if(temp)temp->updateTemplates(true); -} - -bool MSInterface::checkFlags(const QStringList& fl) const -{ - //shortcut for admins - if(userflags.contains("_admin") || userroles.contains("_admin")) - return true; - //check actual flags - foreach(QString f,fl){ - f=f.trimmed(); - if(f.isEmpty())continue; - if(f[0]=='+'){ - if(!userflags.contains(f.mid(1)))return false; - }else if(f[0]=='-'){ - if(userflags.contains(f.mid(1)))return false; - }else //ooops! invalid flag spec - return false; - } - //survived all tests - return true; -} diff --git a/src/iface/msinterface.h b/src/iface/msinterface.h deleted file mode 100644 index 8624853..0000000 --- a/src/iface/msinterface.h +++ /dev/null @@ -1,123 +0,0 @@ -// -// C++ Interface: msinterface -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MSINTERFACE_H -#define MAGICSMOKE_MSINTERFACE_H - -#include "MInterface" - -#define req (MSInterface::instance()) - - -class MSslExceptions; -class MTemplateStore; - -/**the MagicSmoke specific interface class - enhances the basic interface by some functionality needed in the MagicSmoke context*/ -class MSInterface:public MInterface -{ - Q_OBJECT - Q_PROPERTY(QString currentUser READ currentUser) - Q_PROPERTY(QString hostName READ hostName) - Q_PROPERTY(QString dataDir READ dataDir) - Q_PROPERTY(QString settingsGroup READ settingsGroup) - Q_PROPERTY(QString sessionId READ sessionId) - Q_PROPERTY(QString profileId READ profileId) - public: - /**creates the interface object, expects the profile ID as parameter*/ - MSInterface(QString); - /**deletes the interface*/ - ~MSInterface(); - - /**returns the singleton instance of the interface*/ - static MSInterface* instance(){return qobject_cast(MInterface::instance());} - - /**returns the name of the current user*/ - Q_INVOKABLE QString currentUser()const{return m_uname;} - - /**returns the name used for the host in this session*/ - Q_INVOKABLE QString hostName()const{return m_host;} - - /**returns whether the user is part of this role*/ - Q_INVOKABLE bool hasRole(QString s)const{return userroles.contains(s);} - - /**returns whether the user has a particular right*/ - Q_INVOKABLE bool hasRight(Right)const; - - ///returns whether the user has a particular flag - Q_INVOKABLE bool hasFlag(QString f)const{return userflags.contains(f);} - - ///checks the flags in the string list and returns true if all of them match - Q_INVOKABLE bool checkFlags(const QStringList&)const; - - ///checks the space separeted flags in the string and returns true if all of them match - Q_INVOKABLE bool checkFlags(const QString&s)const{return checkFlags(s.split(" "));} - - /**returns the directory where to store data retrieved from the server*/ - Q_INVOKABLE QString dataDir()const; - /**returns the group in which to find settings in QSettings, this group can be used by any class that accesses the profile*/ - Q_INVOKABLE QString settingsGroup()const; - /**returns the group where central profile settings are stored, this group is read-only for anything but the configuration dialog*/ - Q_INVOKABLE QString configSettingsGroup()const; - - /**checks the server for compatibility*/ - bool checkServer(); - - /**returns the current session ID*/ - Q_INVOKABLE QString sessionId()const{return m_sessid;} - - /**returns default headers, ie. session ID*/ - virtual QMap headers(QString)const; - - /**initializes the interface, ie. retrieves language and scripts*/ - void initialize(); - - /**returns a pointer to the template storage engine*/ - Q_INVOKABLE MTemplateStore* templateStore(){return temp;} - - /**returns the profile ID of this session*/ - QString profileId()const{return profileid;} - - ///return all rights of the current user - QList allRights()const{return userrights;} - - ///return all roles of the current user - QStringList allRoles()const{return userroles;} - - ///return all flags of the current user - QStringList allFlags()const{return userflags;} - - public slots: - /**logs into the server, returns true on success*/ - bool login(QString username,QString passwd); - /**logs out of the server*/ - void logout(); - /**refreshes the login*/ - bool relogin(); - /**sets the session id to be transmitted*/ - void setSessionId(QString sid){m_sessid=sid;} - /**handles SSL errors*/ - virtual void sslErrors(QNetworkReply *,const QList&); - /**force template store to update its templates*/ - void updateTemplates(); - - private: - QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey; - mutable QListuserrights; - mutable QStringList userroles,userflags; - QByteArray servertranslation; - MSslExceptions*sslexcept; - bool didsslerror; - MTemplateStore *temp; -}; - - -#endif diff --git a/src/iface/sslexception.cpp b/src/iface/sslexception.cpp deleted file mode 100644 index b806b8e..0000000 --- a/src/iface/sslexception.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// -// C++ Implementation: sslexception -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "sslexception.h" - -#include -#include -#include -#include -#include -#include - -MSslExceptions::MSslExceptions(QString p) -{ - path=p; - //load... - QFile fd(p); - qDebug()<<"loading SSL Exceptions"<(c,e)); - qDebug()<<"Note: will ignore SSL exception of type"<&errs) -{ - //stage 1: record unknown exceptions - for(int i=0;ip(errs[i].certificate(),errs[i].error()); - bool known=false; - for(int j=0;jp(errs[i].certificate(),errs[i].error()); - bool known=false; - for(int j=0;j, (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_SSLEXCEPTION_H -#define MAGICSMOKE_SSLEXCEPTION_H - -#include -#include -#include -#include -#include -#include -#include - -class QWidget; - -/**Helper class: stores and compares SSL-Exceptions*/ -class MSslExceptions -{ - public: - /**create instance from file in path*/ - MSslExceptions(QString path); - - /**saves the exceptions to config file for next session*/ - void savesslexcept(); - /**checks errors against the exception list, records all exceptions*/ - bool checksslexcept(const QList&); - - /**returns the current list of acceptable exceptions*/ - QList > nonFatalExceptions()const{return sslexcept;} - - /**returns the list of collected exceptions*/ - QList > collectedExceptions()const{return sslrecord;} - - /**clears the internal lists of exceptions*/ - void clear(); - - /**clears the list of recorded exceptions*/ - void clearRecorded(){sslrecord.clear();} - - /**accepts the recorded exceptions*/ - void acceptRecorded(); - - private: - QList > sslexcept,sslrecord; - QString path; -}; - -#endif diff --git a/src/libs.pri b/src/libs.pri index a52b7ea..8e1aded 100644 --- a/src/libs.pri +++ b/src/libs.pri @@ -3,30 +3,12 @@ # ZIP library include($$PWD/../taurus/zip.pri) -# PACK library -LIBS += -lqwbase -INCLUDEPATH += $$PWD/../pack/qtbase/include - -# Time Zone DB library -LIBS += -lQtTzData -INCLUDEPATH += $$PWD/../tzone/include - -# ELAM library -include($$PWD/../taurus/elam.pri) - -# Chester DPtr library -include($$PWD/../taurus/chester.pri) +# MagicSmoke Interface +include ($$PWD/../iface/iface.pri) # Aurora Updater library include($$PWD/../taurus/aurora.pri) #make sure the correct Qt DLLs are used -CONFIG += qt thread link_prl separate_debug_info QT += xml network script scripttools QT += widgets printsupport - -#activate C++11 for g++ -gcc { - message("detected GCC, activating C++11 with GNU extensions") - QMAKE_CXXFLAGS += -std=gnu++11 -} diff --git a/src/main.cpp b/src/main.cpp index 9a7d1a9..5a3e34e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include "misc.h" #include +#include "boxwrapper.h" QString choseLanguage(bool warn) { @@ -69,42 +71,42 @@ QString choseLanguage(bool warn) return lang; } -static QString dataDir; - -#include - -#ifdef Q_OS_WIN32 -#define BASEDIRVAR "APPDATA" -#else -#define BASEDIRVAR "HOME" -#endif - -static inline QString resolveDir(const QString &dirspec) +class MProgressWrapperGui:public MProgressWrapper { - //resolve pattern - const QStringList dirspecl=dirspec.split('/',QString::KeepEmptyParts); - bool notfirst=false; - QString rdir; - for(QString dcom:dirspecl){ - if(dcom=="$BASE"){ - dcom=getenv(BASEDIRVAR); - if(dcom.isEmpty()) - qFatal("Cannot determine base application data directory. While resolving %s",dirspec.toLatin1().data()); - }else if(dcom=="$APP") - dcom=qApp->applicationDirPath(); - else if(dcom.startsWith("$")) - dcom=getenv(dcom.mid(1).toLatin1().data()); - //append component - if(notfirst)rdir+="/"; - else notfirst=true; - rdir+=dcom; - } - //make sure it exists - if(!QDir::current().mkpath(rdir)) - qFatal("Unable to create path '%s' for spec '%s'.",rdir.toLatin1().data(),dirspec.toLatin1().data()); - //return it - return rdir; -} + QProgressDialog*pd; + public: + MProgressWrapperGui(QString label,QString button) + { + pd=new QProgressDialog(label,button,0,0); + pd->setMinimumDuration(0); + pd->show(); + } + ~MProgressWrapperGui() + { + if(pd)pd->deleteLater(); + pd=0; + } + virtual void setLabelText(QString l) + { + pd->setLabelText(l); + } + virtual void setCancelButtonText(QString t) + { + pd->setCancelButtonText(t); + } + virtual void cancel() + { + pd->cancel(); + } + virtual void setRange(int mi,int ma) + { + pd->setRange(mi,ma); + } + virtual void setValue(int v) + { + pd->setValue(v); + } +}; #ifndef HOMEPAGE_BASEURL #define HOMEPAGE_BASEURL "http://smoke.silmor.de" @@ -127,7 +129,7 @@ void MApplication::aboutMS() .arg(HOMEPAGE_BASEURL) //%2 .arg(MSInterface::staticVersionInfo(WOb::VersionRootURL)) //%3 .arg(MSInterface::staticVersionInfo(WOb::VersionNumber)) //%4 - .arg(ifc?ifc->dataDir(): ::dataDir) + .arg(ifc?ifc->dataDir(): dataDir()) ); mb.setStandardButtons(QMessageBox::Ok); mb.exec(); @@ -286,6 +288,12 @@ MApplication::MApplication(int&ac,char**av) //install event filter for random generator installEventFilter(ef=new EFilter); + //init GUI wrappers + MBoxWrapper::setWarning([](QString title,QString text){QMessageBox::warning(nullptr,title,text);}); + MProgressWrapper::setFactory([](QString label,QString button)->MProgressWrapper*{ + return new MProgressWrapperGui(label,button); + }); + //check parameters // qDebug()<<"arguments"<, (C) 2012 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_LAMBDACLEAN_H -#define MAGICSMOKE_LAMBDACLEAN_H - -#include - -///clean-up function: executes a lambda expression when it is destructed (i.e. when the instance leaves its scope -class MCleanup -{ - std::functionm_ptr; - public: - ///instantiates a new cleanup object and remembers the given function for later execution - MCleanup(const std::function&f):m_ptr(f){} - - ///sets a new cleanup function, removing the old one - void setFunction(const std::function&f){m_ptr=f;} - - ///destructs the object and executes the cleanup function - ~MCleanup(){if(m_ptr)m_ptr();} -}; - -#endif diff --git a/src/misc/formula.cpp b/src/misc/formula.cpp deleted file mode 100644 index 98fa79c..0000000 --- a/src/misc/formula.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// -// C++ Implementation: magicsmoke ELAM adaptation -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "formula.h" -#include "misc.h" - -#include -#include - -#include -#include -#include -#include - -using namespace ELAM; - -inline static QVariant toMoneyFunc(const QList&lf,bool local) -{ - if(lf.size()!=1) - return Exception(Exception::ArgumentListError, "expecting exactly one argument"); - if(!lf[0].canConvert()) - return Exception(Exception::TypeMismatchError,"cannot convert to int"); - return cent2str(lf[0].toLongLong(),local); -} -static QVariant toMoneyFuncLoc(const QList&lf,Engine&){return toMoneyFunc(lf,true);} -static QVariant toMoneyFuncNLoc(const QList&lf,Engine&){return toMoneyFunc(lf,false);} - -inline static QVariant fromMoneyFunc(const QList&lf,bool local) -{ - if(lf.size()!=1) - return Exception(Exception::ArgumentListError, "expecting exactly one argument"); - if(!lf[0].canConvert()) - return Exception(Exception::TypeMismatchError,"cannot convert to string"); - return str2cent(lf[0].toString(),local); -} -static QVariant fromMoneyFuncLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,true);} -static QVariant fromMoneyFuncNLoc(const QList&lf,Engine&){return fromMoneyFunc(lf,false);} - -inline static QVariant unix2DTFunc(const QList&args,int mode) -{ - if(args.size()<1 || args.size()>2) - return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 or 2 arguments"); - if(!args[0].canConvert()) - return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 1 must be int"); - qint64 tm=args[0].toLongLong(); - bool loc=true; - if(args.size()>1){ - if(!args[1].canConvert()) - return ELAM::Exception(ELAM::Exception::TypeMismatchError,"argument 2 must be boolean"); - loc=args[1].toBool(); - } - switch(mode){ - case 0:return unix2date(tm,loc); - case 1:return unix2time(tm,loc); - default:return unix2dateTime(tm,loc); - } -} -static QVariant unix2DateFunc(const QList&args,Engine&){return unix2DTFunc(args,0);} -static QVariant unix2TimeFunc(const QList&args,Engine&){return unix2DTFunc(args,1);} -static QVariant unix2DateTimeFunc(const QList&args,Engine&){return unix2DTFunc(args,2);} - -static QVariant nullintCast(const QVariant&orig,const Engine&) -{ - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return (qlonglong)ni.value(); - } - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return (qlonglong)ni.value(); - } - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return (qlonglong)ni.value(); - } - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return (qlonglong)ni.value(); - } - return orig; -} - -static QVariant nullstrCast(const QVariant&orig,const Engine&) -{ - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return ni.value(); - } - return orig; -} - -static QVariant nullboolCast(const QVariant&orig,const Engine&) -{ - if(orig.userType()==qMetaTypeId >()){ - Nullable ni=orig.value >(); - if(ni.isNull())return QVariant(); - else return ni.value(); - } - return orig; -} - -MElamEngine::MElamEngine(QObject* parent): Engine(parent) -{ - //configure character classes - QString alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; - characterClasses().setNameClass(alpha,alpha+"0123456789.:"); - QString oc=characterClasses().operatorClass(); - characterClasses().setOperatorClass(oc.remove('.').remove(':')); - characterClasses().setAssignmentChars('\0','='); - if(!characterClasses().isConsistent()) - qDebug()<<"Warning: built-in calculator is inconsistent."; - //load default engines - IntEngine::configureIntEngine(*this); - FloatEngine::configureFloatEngine(*this); - BoolEngine::configureBoolEngine(*this); - BoolEngine::configureLogicEngine(*this); - StringEngine::configureStringEngine(*this); - configureReflection(*this); - //add money class - setFunction("toMoney",toMoneyFuncLoc); - setFunction("toMoneyLocal",toMoneyFuncLoc); - setFunction("toMoneyNL",toMoneyFuncNLoc); - setFunction("fromMoney",fromMoneyFuncLoc); - setFunction("fromMoneyLocal",fromMoneyFuncLoc); - setFunction("fromMoneyNL",fromMoneyFuncNLoc); - //add datetime conversion - setFunction("unix2date",unix2DateFunc); - setFunction("unix2time",unix2TimeFunc); - setFunction("unix2datetime",unix2DateTimeFunc); - //legacy functions for ODF renderer - setFunction("cent2str",[](const QList&args,Engine&)->QVariant{ - if(args.size()!=1) - return Exception(Exception::ArgumentListError,"expected one argument to cent2str"); - else - return cent2str(args[0].toInt()); - }); - setFunction("str2cent",[](const QList&args,Engine&)->QVariant{ - if(args.size()!=1) - return Exception(Exception::ArgumentListError,"expected one argument to str2cent"); - else - return str2cent(args[0].toString()); - }); - //register casts for nullable - setAutoCast(qMetaTypeId(), - QList() - < >() - < >() - < >() - < >(), - nullintCast - ); - setAutoCast(qMetaTypeId(),QList()< >(), nullstrCast); - setAutoCast(qMetaTypeId(),QList()< >(), nullboolCast); -} diff --git a/src/misc/formula.h b/src/misc/formula.h deleted file mode 100644 index f6ee17c..0000000 --- a/src/misc/formula.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// C++ Interface: magicsmoke ELAM adaptation -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_ELAM_H -#define MAGICSMOKE_ELAM_H - -#include - -class MElamEngine:public ELAM::Engine -{ - public: - MElamEngine(QObject*parent=0); -}; - -#endif diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp deleted file mode 100644 index 572385c..0000000 --- a/src/misc/misc.cpp +++ /dev/null @@ -1,741 +0,0 @@ -// -// C++ Implementation: misc -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "misc.h" - -#include - -#include - -#include "MOServerFormat" - -#include -#include -#include -#include -#include - -QString htmlize(QString str) -{ - QString out; - for(int i=0;i')out+=">";else - if(c=='&')out+="&";else - if(c=='\n')out+="
\n";else - if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c; - else out+="&#"+QString::number(ci)+";"; - } - return out; -} - -QString xmlize(QString str,QString newline) -{ - QString out; - for(int i=0;i')out+=">";else - if(c=='&')out+="&";else - if(c=='\n')out+=newline;else - if(c.isSpace()||(c.unicode()>=32&&c.unicode()<=0x7f))out+=c; - else out+="&#"+QString::number(ci)+";"; - } - return out; -} -QByteArray xmlize(QByteArray str,QString newline) -{ - QByteArray out; - for(int i=0;i')out+=">";else - if(c=='&')out+="&";else - if(c=='\n')out+=newline;else - if(QChar(c).isSpace()||(c>=32 && static_cast(c)<=0x7f))out+=c; - else out+="&#"+QString::number((unsigned char)c)+";"; - } - return out; -} - -QString cent2str(qint64 c,bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.formatMoney(c); -} - -qint64 str2cent(QString s,bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.scanMoney(s); -} - -QRegExp priceRegExp(bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.moneyRegExp(false,false); -} - -QString unix2date(qint64 tm,bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.formatDate(tm); -} - -QString unix2time(qint64 tm,bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.formatTime(tm); -} - -QString unix2dateTime(qint64 tm,bool localize) -{ - MLocalFormat mf; - if(!localize)mf.setNonLocalized(); - return mf.formatDateTime(tm); -} - -// ///////////////////////////////////// -// local formatting class -#include -class MLocalFormat::Private:public SharedDPtr -{ - public: - QStringList m_day,m_sday,m_month,m_smonth; - QString m_am,m_pm,m_timezone,m_dateformat,m_timeformat,m_datetimeformat; - QChar m_decimal,m_thousand; - - QString m_currency,m_moneyneg,m_moneypos; - int m_moneydecimals,m_thousanddigits; - bool m_moneysymbehind; - MOServerFormat::MoneyPos m_moneynegpos,m_moneypospos; -}; -DEFINE_SHARED_DPTR(MLocalFormat); - -//static -MLocalFormat MLocalFormat::defaultformat((int)1); - -MLocalFormat::MLocalFormat(int) -{ - d->m_moneydecimals=2; - d->m_thousanddigits=3; - d->m_timezone="UTC"; - d->m_am="AM"; - d->m_pm="PM"; - //set defaults - setWeekDays();setShortWeekDays(); - setMonths();setShortMonths(); - setMoneyFormat();setNumberFormat(); - setDateTimeFormat(); -} - -MLocalFormat::MLocalFormat(const MOServerFormat& s) -{ - //init from current default - operator=(defaultformat); - //overwrite with new settings - QStringList sl; - sl=s.weekdays();if(sl.size()==7)setWeekDays(sl);else setWeekDays(); - sl=s.shortweekdays();if(sl.size()==7)setShortWeekDays(sl);else setShortWeekDays(); - sl=s.months();if(sl.size()==12)setMonths(sl);else setMonths(); - sl=s.shortmonths();if(sl.size()==12)setShortMonths(sl);else setShortMonths(); - setMoneyFormat(s.currencysymbol(),s.moneydecimals(),s.currencysymbolpos()); - setMoneySign(s.moneynegative(),s.moneypositive(),s.moneynegativepos(),s.moneypositivepos()); - setNumberFormat(s.decimaldot().value().at(0), s.thousandseparator().value().at(0), s.thousanddigits().value()); - setAP(s.amtext(),s.pmtext()); - setTimeZone(s.timezone()); - setDateTimeFormat(s.dateformat(),s.timeformat(),s.datetimeformat()); -} - -QStringList MLocalFormat::weekDayNames()const{return d->m_day;} -QStringList MLocalFormat::shortWeekDayNames()const{return d->m_sday;} -QStringList MLocalFormat:: monthNames()const{return d->m_month;} -QStringList MLocalFormat::shortMonthNames()const{return d->m_smonth;} -QString MLocalFormat::currency()const{return d->m_currency;} -QChar MLocalFormat::decimalDot()const{return d->m_decimal;} -QString MLocalFormat::thousandSeparator()const -{ - if(d->m_thousanddigits>0) - return d->m_thousand; - else return ""; -} -int MLocalFormat::thousandDigits()const{return d->m_thousanddigits;} -int MLocalFormat::moneyDecimals()const{return d->m_moneydecimals;} -QString MLocalFormat::amText()const{return d->m_am;} -QString MLocalFormat::pmText()const{return d->m_pm;} -QString MLocalFormat::moneyNegativeSign()const{return d->m_moneyneg;} -QString MLocalFormat::moneyPositiveSign()const{return d->m_moneypos;} -QString MLocalFormat::dateFormat()const{return d->m_dateformat;} -QString MLocalFormat::timeFormat()const{return d->m_timeformat;} -QString MLocalFormat::dateTimeFormat()const{return d->m_datetimeformat;} -QString MLocalFormat::timeZone()const{return d->m_timezone;} - -//static -void MLocalFormat::setDefaultFormat(const MLocalFormat& f) -{ - defaultformat=f; - TimeStamp::setDefaultZone(f.d->m_timezone); -} - - -MLocalFormat::MLocalFormat() -{ - operator=(defaultformat); -} - - -void MLocalFormat::setWeekDays(const QStringList&w) -{ - d.decouple(); - if(w.size()==0){ - d->m_day=QStringList() - <m_day=w; -} -void MLocalFormat::setShortWeekDays(const QStringList&w) -{ - d.decouple(); - if(w.size()==0){ - d->m_sday=QStringList() - <m_sday=w; -} -void MLocalFormat::setMonths(const QStringList&m) -{ - d.decouple(); - if(m.size()==0){ - d->m_month=QStringList() - <m_month=m; -} -void MLocalFormat::setShortMonths(const QStringList&m) -{ - d.decouple(); - if(m.size()==0){ - d->m_smonth=QStringList() - <m_smonth=m; -} - -void MLocalFormat::setDateTimeFormat(QString dateformat, QString timeformat, QString datetimeformat) -{ - d.decouple(); - if(dateformat=="")d->m_dateformat=QCoreApplication::translate("MLocalFormat","%Y-%M-%D","date format"); - else d->m_dateformat=dateformat; - if(timeformat=="")d->m_timeformat=QCoreApplication::translate("MLocalFormat","%h:%I","time format"); - else d->m_timeformat=timeformat; - if(datetimeformat=="")d->m_datetimeformat=QCoreApplication::translate("MLocalFormat","%Y-%M-%D %h:%I","date and time format"); - else d->m_datetimeformat=datetimeformat; -} - - -void MLocalFormat::setMoneyFormat(QString c,int n,bool s) -{ - d.decouple(); - d->m_currency=c; - d->m_moneydecimals=n; - d->m_moneysymbehind=s; -} - -void MLocalFormat::setMoneySign(QString n,QString p, MOServerFormat::MoneyPos np, MOServerFormat::MoneyPos pp) -{ - d.decouple(); - d->m_moneyneg=n;d->m_moneypos=p; - d->m_moneynegpos=np;d->m_moneypospos=pp; -} - -void MLocalFormat::setAP(QString am,QString pm) -{ - d.decouple(); - - if(am=="--")d->m_am=QCoreApplication::translate("MLocalFormat","am","AM/PM time component"); - else d->m_am=am; - if(pm=="--")d->m_pm=QCoreApplication::translate("MLocalFormat","pm","AM/PM time component"); - else d->m_pm=pm; -} - -void MLocalFormat::setNumberFormat(QChar dec,QChar thou,int dig) -{ - d.decouple(); - - if(dec.isNull())d->m_decimal=QCoreApplication::translate("MLocalFormat",".","decimal dot")[0]; - else d->m_decimal=dec; - - if(thou.isNull())d->m_thousand=QCoreApplication::translate("MLocalFormat",",","thousand division character")[0]; - else d->m_thousand=thou; - - if(dig<0)d->m_thousanddigits=QCoreApplication::translate("MLocalFormat","0","digits between thousand division chars, <=0 means none").toInt(); - else d->m_thousanddigits=dig; -} - -void MLocalFormat::setNonLocalized() -{ - d.decouple(); - //reset number format - d->m_decimal='.';d->m_thousanddigits=0; - //reset money signs - setMoneyFormat();setMoneySign(); -} - - -QString MLocalFormat::formatDate(const QDate&date,QString format)const -{ - return formatDate(TimeStamp(date,d->m_timezone),format); -} -QString MLocalFormat::formatDate(const TimeStamp& date, QString format) const -{ - if(format=="")format=d->m_dateformat; - return formatDateTime(date,format); -} -QString MLocalFormat::formatDate(qint64 date,QString format)const -{ - return formatDate(TimeStamp(date,d->m_timezone),format); -} -QString MLocalFormat::formatTime(const TimeStamp& time, QString format) const -{ - if(format=="")format=d->m_timeformat; - return formatDateTime(time,format); -} -QString MLocalFormat::formatTime(const QTime&time,QString format)const -{ - return formatTime(TimeStamp(time,d->m_timezone),format); -} -QString MLocalFormat::formatTime(qint64 time,QString format)const -{ - return formatTime(TimeStamp(time,d->m_timezone),format); -} -QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const -{ - return formatDateTime(TimeStamp(time,d->m_timezone),format); -} -QString MLocalFormat::formatDateTime(const TimeStamp& ts, QString format) const -{ - if(format=="")format=d->m_datetimeformat; - //parse - TimeStamp time=ts.toZone(d->m_timezone); - QString out; - bool inp=false; - for(int i=0;im_smonth.value(time.month()-1);break; - case 'N':out+=d->m_month.value(time.month()-1);break; - case 'd':out+=QString::number(time.day());break; - case 'D':{ - QString m=QString::number(time.day()); - if(m.size()<2)m="0"+m; - out+=m; - break; - } - case 'w':out+=d->m_sday.value(time.weekDay());break; - case 'W':out+=d->m_day.value(time.weekDay());break; - //time formats - case 'h':out+=QString::number(time.hour());break; - case 'H':{ - QString t=QString::number(time.hour()); - if(t.size()<2)t="0"+t; - out+=t; - break; - } - case 'i':out+=QString::number(time.minute());break; - case 'I':{ - QString t=QString::number(time.minute()); - if(t.size()<2)t="0"+t; - out+=t; - break; - } - case 's':out+=QString::number(time.second());break; - case 'S':{ - QString t=QString::number(time.second()); - if(t.size()<2)t="0"+t; - out+=t; - break; - } - case 'z':out+=QString::number(time.msecs());break; - case 'Z':{ - QString t=QString::number(time.msecs()); - while(t.size()<3)t="0"+t; - out+=t; - break; - } - case 'a':{ - int t=time.hour()%12;if(t==0)t=12; - out+=QString::number(t); - break; - } - case 'A':{ - int th=time.hour()%12;if(th==0)th=12; - QString t=QString::number(th); - if(t.size()<2)t="0"+t; - out+=t; - break; - } - case 'p':{ - int t=time.hour(); - if(t>=1 && t<=12)out+=d->m_am.toLower(); - else out+=d->m_pm.toLower(); - break; - } - case 'P':{ - int t=time.hour(); - if(t>=1 && t<=12)out+=d->m_am; - else out+=d->m_pm; - break; - } - case 't': - case 'T':{ - //get diff from UTC - int d=time.offsetFromUTC()/60; - //west(-) or east(+)? - QString t; - if(d<0){t="-";d*=-1;}else t="+"; - //append - out+=QString("%1%2:%3") - .arg(t) - .arg(int(d/60),2,10,QChar('0')) - .arg(int(d%60),2,10,QChar('0')); - break; - } - case 'o':out+=time.zoneAbbreviation();break; - case 'O':out+=d->m_timezone;break; - // % sign - case '%':out+="%";break; - //mistakes - default:out+="%"+format[i];break; - } - inp=false; - }else{ - if(format[i]=='%')inp=true; - else out+=format[i]; - } - } - //catch mistaken % at end - if(inp)out+="%"; - //return result - return out; -} - -QString MLocalFormat::formatDateTime(qint64 time,QString format)const -{ - return formatDateTime(TimeStamp(time,d->m_timezone),format); -} - -QString MLocalFormat::formatNumber(qint64 n)const -{ - //shortcut if we use standard format anyway - if(d->m_thousanddigits<=0)return QString::number(n); - //convert number to decimals - bool neg=false; - if(n<0){n*=-1;neg=true;} - QString s=QString::number(n); - //insert dividers - QString r; - int l=s.size(); - for(int i=0;i0 && ((l-i)%d->m_thousanddigits)==0)r+=d->m_thousand; - r+=s[i]; - } - if(neg)r="-"+r; - return r; -} - -QString MLocalFormat::formatNumber(double num,uint decimals)const -{ - //check negative - bool neg=false; - if(num<0.){num*=-1.;neg=true;} - //before the dot - qint64 be=floorl(num); - QString r=formatNumber(be); - //fractions - if(decimals>0){ - r+=d->m_decimal; - num-=be; - for(int i=0;i<(int)decimals;i++){ - num*=10.; - int d=floorl(num); - r+=QString::number(d); - num-=d; - } - } - //add negative sign - if(neg)r="-"+r; - //result - return r; -} - -QString MLocalFormat::formatMoney(qint64 num,bool usethousand)const -{ - return formatMoney(num,(usethousand?UseThousand:0)|ShowCurrencySymbol); -} - - -QString MLocalFormat::formatMoney(qint64 num, MLocalFormat::MoneyFlags flags) const -{ - //check value - bool neg=false; - if(num<0){num*=-1;neg=true;} - //split main and fraction - qint64 mod=1;for(int i=0;im_moneydecimals;i++)mod*=10; - qint64 frac=num%mod; - num/=mod; - //create main unit - QString ms; - if(flags&UseThousand)ms=formatNumber(num); - else ms=QString::number(num); - //create fractional unit - QString fs=QString::number(frac); - for(int i=fs.size();im_moneydecimals;i++)fs="0"+fs; - //combine and get currency symbol - QString r=ms+d->m_decimal+fs; - QString curr; - if(flags&ShowCurrencySymbol)curr=d->m_currency; - //add sign - QString sign; - if(neg)sign=d->m_moneyneg; - else sign=d->m_moneypos; - switch(neg?d->m_moneynegpos:d->m_moneypospos){ - case MOServerFormat::NoSign:break; - case MOServerFormat::SignParen:r="("+r+")";break; - case MOServerFormat::SignAfterSym:curr+=sign;break; - case MOServerFormat::SignBeforeSym:curr=sign+curr;break; - case MOServerFormat::SignAfterNum:r+=sign;break; - case MOServerFormat::SignBeforeNum: - default: - r=sign+r; - break; - } - //add currency - if(!curr.isEmpty()){ - if(d->m_moneysymbehind)r+=" "+curr; - else r=curr+" "+r; - } - //return result - return r; -} - -qint64 MLocalFormat::scanInt(QString num)const -{ - num=num.trimmed(); - qint64 r=0; - bool neg=false; - for(int i=0;im_thousand)continue; - //non-numericals break - else break; - } - if(neg)r*=-1; - return r; -} -qint64 MLocalFormat::scanMoney(QString num)const -{ - //init - num=num.trimmed(); - qint64 r=0,dd=0,nd=0; - bool neg=false,frc=false; - //scan string; r=main unit; d=fractions - for(int i=0;im_moneyneg.contains(c) || c=='-')neg=true;else - //decimal dot - if(c==d->m_decimal)frc=true;else - //digits - if(c.isDigit()){ - if(frc){ - if(nd>=d->m_moneydecimals)break; - dd*=10;dd+=c.digitValue(); - nd++; - }else{ - r*=10;r+=c.digitValue(); - } - }else - //ignore thousand divider - if(c==d->m_thousand)continue; - //non-numericals break - else break; - } - //move main to left - for(int i=0;im_moneydecimals;i++)r*=10; - //add fractions - for(;ndm_moneydecimals;nd++)dd*=10; - r+=dd; - //negative? - if(neg)r*=-1; - //result - return r; -} - -double MLocalFormat::scanFloat(QString num)const -{ - //init - num=num.trimmed(); - double r=0.; - double ff=1.; - bool neg=false,frc=false; - //scan - for(int i=0;im_decimal)frc=true;else - //digits - if(c.isDigit()){ - if(frc){ - ff/=10.; - r+=c.digitValue()*ff; - }else{ - r*=10.; - r+=c.digitValue(); - } - }else - //ignore thousand divider - if(c==d->m_thousand)continue; - //non-numericals break - else break; - } - //return - if(neg)r*=-1.; - return r; -} - -QRegExp MLocalFormat::moneyRegExp(bool allownegative,bool allowcurrency)const -{ - //main unit - QString r="[\\d"+QRegExp::escape(d->m_thousand)+"]+"; - //fractions - if(d->m_moneydecimals>0){ - r+=QRegExp::escape(d->m_decimal); - r+="\\d{"+QString::number(d->m_moneydecimals)+"}"; - } - //negative - if(allownegative){ - //front - QString f="[-"; - if(d->m_moneyneg.size()>0) - if(d->m_moneyneg[0]!='\n' && d->m_moneyneg[0]!='-') - f+=QRegExp::escape(d->m_moneyneg[0]); - f+="]?"; - r=f+r; - //back - if(d->m_moneyneg.size()>1) - r+=QRegExp::escape(d->m_moneyneg[1])+"?"; - } - //currency - if(allowcurrency && d->m_currency!="") - r+="("+QRegExp::escape(d->m_currency)+")?"; - //return - return QRegExp(r); -} - -void MLocalFormat::setTimeZone(QString olsonname) -{ - d.decouple(); - if(TimeStamp::loadZone(olsonname)) - d->m_timezone=olsonname; -} - -QString currentDir() -{ - return QSettings().value("lastUsedDirectory",".").toString(); -} - -void setCurrentDir(QString fn) -{ - if(fn.isEmpty())return; - QFileInfo fi(fn); - //it is already a directory - if(fi.isDir())QSettings().setValue("lastUsedDirectory",fi.absoluteFilePath()); - //it is probably a file - else { - //get parent directory name - fn=fi.dir().absolutePath(); - if(QFileInfo(fn).isDir()) - QSettings().setValue("lastUsedDirectory",fn); - //abort if not found by now, this was bogus - } -} diff --git a/src/misc/misc.h b/src/misc/misc.h deleted file mode 100644 index 2d4c496..0000000 --- a/src/misc/misc.h +++ /dev/null @@ -1,298 +0,0 @@ -// -// C++ Interface: misc -// -// Description: miscellaneous helper functions -// -// -// Author: Konrad Rosenbaum , (C) 2008-2012 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MISC_H -#define MAGICSMOKE_MISC_H - -#include -#include -#include -#include - -class TimeStamp; -#include -#include - -/**converts special HTML characters into harmless &-codes, so the text can be included*/ -QString htmlize(QString str); - -/**converts special XML characters into harmless &-codes, so the text can be included*/ -QString xmlize(QString str,QString newline="\n"); -/**converts special XML characters into harmless &-codes, so the text can be included*/ -QByteArray xmlize(QByteArray str,QString newline="\n"); - -/**converts a cent value into a (localized) string*/ -QString cent2str(qint64 cent,bool localize=true); - -/**converts a (localized) string back into a cent value (must not contain spaces or extra dots)*/ -qint64 str2cent(QString s,bool fromlocal=true); - -/**converts a unix timestamp into a date*/ -QString unix2date(qint64,bool localize=true); - -/**converts a unix timestamp into a time (ommitting the date)*/ -QString unix2time(qint64,bool localize=true); - -/**converts a unix timestamp into a date-time-string*/ -QString unix2dateTime(qint64,bool localize=true); - -/**return a (localized) regular expression that validates prices*/ -QRegExp priceRegExp(bool localize=true); - -///returns the current directory (the one last used in a file dialog) -QString currentDir(); - -///sets a new current directory (transparently handles files and directories) -void setCurrentDir(QString); - -/**localized formatter class for timestamps, numbers and money; -per default it uses the local translation to format data, but can be overidden; - -date values can be formatted with the following variables: - - - - - - - - - - - -
%%ytwo-digit year (eg. 08)
%%Yfour-digit year (eg. 1908)
%%mmonth as simple number (eg. 7)
%%Mmonth as two digit number (eg. 07)
%%nshort name of the month (eg. Jul)
%%Nlong name of the month (eg. July)
%%dday of the month as simple number (eg. 5)
%%Dday of the month as two digit number (eg. 05)
%%wday of the week as short name (eg. Wed)
%%Wday of the week as long name (eg. Wednesday)
- -time values can be formatted with the following variables: - - - - - - - - - - - - - - - - - -
%%hhour as simple number (eg. 7) in 24-hour format
%%Hhour as two digit number (eg. 07) in 24-hour format
%%ahour as simple number (eg. 7) in 12-hour format
%%Ahour as two digit number (eg. 07) in 12-hour format
%%iminute as simple number (eg. 7)
%%Iminute as two digit number (eg. 07)
%%ssecond as simple number (eg. 7)
%%Ssecond as two digit number (eg. 07)
%%zmilli-seconds as simple number (eg. 7)
%%Zmilli-seconds as three digit number (eg. 007)
%%p"am" or "pm" according to current time, this is the one set with setAP
%%P"AM" or "PM" according to current time, this is toUpper executed on the one set with setAP
%%TISO timezone as +/-hhmm (eg. -0100 or +0100)
%%tISO timezone as +/-hh:mm (eg. -01:00 or +01:00)
%%otimezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET")
%%Otimezone as Olson name (eg. "Europe/Berlin")
- -Any occurrence of "%%" will be translated to a literal "%" sign. - -For example "%w the %d'th of %N in the year of the lord %Y at %a:%I %P" will be formatted as "Sat 19'th of June in the year of the lord 2010 at 8:29 AM". -*/ -class MLocalFormat -{ - DECLARE_SHARED_DPTR(d); - public: - /**constructs a formatter object that corresponds to the default*/ - MLocalFormat(); - /**copies a formatter object inheriting its overrides*/ - MLocalFormat(const MLocalFormat&)=default; - /**initializes the formatter object from a server format object*/ - MLocalFormat(const MOServerFormat&); - /**deletes the formatter object*/ - virtual ~MLocalFormat(){} - - /**sets a new default format*/ - static void setDefaultFormat(const MLocalFormat&); - - /**copies a formatter object*/ - virtual MLocalFormat& operator=(const MLocalFormat&)=default; - - /**overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday*/ - virtual void setWeekDays(const QStringList&l=QStringList()); - /**overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday (Sun)*/ - virtual void setShortWeekDays(const QStringList&l=QStringList()); - - /**overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January*/ - virtual void setMonths(const QStringList&l=QStringList()); - /**overrides the short names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January (Jan)*/ - virtual void setShortMonths(const QStringList&l=QStringList()); - - /**overrides the formatting of money - the settings of numbers are re-used - \param digitsCents defines how many digits are used for sub-amounts (cents), if zero no cents are used, normal are the values 0, 2 and 3; the default is 2 - \param currency defines the symbol of the currency used, the default is an empty string - \param symbolBehind defines whether the currency symbol is shown before (false) or behind (true) the numeric value - */ - virtual void setMoneyFormat(QString currency=QString(),int digitsCents=2, bool symbolBehind=true); - /**overrides the formatting of money - the settings of numbers are re-used - \param negative defines the sign for negative values, the default is "-" - \param positive defines the sign for positive values, the default is an empty string - \param negativePos defines where the negative sign is printed - \param positivePos defines where the positive sign is printed - */ - virtual void setMoneySign(QString negative="-",QString positive=QString(), MOServerFormat::MoneyPos negativePos=MOServerFormat::SignBeforeNum, MOServerFormat::MoneyPos positivePos=MOServerFormat::NoSign); - - /**overrides the formatting of numbers and money; - \param decimal defines the character used to separate decimals from the main body, if QChar() is used it returns to the translation default (a dot "." in default localization) - \param thousandDiv defines the character used to separate blocks of digits, if QChar() is used it returns to the translation default (comma "," in default) - \param digitsDiv defines the amount of digits in a block, eg. the value 3 will format 1000 as 1,000 (none per default)*/ - virtual void setNumberFormat(QChar decimal=QChar(),QChar thousandDiv=QChar(),int digitsDiv=-1); - - /**overrides the formatting of the AM/PM part of time display, resets to the localization if none given*/ - virtual void setAP(QString am="--",QString pm="--"); - - /**overrides the local time zone - \param olsonname the name of the local timezone in Olson notation, eg. "Europe/Berlin"*/ - virtual void setTimeZone(QString olsonname); - - /**overrides the default formatting of date and time, if empty the translation default is used*/ - virtual void setDateTimeFormat(QString dateformat=QString(),QString timeformat=QString(),QString datetimeformat=QString()); - - /**returns the currently set time zone of this formatter*/ - virtual QString timeZone()const; - - /**overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str*/ - virtual void setNonLocalized(); - - /**formats a date according to the given format, if none is given, the translation default is used - \param date a QDate used as input, it is assumed to be local - \param format a format string */ - virtual QString formatDate(const QDate&date,QString format=QString())const; - /**formats a date according to the given format, if none is given, the translation default is used - \param date a unix timestamp, it is converted to the local time of this local format object - \param format a format string */ - virtual QString formatDate(qint64 date,QString format=QString())const; - /**formats a date according to the given format, if none is given, the translation default is used - \param date a timestamp, it is converted to the local time of this local format object - \param format a format string */ - virtual QString formatDate(const TimeStamp& date,QString format=QString())const; - - /**formats a time according to the given format, if none is given, the translation default is used - \param time a QTime used as input, it is assumed to be local - \param format a format string */ - virtual QString formatTime(const QTime&time,QString format=QString())const; - /**formats a time according to the given format, if none is given, the translation default is used - \param time a unix timestamp, it is converted to local time - \param format a format string */ - virtual QString formatTime(qint64 time,QString format=QString())const; - /**formats a time according to the given format, if none is given, the translation default is used - \param time a timestamp, it is converted to the local time of this local format object - \param format a format string */ - virtual QString formatTime(const TimeStamp& time,QString format=QString())const; - - /**formats a date and time according to the given format, if none is given, the translation default is used - \param time a QDateTime used as input, it is assumed to be local - \param format a format string as specified by QDateTime::toString */ - virtual QString formatDateTime(const QDateTime&time,QString format=QString())const; - /**formats a date and time according to the given format, if none is given, the translation default is used - \param time a unix timestamp, it is converted to local time - \param format a format string as specified by QDateTime::toString */ - virtual QString formatDateTime(qint64 time,QString format=QString())const; - /**formats a date and time according to the given format, if none is given, the translation default is used - \param time a TimeStamp used as input, it is converted to the local time of this local format object - \param format a format string as specified by QDateTime::toString */ - virtual QString formatDateTime(const TimeStamp&time,QString format=QString())const; - - - /**formats an integer number*/ - virtual QString formatNumber(qint64)const; - /**formats an integer number*/ - virtual QString formatNumber(int n)const{return formatNumber(qint64(n));} - /**formats an integer number*/ - virtual QString formatNumber(uint n)const{return formatNumber(qint64(n));} - - /**formats a floating point number, this version does not use exponential display, but adheres to the settings of local decimal dot and thousands block division - \param num the number to be formatted - \param decimals the maximum number of digits after the decimal dot*/ - virtual QString formatNumber(double num,uint decimals=4)const; - - enum MoneyFlag { - PlainMoneyFormat=0, - UseThousand=1, - ShowCurrencySymbol=2, - - DefaultFormat=UseThousand|ShowCurrencySymbol - }; - Q_DECLARE_FLAGS(MoneyFlags,MoneyFlag); - - /**formats a money value - \param num the amount in cents - \param flags determines how the string will be formatted */ - virtual QString formatMoney(qint64 num,MoneyFlags flags=DefaultFormat)const; - /**formats a money value - \param num the amount in cents - \param usethousand if true the thousand block division is inserted */ - virtual QString formatMoney(qint64 num,bool usethousand)const; - - /**scans an integer number and returns the value, non-numerical chars are ignored*/ - virtual qint64 scanInt(QString)const; - - /**scans a money value and returns it in cents, non-numerical chars are ignored*/ - virtual qint64 scanMoney(QString)const; - - /**scans a floating point number and returns it, non-numerical chars are ignored*/ - virtual double scanFloat(QString)const; - - /**returns the names used for week days*/ - QStringList weekDayNames()const; - /**returns the abbreviations used for week days*/ - QStringList shortWeekDayNames()const; - - /**returns the names used for months*/ - QStringList monthNames()const; - /**returns the names used for months*/ - QStringList shortMonthNames()const; - - /**returns the currency symbol*/ - QString currency()const; - - /**returns the decimal dot symbol*/ - QChar decimalDot()const; - - /**returns the thousand separator if used, otherwise an empty string*/ - QString thousandSeparator()const; - - /**returns the amount of digits between thousand separators*/ - int thousandDigits()const; - - /**returns the amount of decimals in a money value*/ - int moneyDecimals()const; - - /**returns the text for AM in 12-hour clock format*/ - QString amText()const; - /**returns the text for PM in 12-hour clock format*/ - QString pmText()const; - - /**returns the negative sign for money values*/ - QString moneyNegativeSign()const; - /**returns the positive sign for money values*/ - QString moneyPositiveSign()const; - - /**returns a regular expression matching money values - \param allownegative if given the resulting RegExp allows to use negative values - \param allowcurrency if given the resulting RegExp allows to use the currency symbol */ - QRegExp moneyRegExp(bool allownegative=false,bool allowcurrency=false)const; - - /**returns the default format for dates*/ - QString dateFormat()const; - - /**returns the default format for times*/ - QString timeFormat()const; - - /**returns the default format for date/time*/ - QString dateTimeFormat()const; - protected: - /** \internal constructs the default object from the translation*/ - MLocalFormat(int); - /** \internal default format*/ - static MLocalFormat defaultformat; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(MLocalFormat::MoneyFlags); - -#endif diff --git a/src/misc/misc.pri b/src/misc/misc.pri index 9739a91..229639f 100644 --- a/src/misc/misc.pri +++ b/src/misc/misc.pri @@ -1,18 +1,14 @@ HEADERS += \ $$PWD/debug.h \ - $$PWD/misc.h \ $$PWD/waitcursor.h \ $$PWD/sclock.h \ - $$PWD/formula.h \ $$PWD/dommodel.h SOURCES += \ $$PWD/code39.cpp \ $$PWD/debug.cpp \ - $$PWD/misc.cpp \ $$PWD/waitcursor.cpp \ $$PWD/sclock.cpp \ - $$PWD/formula.cpp \ $$PWD/dommodel.cpp INCLUDEPATH += $$PWD diff --git a/src/misc/waitcursor.cpp b/src/misc/waitcursor.cpp index 270e885..a43dbad 100644 --- a/src/misc/waitcursor.cpp +++ b/src/misc/waitcursor.cpp @@ -4,13 +4,14 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2009-2011 +// Author: Konrad Rosenbaum , (C) 2009-2013 // // Copyright: See README/COPYING.GPL files that come with this distribution // // #include "waitcursor.h" +#include #include #include @@ -24,3 +25,13 @@ WaitCursor::~WaitCursor() { QApplication::restoreOverrideCursor(); } + +static int transactionCursor() +{ + MTransaction::setStartStopActions( + []{QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));}, + []{QApplication::restoreOverrideCursor();} + ); +} + +static int tcdummy=transactionCursor(); \ No newline at end of file diff --git a/src/smoke.pro b/src/smoke.pro index 996ce1a..6e91bc0 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -3,7 +3,6 @@ TEMPLATE = lib TARGET = magicsmoke -DESTDIR = $$PWD/../bin VERSION = #Localization @@ -12,15 +11,6 @@ TRANSLATIONS = \ smoke_de_SAX.ts \ smoke_en.ts -#hide classes that are not explicitly exported -# this is default on Windows, we have it here to have all systems behave the same way -CONFIG += hide_symbols - -#compilation output: -OBJECTS_DIR = .ctmp -MOC_DIR = .ctmp -RCC_DIR = .ctmp - #main source files SOURCES = main.cpp HEADERS = main.h @@ -39,28 +29,16 @@ DEFINES += HOMEPAGE_BASEURL=\\\"http://smoke.silmor.de\\\" RESOURCES += images/files.qrc #libraries, modules, stuff... -include(libs.pri) include(widgets/widgets.pri) include(templates/templates.pri) -include(iface/iface.pri) include(misc/misc.pri) include(crypto/crypto.pri) include(dialogs/dialogs.pri) include(mwin/mwin.pri) include(script/script.pri) -#build generated stuff last -include(wext/wext.pri) -include(wob/wob.pri) +include (../basics.pri) +include (libs.pri) #make sure dependencies are found DEPENDPATH += $$INCLUDEPATH -LIBS += -L$$PWD/../bin - -#protect the stack -QMAKE_CFLAGS += -fstack-protector-all -Wstack-protector -QMAKE_CXXFLAGS += -fstack-protector-all -Wstack-protector -win32 { - QMAKE_LFLAGS += -Wl,--nxcompat - LIBS += -lssp -} diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index ff720f5..00680df 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2008-2011 +// Author: Konrad Rosenbaum , (C) 2008-2013 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -28,25 +28,18 @@ #include #include -MTemplateChoice::MTemplateChoice(const QString&cd,const QString&tname,const QStringList&choices,const QString&sg) - :sgroup(sg),cachedir(cd) +MTemplateChoice::MTemplateChoice(const QList&tl) + :templst(tl) { setWindowTitle(tr("Chose Template")); setSizeGripEnabled(true); QVBoxLayout *vl; setLayout(vl=new QVBoxLayout); - vl->addWidget(new QLabel(tr("Please chose a variant of template %1:").arg(tname))); + vl->addWidget(new QLabel(tr("Please chose a variant of template %1:").arg(templst.value(0).fileName()))); vl->addWidget(box=new QComboBox); box->setEditable(false); - QSettings set; - set.beginGroup(sg); - for(int i=0;i1)v=vs[1]; - else v=tr("(default)","default template pseudo-variant"); - d=set.value(choices[i]+"/description").toString(); - box->addItem(v+": "+d,choices[i]); + for(const MTemplate&tmp:templst){ + box->addItem(tmp.fileName()+": "+tmp.description()); } vl->addStretch(1); QHBoxLayout *hl; @@ -60,14 +53,20 @@ MTemplateChoice::MTemplateChoice(const QString&cd,const QString&tname,const QStr MTemplate MTemplateChoice::choice()const { - QString fn=box->itemData(box->currentIndex()).toString(); - QSettings set; - set.beginGroup(sgroup+"/"+fn); - return MTemplate(cachedir+"/"+fn, set.value("checksum").toString(), set.value("description").toString(), set.value("flags").toString()); + return templst.value(box->currentIndex()); } - - +static inline int initTemplateChoser() +{ + MTemplate::setTemplateChoiceFunction([](const QList&tl)->MTemplate{ + MTemplateChoice tc(tl); + if(tc.exec()==QDialog::Accepted) + return tc.choice(); + return MTemplate(); + }); + return 0; +} +static int dummy=initTemplateChoser(); /**************************************************************/ MTemplateEditor::MTemplateEditor(MTemplateStore*s) diff --git a/src/templates/templatedlg.h b/src/templates/templatedlg.h index 640689d..316980d 100644 --- a/src/templates/templatedlg.h +++ b/src/templates/templatedlg.h @@ -29,15 +29,15 @@ class MTemplateChoice:public QDialog { Q_OBJECT public: - MTemplateChoice(const QString&,const QString&,const QStringList&,const QString&); + MTemplateChoice(const QList&); ///returns the choice made by the user MTemplate choice()const; private: //selection box QComboBox*box; - //settings group where to find data - QString sgroup,cachedir; + //data + QListtemplst; }; /**lets the user add and remove templates and variants to/from the database; used by MWebRequest!*/ diff --git a/src/templates/templates.cpp b/src/templates/templates.cpp deleted file mode 100644 index 5e10ea1..0000000 --- a/src/templates/templates.cpp +++ /dev/null @@ -1,426 +0,0 @@ -// -// C++ Implementation: templates -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -/***************************** - * Settings hierarchy for templates: - * - * /templates/$PROFILEID -> template settings for this profile - * .../$TEMPLATENAME -> the settings for a template, uses the complete name (eg. bill.odtt,2) - * ....../checksum -> key that stores the checksum (calculated by server!!) - * ....../description -> key that stores the description (as received from server) - * - * - * Template buffer on disk: - * - * req->dataDir()/templates -> directory for template files; - * each file is stored with complete name, no meta-info - ***************************/ - -#include "main.h" -#include "templatedlg.h" -#include "templates.h" -#include "msinterface.h" - -#include "MTGetTemplateList" -#include "MTGetTemplate" -#include "MTSetTemplate" -#include "MTDeleteTemplate" -#include "MTSetTemplateDescription" -#include "MTSetTemplateFlags" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -MTemplateStore::MTemplateStore(QString p) -{ - profileid=p; -} - -MTemplate MTemplateStore::getTemplate(QString f) -{ - //syntax check - f=f.toLower(); - QRegExp fregexp("[a-z0-9_]+"); - if(!fregexp.exactMatch(f))return MTemplate(); - //update directory (no force) - updateTemplates(false); - //find files matching the pattern - //basics - QString dname=req->dataDir()+"/templates/"; - QSettings set; - set.beginGroup("templates/"+profileid); - //get directory - QStringList dir=set.childGroups(); - QStringList tdir; - MSInterface*ifc=MSInterface::instance(); - for(int i=0;icheckFlags(set.value(dir[i]+"/flags").toString())) - tdir<dataDir()+"/templates/"; - QSettings set; - set.beginGroup("templates/"+profileid); - //check directory - if(!set.childGroups().contains(f))return MTemplate(); - //return if found - return MTemplate(dname+"/"+f, set.value(f+"/checksum").toString(), set.value(f+"/description").toString(), set.value(f+"/flags").toString()); -} - -void MTemplateStore::updateTemplates(bool force) -{ - //basics - QString dname=req->dataDir()+"/templates/"; - QSettings set; - set.beginGroup("templates/"+profileid); - //make sure directory exists - QDir(req->dataDir()).mkpath("templates"); - //do we need an update yet? - QDateTime last=QDateTime::fromTime_t(set.value("lastupdate",0).toInt()+300); - if(last>=QDateTime::currentDateTime() && !force)return; - - //get local info - QStringList files=set.childGroups(); - QMap fmap; - for(int i=0;iqueryGetTemplateList(); - if(gtl.hasError())return; - //remember update time - set.setValue("lastupdate",QDateTime::currentDateTime().toTime_t()); - //scan and create new list - QListnf=gtl.gettemplates(); - QMapnfmap; - for(int i=0;iqueryGetTemplate(fn); - if(gt.hasError())return false; - //store - QFile f(dname+"/"+fn); - if(!f.open(QIODevice::WriteOnly|QIODevice::Truncate))return false; - f.write(gt.gettemplatefile().value().content()); - return true; -} - -bool MTemplateStore::setTemplate(QString n,QString f) -{ - //very rough sanity check - QRegExp fregexp("[a-z0-9_\\.,]+"); - if(!fregexp.exactMatch(n))return false; - //get content - QFile fl(f); - if(!fl.open(QIODevice::ReadOnly)) - return false; - QByteArray ba=fl.readAll(); - fl.close(); - //send to server - MTSetTemplate st=req->querySetTemplate(n,ba,""); - if(st.hasError()) - return false; - //delete it from cache, so it is retrieved again; force retrieval - //TODO: the server returns the hash (since dec08), use it and update the cache without retrieval - QSettings set; - set.remove("templates/"+profileid+"/"+n); - set.setValue("templates/"+profileid+"/lastupdate",0); - QFile(req->dataDir()+"/templates/"+n).remove(); - //return success - return true; -} - -bool MTemplateStore::deleteTemplate(QString n) -{ - //very rough sanity check - QRegExp fregexp("[a-z0-9_\\.,]+"); - if(!fregexp.exactMatch(n))return false; - //send to server - MTDeleteTemplate dt=req->queryDeleteTemplate(n); - if(dt.hasError()) - return false; - //delete it from cache - QSettings set; - set.remove("templates/"+profileid+"/"+n); - QFile(req->dataDir()+"/templates/"+n).remove(); - return true; -} - -bool MTemplateStore::setTemplateDescription(QString n,QString d) -{ - //very rough sanity check - QRegExp fregexp("[a-z0-9_\\.,]+"); - if(!fregexp.exactMatch(n))return false; - //check that we have a real change - QSettings set; - set.beginGroup("templates/"+profileid+"/"+n); - QString o=set.value("description").toString(); - qDebug("setting %s '%s' -> '%s'",n.toLatin1().data(),o.toLatin1().data(),d.toLatin1().data()); - if(o==d)return true; - //send to server - MTSetTemplateDescription std=req->querySetTemplateDescription(n,d); - if(std.hasError()) - return false; - //update internal description - set.setValue("description",d); - //return success - return true; -} - -bool MTemplateStore::setTemplateFlags(QString n, QString flags) -{ - //check that we have a real change - QSettings set; - set.beginGroup("templates/"+profileid+"/"+n); - QString o=set.value("flags").toString(); - qDebug("setting %s '%s' -> '%s'",n.toLatin1().data(),o.toLatin1().data(),flags.toLatin1().data()); - if(o==flags)return true; - //send to server - MTSetTemplateFlags std=req->querySetTemplateFlags(n,flags); - if(std.hasError()) - return false; - //update internal description - set.setValue("flags",flags); - //return success - return true; -} - -QList MTemplateStore::allTemplates() -{ - updateTemplates(false); - QString dname=req->dataDir()+"/templates/"; - QSettings set; - set.beginGroup("templates/"+profileid); - QStringList names=set.childGroups(); - QList ret; - for(int i=0;i1)return lst[1]; - return ""; -} - -QString MTemplate::checksum()const{return m_checksum;} - -bool MTemplate::isValid()const{return m_fname!="";} - -QString MTemplate::targetExtension()const -{ - QString x=extension(); - //ODF file? - if(QRegExp("od.t").exactMatch(x))return x.left(3); - //all else: not storable - return ""; -} - -bool MTemplate::isOdf()const{return (type()&OdfTemplateMask)!=0;} - -bool MTemplate::isLabel()const{return type()==LabelTemplate;} -MTemplate::Type MTemplate::type()const -{ - QString x=extension(); - //ODF file? - if(x=="odtt")return OdtTemplate; - if(x=="odst")return OdsTemplate; - if(x=="odpt")return OdpTemplate; - if(x=="odgt")return OdgTemplate; - if(x=="odbt")return OdbTemplate; - //label? - if(x=="xtt")return LabelTemplate; - //script? - if(x=="zip")return ZipTemplate; - //hmm, unknown one - return UnknownTemplate; -} - -QString MTemplate::description()const{return m_descr;} - - -static QStringList tempBaseNames; -//static -QStringList MTemplate::legalBaseNames() -{ - if(tempBaseNames.size()==0){ - tempBaseNames<<"ticket"<<"voucher"<<"bill"<<"eventsummary"<<"scripts"; - } - return tempBaseNames; -} - -//static -MTemplate::Types MTemplate::legalTypes(QString bn) -{ - if(bn=="ticket" || bn=="voucher") - return LabelTemplate; - if(bn=="bill" || bn=="eventsummary") - return OdfTemplateMask; - if(bn=="scripts") - return ZipTemplate; - 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(); -} diff --git a/src/templates/templates.h b/src/templates/templates.h deleted file mode 100644 index 233e880..0000000 --- a/src/templates/templates.h +++ /dev/null @@ -1,174 +0,0 @@ -// -// C++ Interface: templates -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_TEMPLATES_H -#define MAGICSMOKE_TEMPLATES_H - -#include - -/**this class wraps a single template*/ -class MTemplate -{ - public: - /**creates an invalid template*/ - MTemplate(); - - /**creates a temporary template by a physical file name*/ - MTemplate(QString fn); - - /**copies a template*/ - MTemplate(const MTemplate&); - - ///copies a template - MTemplate& operator=(const MTemplate&); - - ///reinitializes the template from the given file name - void setFile(const QString&); - - /**returns the name/path of the cache file, if it exists*/ - QString cacheFileName()const; - - /**returns the file name of the template (eg. mytemplate.odtt)*/ - QString fileName()const; - - /**returns the complete encoded name of the template (eg. mytemplate.odtt,v1)*/ - QString completeFileName()const; - - /**returns the base name of the template (eg. mytemplate for mytemplate.odtt)*/ - QString baseName()const; - - /**returns the extension of the template (eg. odtt for mytemplate.odtt)*/ - QString extension()const; - - /**returns the variant ID of the template (warning: it has no meaning outside the template storage system*/ - QString variantID()const; - - /**returns the checksum (calculated by the server)*/ - QString checksum()const; - - /**returns the description*/ - QString description()const; - - /**returns whether this is a valid template*/ - bool isValid()const; - - /**returns the extension of the target document if it is saved (empty if the template cannot be saved)*/ - QString targetExtension()const; - - /**returns whether this is an ODF template*/ - bool isOdf()const; - - /**returns whether this is a label template*/ - bool isLabel()const; - - ///returns the flags of this template - QString flags()const{return m_flags;} - - /**template type; currently only ODF and Labels are known*/ - enum Type{ - /**uninitialized or unknown label type*/ - UnknownTemplate=0, - /**ODF Text template*/ - OdtTemplate=1, - /**ODF SpreadSheet template*/ - OdsTemplate=2, - /**ODF Presentation*/ - OdpTemplate=4, - /**ODF Drawing*/ - OdgTemplate=8, - /**ODF DataBase*/ - OdbTemplate=0x10, - /**ODF template*/ - OdfTemplateMask=0xff, - /**Label template*/ - LabelTemplate=0x100, - /**Script-Zip template*/ - ZipTemplate=0x200 - }; - Q_DECLARE_FLAGS(Types,Type) - - /**returns the template type*/ - Type type()const; - - /**returns the currently known (by the client) template base names*/ - static QStringList legalBaseNames(); - - /**returns the legal file types (as understood by the client) for a template base name; returns UnknownTemplate if none is legal*/ - static Types legalTypes(QString); - - /**returns the legal template file suffixes (as understood by the client) for a template base name; returns empty if none is legal*/ - static QStringList legalSuffixes(QString); - - protected: - friend class MTemplateStore; - friend class MTemplateChoice; - /**creates a template wrapper from a cache file name; this constructor is used internally in the storage system - \param fn physical file name of the template - \param chk server side check sum of the template - \param dsc description of the template - \param flg flags of the template - */ - MTemplate(QString fn,QString chk,QString dsc,QString flg); - private: - QString m_fname,m_checksum,m_descr,m_flags; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(MTemplate::Types) - -/**this class implements the storage end of the template subsystem, its only instance exists in the webrequest*/ -class MTemplateStore -{ - protected: - friend class MSInterface; - friend class MTemplateEditor; - /**instantiates the template subsystem*/ - MTemplateStore(QString); - - /**stores a specific template*/ - bool setTemplate(QString templatename,QString localfile); - - /**stores a new description for a template*/ - bool setTemplateDescription(QString templatename,QString description); - - ///stores a change of flags for a template - bool setTemplateFlags(QString templatename,QString flags); - - /**deletes a template (requires full name), used by MTemplateEditor*/ - bool deleteTemplate(QString); - - /**updates the template directory, does not do anything if force==false and the last update was less than 5min ago*/ - void updateTemplates(bool force); - - /**returns all templates (for MTemplateEditor)*/ - QList allTemplates(); - - private: - /**unused, just here to remove it from accessability*/ - MTemplateStore(){} - - /**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); - /**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); - - - - private: - QString profileid; -}; - -#endif diff --git a/src/templates/templates.pri b/src/templates/templates.pri index 9790050..cb72c6f 100644 --- a/src/templates/templates.pri +++ b/src/templates/templates.pri @@ -3,7 +3,6 @@ HEADERS += \ $$PWD/ticketrender.h \ $$PWD/office.h \ $$PWD/labeldlg.h \ - $$PWD/templates.h \ $$PWD/templatedlg.h \ $$PWD/ticketedit.h \ $$PWD/odfedit.h @@ -13,7 +12,6 @@ SOURCES += \ $$PWD/ticketrender.cpp \ $$PWD/office.cpp \ $$PWD/labeldlg.cpp \ - $$PWD/templates.cpp \ $$PWD/templatedlg.cpp \ $$PWD/ticketedit.cpp \ $$PWD/odfedit.cpp diff --git a/src/wext/MOAddress b/src/wext/MOAddress deleted file mode 100644 index d85f82c..0000000 --- a/src/wext/MOAddress +++ /dev/null @@ -1 +0,0 @@ -#include"address.h" diff --git a/src/wext/MOCustomer b/src/wext/MOCustomer deleted file mode 100644 index 396763a..0000000 --- a/src/wext/MOCustomer +++ /dev/null @@ -1 +0,0 @@ -#include"customer.h" diff --git a/src/wext/MOCustomerInfo b/src/wext/MOCustomerInfo deleted file mode 100644 index 468bee4..0000000 --- a/src/wext/MOCustomerInfo +++ /dev/null @@ -1 +0,0 @@ -#include"customerinfo.h" diff --git a/src/wext/MOEvent b/src/wext/MOEvent deleted file mode 100644 index 0da8fbb..0000000 --- a/src/wext/MOEvent +++ /dev/null @@ -1 +0,0 @@ -#include"event.h" diff --git a/src/wext/MOOrder b/src/wext/MOOrder deleted file mode 100644 index 4222ffc..0000000 --- a/src/wext/MOOrder +++ /dev/null @@ -1 +0,0 @@ -#include"order.h" diff --git a/src/wext/MOOrderInfo b/src/wext/MOOrderInfo deleted file mode 100644 index 61ee41e..0000000 --- a/src/wext/MOOrderInfo +++ /dev/null @@ -1 +0,0 @@ -#include"orderinfo.h" diff --git a/src/wext/MOTicket b/src/wext/MOTicket deleted file mode 100644 index 056e50f..0000000 --- a/src/wext/MOTicket +++ /dev/null @@ -1 +0,0 @@ -#include"ticket.h" diff --git a/src/wext/MOVoucher b/src/wext/MOVoucher deleted file mode 100644 index 81cd139..0000000 --- a/src/wext/MOVoucher +++ /dev/null @@ -1 +0,0 @@ -#include"voucher.h" diff --git a/src/wext/MTransaction b/src/wext/MTransaction deleted file mode 100644 index 1fadece..0000000 --- a/src/wext/MTransaction +++ /dev/null @@ -1 +0,0 @@ -#include "transaction.h" diff --git a/src/wext/address.cpp b/src/wext/address.cpp deleted file mode 100644 index b707748..0000000 --- a/src/wext/address.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// C++ Implementation: MOAddress -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOAddress" - -#include -#include - -WOSCRIPT_IMP(MOAddress) - -static int moaid= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); - -QString MOAddress::fullAddress(QString nm)const -{ - //collect lines - QStringList rl; - if(name().isNull() || name()==""){ - if(nm!="")rl<, (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MADDRESS_H -#define MAGICSMOKE_MADDRESS_H - -#include "MOAddressAbstract" - -#include - -class MOAddress:public MOAddressAbstract -{ - Q_OBJECT - WOBJECT(MOAddress) - WOSCRIPT(MOAddress) - public: - /**returns the full address, if name is given and the address does not have its own name, it is included as top line*/ - QString fullAddress(QString name=QString())const; - - /**returns true if this is a valid address stored in the DB (ie. it has an address ID)*/ - bool isValid()const{return !addressid().isNull() && addressid().value()>=0;} -}; - -Q_DECLARE_METATYPE(MOAddress) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/customer.cpp b/src/wext/customer.cpp deleted file mode 100644 index 727ab10..0000000 --- a/src/wext/customer.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// -// C++ Implementation: customer -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOCustomer" -#include "MOCustomerInfo" -#include "msinterface.h" -#include - -#include "MTGetCustomer" - -static int mymeta= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); - -WOSCRIPT_IMP(MOCustomer) - -MOCustomer::MOCustomer(qint64 i) -{ - MTGetCustomer gc=req->queryGetCustomer(i); - if(gc.stage()==gc.Success) - operator=(gc.getcustomer().value()); -} - -MOCustomer::MOCustomer(const MOCustomerInfo&ci) -{ - MTGetCustomer gc=req->queryGetCustomer(ci.id()); - if(gc.stage()==gc.Success) - operator=(gc.getcustomer().value()); -} - -QString MOCustomer::address(int i) -{ - if(i<0)return ""; - QListadrs=addresses(); - if(i>=adrs.size())return ""; - return adrs[i].fullAddress(fullName()); -} - -QString MOCustomer::fullName()const -{ - QString ret=title().value().trimmed(); - QString s=name().value().trimmed(); - if(s!=""){ - if(ret!="")ret+=" "; - ret+=s; - } - s=firstname().value().trimmed(); - if(s!=""){ - if(ret!="")ret+=", "; - ret+=s; - } - return ret; -} diff --git a/src/wext/customer.h b/src/wext/customer.h deleted file mode 100644 index cebb6e8..0000000 --- a/src/wext/customer.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// C++ Interface: MOCustomer -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOCUSTOMER_H -#define MAGICSMOKE_MOCUSTOMER_H - -#include "MOCustomerAbstract" - -class MOCustomerInfo; - -class MOCustomer:public MOCustomerAbstract -{ - Q_OBJECT - WOBJECT(MOCustomer) - WOSCRIPT(MOCustomer) - public: - /**shortcut: gets the customer from the DB*/ - MOCustomer(qint64); - /**shortcut: extracts the ID from the info and retrieves the customer from the DB*/ - MOCustomer(const MOCustomerInfo&); - /**returns whether the customer is valid*/ - bool isValid(){return !id().isNull();} - - /**alias for id()*/ - Nullable customerid()const{return id();} - - /**returns the address of the customer*/ - QString address(int i=0); - - /**returns the full name (incl. title)*/ - QString fullName()const; - -}; - -Q_DECLARE_METATYPE(MOCustomer) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/customerinfo.cpp b/src/wext/customerinfo.cpp deleted file mode 100644 index 277b0a0..0000000 --- a/src/wext/customerinfo.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -// C++ Implementation: MOCustomerInfo -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOCustomerInfo" -#include - -static int mymeta= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); -WOSCRIPT_IMP(MOCustomerInfo) - -QString MOCustomerInfo::fullName()const -{ - QString ret=title().value().trimmed(); - QString s=name().value().trimmed(); - if(s!=""){ - if(ret!="")ret+=" "; - ret+=s; - } - s=firstname().value().trimmed(); - if(s!=""){ - if(ret!="")ret+=", "; - ret+=s; - } - return ret; -} diff --git a/src/wext/customerinfo.h b/src/wext/customerinfo.h deleted file mode 100644 index 341e98a..0000000 --- a/src/wext/customerinfo.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// C++ Interface: unabstract -// -// Description: removes abstract flag from classes that only need to be abstract in PHP -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOCUSTOMERI_H -#define MAGICSMOKE_MOCUSTOMERI_H - -#include "MOCustomerInfoAbstract" -class MOCustomerInfo:public MOCustomerInfoAbstract -{ - Q_OBJECT - WOBJECT(MOCustomerInfo) - WOSCRIPT(MOCustomerInfo) - public: - /**returns the full name (incl. title)*/ - QString fullName()const; - - /**alias for customerid()*/ - Nullable id()const{return customerid();} -}; - -Q_DECLARE_METATYPE(MOCustomerInfo) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/event.cpp b/src/wext/event.cpp deleted file mode 100644 index 5a13425..0000000 --- a/src/wext/event.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// -// C++ Implementation: event -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOEvent" - -#include -#include -#include -#include - -#include "msinterface.h" -#include "MTGetEvent" - -#include "misc.h" - -static int mymeta= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); -WOSCRIPT_IMP(MOEvent) - -MOEvent::MOEvent(qint64 i) -{ - MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); - if(ge.stage()==ge.Success) - operator=(ge.getevent().value()); -} - -QRegExp MOEvent::priceRegExp()const -{ - return ::priceRegExp(); -} - -QString MOEvent::priceString()const -{ - qint64 dp=/*defaultprice()*/0; - QString ret=QString::number(dp/100); - ret+=QCoreApplication::translate("MOEvent",".","price decimal dot"); - ret+=QString::number((dp/10)%10); - ret+=QString::number(dp%10); - return ret; -} - -QString MOEvent::startTimeString()const -{ - return unix2dateTime(start()); -} - -QString MOEvent::startDateString()const -{ - return unix2date(start()); -} - -QString MOEvent::endTimeString()const -{ - return unix2dateTime(end()); -} - -QList< MOEventPrice > MOEvent::priceFiltered() const -{ - QList ep=price(); - QList ret; - MSInterface *ifc=MSInterface::instance(); - if(ifc==0)return ep; - foreach(MOEventPrice p,ep){ - if(ifc->checkFlags(p.flags())) - ret<, (C) 2007-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef EVENT_H -#define EVENT_H - -#include -#include - -/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ -class MOEvent:public MOEventAbstract -{ - Q_OBJECT - WOBJECT(MOEvent) - WOSCRIPT(MOEvent) - public: - /**get event directly from server*/ - MOEvent(qint64); - - /**alias for id()*/ - inline Nullable eventid()const{return id();} - - /**returns the start time of the event as localized string*/ - QString startTimeString()const; - /**returns the start date as localized string*/ - 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; - /**returns the local regular expression for prices*/ - QRegExp priceRegExp()const; - - /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ - bool isValid()const{return !eventid().isNull() && eventid().value()>0;} - - ///returns only the prices that this user can order for - QList priceFiltered()const; -}; - -Q_DECLARE_METATYPE(MOEvent) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/order.cpp b/src/wext/order.cpp deleted file mode 100644 index 424bbbe..0000000 --- a/src/wext/order.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// -// C++ Implementation: MOOrder -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOOrder" -#include "MOOrderInfo" -#include "MORole" - -#include "MTGetOrder" - -#include "msinterface.h" -#include - -static int mymeta= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >()+ - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >()+ - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); - -MOOrder::MOOrder(qint64 id) -{ - MTGetOrder go=req->queryGetOrder(id); - if(go.stage()==go.Success) - operator=(go.getorder().value()); -} - -bool MOOrder::needsPayment()const -{ - if(status()==Placed || status()==Sent) - if(amountpaid()0; - if(status()==Placed || status()==Sent) - return amountpaid()>totalprice(); - return false; -} - -int MOOrder::amountToPay()const -{ - if(status()==Placed || status()==Sent) - if(amountpaid()totalprice()) - return amountpaid()-totalprice(); - return 0; -} - -bool MOOrder::isSent()const -{ - //only in placed mode there is a need for action, hence in all other modes we assume sent - return status()!=Placed; -} - -TimeStamp MOOrder::orderDateTime() -{ - if(ordertime().value()==0)return TimeStamp(); - return TimeStamp(ordertime()); -} - -QString MOOrder::orderDateTimeStr() -{ - if(ordertime().value()==0)return ""; - return unix2dateTime(ordertime()); -} - -QString MOOrder::orderDateStr() -{ - if(ordertime().value()==0)return ""; - return unix2date(ordertime()); -} - -TimeStamp MOOrder::sentDateTime() -{ - return TimeStamp(senttime()); -} - -QString MOOrder::sentDateTimeStr() -{ - if(senttime().value()==0)return ""; - return unix2dateTime(senttime()); -} - -QString MOOrder::sentDateStr() -{ - if(senttime().value()==0)return ""; - return unix2date(senttime()); -} - -QString MOOrder::fullInvoiceAddress(bool allowfallback)const -{ - if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) - return invoiceaddress().value().fullAddress(customer().value().fullName()); - //fall back - if(!allowfallback)return ""; - if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) - return deliveryaddress().value().fullAddress(customer().value().fullName()); - //give up - return ""; -} - -QString MOOrder::fullDeliveryAddress(bool allowfallback)const -{ - if(!deliveryaddress().isNull() && deliveryaddress().value().isValid()) - return deliveryaddress().value().fullAddress(customer().value().fullName()); - //fall back - if(!allowfallback)return ""; - if(!invoiceaddress().isNull() && invoiceaddress().value().isValid()) - return invoiceaddress().value().fullAddress(customer().value().fullName()); - //give up - return ""; -} diff --git a/src/wext/order.h b/src/wext/order.h deleted file mode 100644 index d00f36f..0000000 --- a/src/wext/order.h +++ /dev/null @@ -1,114 +0,0 @@ -// -// C++ Interface: unabstract -// -// Description: removes abstract flag from classes that only need to be abstract in PHP -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOORDER_H -#define MAGICSMOKE_MOORDER_H - -#include "MOOrderAbstract" -#include "misc.h" - -#include - -/**this class represents a complete order*/ -class MOOrder:public MOOrderAbstract -{ - Q_OBJECT - WOBJECT(MOOrder) - WOSCRIPT(MOOrder) - Q_PROPERTY(bool isValid READ isValid) - Q_PROPERTY(bool isReservation READ isReservation) - Q_PROPERTY(bool isSent READ isSent) - Q_PROPERTY(QString orderStatusString READ orderStatusString) - Q_PROPERTY(QString totalPriceString READ totalPriceString) - Q_PROPERTY(bool needsPayment READ needsPayment) - Q_PROPERTY(bool needsRefund READ needsRefund) - Q_PROPERTY(int amountToPay READ amountToPay) - Q_PROPERTY(QString amountToPayStr READ amountToPayStr) - Q_PROPERTY(int amountToRefund READ amountToRefund) - Q_PROPERTY(QString amountToRefundStr READ amountToRefundStr) - Q_PROPERTY(QString orderDateTimeStr READ orderDateTimeStr) - Q_PROPERTY(TimeStamp oderDateTime READ orderDateTime) - Q_PROPERTY(TimeStamp sentDateTime READ sentDateTime) - Q_PROPERTY(QString sentDateTimeStr READ sentDateTimeStr) - Q_PROPERTY(QString orderDateStr READ orderDateStr) - Q_PROPERTY(QString sentDateStr READ sentDateStr) - Q_PROPERTY(QString fullInvoiceAddress READ fullInvoiceAddress) - Q_PROPERTY(QString fullDeliveryAddress READ fullDeliveryAddress) - public: - /**create order by id, retrieves it automatically from the database*/ - MOOrder(qint64); - - /**returns whether the order is valid (it comes from the DB and it has been understood by the parser)*/ - bool isValid()const{return !orderid().isNull();} - - /**returns whether this order is a reservation*/ - bool isReservation()const{return status()==Reserved;} - - /**returns whether the tickets of this order have already been shipped*/ - bool isSent()const; - - /**returns the status of the order as localized string*/ - QString orderStatusString()const{return OrderState2locstr(status());} - - /**returns how much money needs to be paid in total for this order, in cents*/ - QString totalPriceString()const{return cent2str(totalprice());} - - /**returns how much money has already been paid for this order, in cents*/ - QString amountPaidString()const{return cent2str(amountpaid());} - - /**returns whether there is anything left to pay*/ - bool needsPayment()const; - - /**returns whether there is anything left to refund*/ - bool needsRefund()const; - - /**returns how much there is to be paid, in cents*/ - int amountToPay()const; - - /**returns how much there is to be paid, as localized string*/ - QString amountToPayStr()const{return cent2str(amountToPay());} - - /**returns how much there is to be refunded, in cents*/ - int amountToRefund()const; - - /**returns how much there is to be refunded, as localized string*/ - QString amountToRefundStr()const{return cent2str(amountToRefund());} - - /**return the order date+time*/ - TimeStamp orderDateTime(); - - /**returns the order date+time as string*/ - QString orderDateTimeStr(); - - /**returns the order date only as string*/ - QString orderDateStr(); - - /**returns the shipping date+time*/ - TimeStamp sentDateTime(); - - /**returns the shipping date+time as string*/ - QString sentDateTimeStr(); - - /**returns the shipping date only as string*/ - QString sentDateStr(); - - /**returns the full invoice address, or delivery address if no explicit invoice address was given and allowfallback==true*/ - QString fullInvoiceAddress(bool allowfallback=true)const; - /**returns the full delivery address, or invoice address if no explicit delivery address was given and allowfallback==true*/ - QString fullDeliveryAddress(bool allowfallback=true)const; -}; - -Q_DECLARE_METATYPE(MOOrder) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/orderinfo.h b/src/wext/orderinfo.h deleted file mode 100644 index 570d018..0000000 --- a/src/wext/orderinfo.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// C++ Interface: unabstract -// -// Description: removes abstract flag from classes that only need to be abstract in PHP -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOORDERI_H -#define MAGICSMOKE_MOORDERI_H - -#include "MOOrderInfoAbstract" -#include "misc.h" - -class MOOrderInfo:public MOOrderInfoAbstract -{ - Q_OBJECT - WOBJECT(MOOrderInfo) - WOSCRIPT(MOOrderInfo) - Q_PROPERTY(bool isReservation READ isReservation) - Q_PROPERTY(bool isSent READ isSent) - Q_PROPERTY(bool isCancelled READ isCancelled) - Q_PROPERTY(bool needsPayment READ needsPayment) - Q_PROPERTY(bool needsRefund READ needsRefund) - public: - QString totalPriceString()const{return cent2str(totalprice());} - QString amountPaidString()const{return cent2str(amountpaid());} - QString amountDueString()const{return cent2str(amountdue());} - QString orderStatusString()const{return OrderState2locstr(status());} - - bool needsPayment()const{return amountpaid()totalprice();} - bool isSent()const{return status()==Sent;} - bool isReservation()const{return status()==Reserved;} - bool isCancelled()const{return status()==Cancelled;} - bool isPlaced()const{return status()==Placed;} -}; - -Q_DECLARE_METATYPE(MOOrderInfo) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif \ No newline at end of file diff --git a/src/wext/ticket.cpp b/src/wext/ticket.cpp deleted file mode 100644 index 0683f47..0000000 --- a/src/wext/ticket.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// C++ Implementation: MOTicket -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "MOTicket" -#include "MOVoucher" -#include "msinterface.h" -#include -#include "MTGetEvent" - -static int mymeta= - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >()+ - qRegisterMetaType()+ - qRegisterMetaType >()+ - qRegisterMetaType >(); - -MOEvent MOTicket::event()const -{ - //if I am valid... - if(!ticketid().isNull() && !eventid().isNull()) - //...and the event is not... - if(m_event.eventid().isNull()){ - //...then retrieve the event - MTGetEvent ge=req->queryGetEvent(eventid()); - if(!ge.hasError()) - m_event=ge.getevent(); - } - //return whatever we have by now - return m_event; -} - -void MOTicket::setEvent(const MOEvent& e) -{ - m_event=e; - seteventid(e.eventid()); -} - -QString MOTicket::priceCategoryName()const -{ - return pricecategory().value().name(); -} -QString MOTicket::priceCategoryShort()const -{ - return pricecategory().value().abbreviation(); -} diff --git a/src/wext/ticket.h b/src/wext/ticket.h deleted file mode 100644 index 7591786..0000000 --- a/src/wext/ticket.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// C++ Interface: MOTicket -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOTICKET_H -#define MAGICSMOKE_MOTICKET_H - -#include "MOTicketAbstract" -#include "misc.h" -#include "MOEvent" - -class MOTicket:public MOTicketAbstract -{ - Q_OBJECT - WOBJECT(MOTicket) - WOSCRIPT(MOTicket) - Q_PROPERTY(int amountToPay READ amountToPay) - Q_PROPERTY(QString priceString READ priceString) - Q_PROPERTY(QString statusString READ statusString) - Q_PROPERTY(QString priceCategoryName READ priceCategoryName) - Q_PROPERTY(QString priceCategoryShort READ priceCategoryShort) - public: - /**returns the amount to be paid for this ticket; this may be 0 even if there is a price attached*/ - int amountToPay()const{if(status()&MaskPay)return price();else return 0;} - - /**returns the price as string*/ - QString priceString()const{return cent2str(price());} - - /**returns the ticket status as localized string*/ - QString statusString()const{return TicketState2locstr(status());} - - /**returns the full price category name*/ - QString priceCategoryName()const; - /**returns the abbreviation for the price category*/ - QString priceCategoryShort()const; - - /**returns the event that this ticket belongs to - does a roundtrip to the database the first time this is called!*/ - MOEvent event()const; - - /**used by label editor: sets the simulated event*/ - void setEvent(const MOEvent&e); - private: - //this must be mutable, since event() is semantically and technically const - mutable MOEvent m_event; -}; - -Q_DECLARE_METATYPE(MOTicket) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/transaction.cpp b/src/wext/transaction.cpp deleted file mode 100644 index cc54f0b..0000000 --- a/src/wext/transaction.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// C++ Implementation: MTransaction -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See COPYING.GPL file that comes with this distribution -// -// - -#include "MTransaction" -#include "waitcursor.h" - -QByteArray MTransaction::executeQuery(QString hreq,QByteArray data) -{ - //show the user we are waiting - WaitCursor wc; - //call parent - return WTransaction::executeQuery(hreq,data); -} - -MTransaction::MTransaction(QString iface):WTransaction(iface){} -MTransaction::MTransaction(const WTransaction&t):WTransaction(t){} -MTransaction::MTransaction(const MTransaction&t):WTransaction(t){} diff --git a/src/wext/transaction.h b/src/wext/transaction.h deleted file mode 100644 index e212f7d..0000000 --- a/src/wext/transaction.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// C++ Interface: MTransaction -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2010 -// -// Copyright: See COPYING.GPL file that comes with this distribution -// -// - -#ifndef MSMOKE_MTRANSACTION_H -#define MSMOKE_MTRANSACTION_H - -#include - -class MTransaction:public WTransaction{ - protected: - /**internal: construct the transaction*/ - MTransaction(QString iface=QString()); - /**internal: copy the transaction*/ - MTransaction(const WTransaction&); - /**internal: copy the transaction*/ - MTransaction(const MTransaction&); - /**internal: extend executeQuery to show a wait cursor*/ - QByteArray executeQuery(QString,QByteArray); -}; - -#endif diff --git a/src/wext/voucher.h b/src/wext/voucher.h deleted file mode 100644 index 70f6a9d..0000000 --- a/src/wext/voucher.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// C++ Interface: MOVoucher -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2009-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_MOVOUCHER_H -#define MAGICSMOKE_MOVOUCHER_H - -#include "MOVoucherAbstract" -#include "misc.h" - -class MOVoucher:public MOVoucherAbstract -{ - Q_OBJECT - WOBJECT(MOVoucher) - WOSCRIPT(MOVoucher) - Q_PROPERTY(QString valueString READ valueString) - Q_PROPERTY(QString statusString READ statusString) - Q_PROPERTY(QString priceString READ priceString) - public: - /**returns whether this is a valid voucher object (ie. it has a voucher ID)*/ - bool isValid()const{return !voucherid().isNull();} - /**returns the current value as string*/ - QString valueString()const{return cent2str(value());} - /**returns the status of the voucher as string*/ - QString statusString()const{return VoucherState2locstr(status());} - /**returns the price as string*/ - QString priceString()const{return cent2str(price());} -}; - -Q_DECLARE_METATYPE(MOVoucher) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(Nullable) - -#endif diff --git a/src/wext/wext.pri b/src/wext/wext.pri deleted file mode 100644 index f9f30b6..0000000 --- a/src/wext/wext.pri +++ /dev/null @@ -1,21 +0,0 @@ -INCLUDEPATH += ./wext - -HEADERS += \ - wext/customerinfo.h \ - wext/order.h \ - wext/orderinfo.h \ - wext/ticket.h \ - wext/voucher.h \ - wext/address.h \ - wext/event.h \ - wext/customer.h \ - wext/transaction.h - -SOURCES += \ - wext/customerinfo.cpp \ - wext/order.cpp \ - wext/ticket.cpp \ - wext/address.cpp \ - wext/event.cpp \ - wext/customer.cpp \ - wext/transaction.cpp diff --git a/wob/magicsmoke.wolf b/wob/magicsmoke.wolf index 5728acb..3893bcf 100644 --- a/wob/magicsmoke.wolf +++ b/wob/magicsmoke.wolf @@ -8,7 +8,7 @@ --> These files describe the database schema and communication protocol of MagicSmoke. - &copy; Konrad Rosenbaum, 2009-2011 + &copy; Konrad Rosenbaum, 2009-2013 <br/>these files are protected under the GNU AGPLv3 or at your option any newer @@ -17,7 +17,7 @@ - + -- 1.7.2.5