From: Konrad Rosenbaum Date: Thu, 12 Dec 2013 19:22:24 +0000 (+0100) Subject: refactor libs into non-gui and gui parts X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=355517ff1cb1184a4a3dc348ae966db0593273ff;p=web%2Fkonrad%2Fsmoke.git refactor libs into non-gui and gui parts --- 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/src/misc/cleanup.h b/iface/misc/cleanup.h similarity index 89% rename from src/misc/cleanup.h rename to iface/misc/cleanup.h index 76e81cc..d7a6f39 100644 --- a/src/misc/cleanup.h +++ b/iface/misc/cleanup.h @@ -15,8 +15,12 @@ #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 MCleanup +class MSIFACE_EXPORT MCleanup { std::functionm_ptr; public: diff --git a/src/misc/formula.cpp b/iface/misc/formula.cpp similarity index 100% rename from src/misc/formula.cpp rename to iface/misc/formula.cpp diff --git a/src/misc/formula.h b/iface/misc/formula.h similarity index 74% rename from src/misc/formula.h rename to iface/misc/formula.h index f6ee17c..7241b47 100644 --- a/src/misc/formula.h +++ b/iface/misc/formula.h @@ -15,7 +15,11 @@ #include -class MElamEngine:public ELAM::Engine +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +class MSIFACE_EXPORT MElamEngine:public ELAM::Engine { public: MElamEngine(QObject*parent=0); diff --git a/src/misc/misc.cpp b/iface/misc/misc.cpp similarity index 100% rename from src/misc/misc.cpp rename to iface/misc/misc.cpp diff --git a/src/misc/misc.h b/iface/misc/misc.h similarity index 95% rename from src/misc/misc.h rename to iface/misc/misc.h index 2d4c496..685456a 100644 --- a/src/misc/misc.h +++ b/iface/misc/misc.h @@ -22,37 +22,41 @@ 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 htmlize(QString str); +QString MSIFACE_EXPORT htmlize(QString str); /**converts special XML characters into harmless &-codes, so the text can be included*/ -QString xmlize(QString str,QString newline="\n"); +QString MSIFACE_EXPORT 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"); +QByteArray MSIFACE_EXPORT xmlize(QByteArray str,QString newline="\n"); /**converts a cent value into a (localized) string*/ -QString cent2str(qint64 cent,bool localize=true); +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 str2cent(QString s,bool fromlocal=true); +qint64 MSIFACE_EXPORT str2cent(QString s,bool fromlocal=true); /**converts a unix timestamp into a date*/ -QString unix2date(qint64,bool localize=true); +QString MSIFACE_EXPORT unix2date(qint64,bool localize=true); /**converts a unix timestamp into a time (ommitting the date)*/ -QString unix2time(qint64,bool localize=true); +QString MSIFACE_EXPORT unix2time(qint64,bool localize=true); /**converts a unix timestamp into a date-time-string*/ -QString unix2dateTime(qint64,bool localize=true); +QString MSIFACE_EXPORT unix2dateTime(qint64,bool localize=true); /**return a (localized) regular expression that validates prices*/ -QRegExp priceRegExp(bool localize=true); +QRegExp MSIFACE_EXPORT priceRegExp(bool localize=true); ///returns the current directory (the one last used in a file dialog) -QString currentDir(); +QString MSIFACE_EXPORT currentDir(); ///sets a new current directory (transparently handles files and directories) -void setCurrentDir(QString); +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; @@ -95,7 +99,7 @@ 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 +class MSIFACE_EXPORT MLocalFormat { DECLARE_SHARED_DPTR(d); public: 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/src/iface/msinterface.cpp b/iface/msinterface.cpp similarity index 73% rename from src/iface/msinterface.cpp rename to iface/msinterface.cpp index 6d1e0af..43f9370 100644 --- a/src/iface/msinterface.cpp +++ b/iface/msinterface.cpp @@ -11,10 +11,10 @@ // #include "msinterface.h" -#include "main.h" #include "sslexception.h" #include "templates.h" #include "misc.h" +#include "boxwrapper.h" #include "MTGetMyRights" #include "MTGetMyRoles" @@ -28,12 +28,48 @@ #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() { @@ -71,7 +107,7 @@ 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()))); + MBoxWrapper::warning(tr("Warning"),tr("Login failed: %1").arg(tr(lg.errorString().toLatin1()))); else setSessionId(lg.getsessionid()); if(lg.stage()!=lg.Success)return false; @@ -105,21 +141,21 @@ bool MSInterface::checkServer() qDebug("caught exception while getting server info (%s): %s", e.component().toLatin1().data(), e.error().toLatin1().data()); - QMessageBox::warning(0,tr("Error"),tr("Communication problem while talking to the server, see log for details.")); + MBoxWrapper::warning(tr("Error"),tr("Communication problem while talking to the server, see log for details.")); return false; } if(si.stage()!=si.Success){ - QMessageBox::warning(0,tr("Error"),tr("Communication with server was not successful.")); + MBoxWrapper::warning(tr("Error"),tr("Communication with server was not successful.")); return false; } //is server new enough for me? if(si.getServerProtocolVersion().value()commVersion()){ - QMessageBox::warning(0,tr("Error"),tr("This client is too old for the server, please upgrade.")); + MBoxWrapper::warning(tr("Error"),tr("This client is too old for the server, please upgrade.")); return false; } //we are ok @@ -147,13 +183,25 @@ QMap MSInterface::headers(QString s)const QString MSInterface::dataDir()const { QString dd="profile."+profileid; - QDir dir(MApplication::dataDir()); + QDir dir(appDataDir()); if(!dir.exists(dd)) if(!dir.mkpath(dd)) qDebug("Warning: oh dir! Can't create my data directory!"); - return MApplication::dataDir()+"/"+dd; + return appDataDir()+"/"+dd; } +QString MSInterface::appDataDir() +{ + return ::dataDir; +} + +void MSInterface::setAppDataDir(QString d) +{ + ::dataDir=resolveDir(d); + qDebug()<<"Setting the data directory to"<<::dataDir<<"from"<&errs) } //message box if(!didsslerror){ - QMessageBox::warning(0,tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration.")); + MBoxWrapper::warning(tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration.")); } } diff --git a/src/iface/msinterface.h b/iface/msinterface.h similarity index 83% rename from src/iface/msinterface.h rename to iface/msinterface.h index 8624853..f271ab6 100644 --- a/src/iface/msinterface.h +++ b/iface/msinterface.h @@ -17,12 +17,16 @@ #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 MSInterface:public MInterface +class MSIFACE_EXPORT MSInterface:public MInterface { Q_OBJECT Q_PROPERTY(QString currentUser READ currentUser) @@ -94,6 +98,18 @@ class MSInterface:public MInterface ///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*/ diff --git a/src/iface/sslexception.cpp b/iface/sslexception.cpp similarity index 99% rename from src/iface/sslexception.cpp rename to iface/sslexception.cpp index b806b8e..eb1d578 100644 --- a/src/iface/sslexception.cpp +++ b/iface/sslexception.cpp @@ -13,7 +13,7 @@ #include "sslexception.h" #include -#include +// #include #include #include #include diff --git a/src/iface/sslexception.h b/iface/sslexception.h similarity index 92% rename from src/iface/sslexception.h rename to iface/sslexception.h index bc7a143..da383e1 100644 --- a/src/iface/sslexception.h +++ b/iface/sslexception.h @@ -23,8 +23,12 @@ class QWidget; +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + /**Helper class: stores and compares SSL-Exceptions*/ -class MSslExceptions +class MSIFACE_EXPORT MSslExceptions { public: /**create instance from file in path*/ diff --git a/src/templates/templates.cpp b/iface/templates/templates.cpp similarity index 91% rename from src/templates/templates.cpp rename to iface/templates/templates.cpp index 5e10ea1..e3f7773 100644 --- a/src/templates/templates.cpp +++ b/iface/templates/templates.cpp @@ -25,10 +25,9 @@ * each file is stored with complete name, no meta-info ***************************/ -#include "main.h" -#include "templatedlg.h" #include "templates.h" #include "msinterface.h" +#include "boxwrapper.h" #include "MTGetTemplateList" #include "MTGetTemplate" @@ -43,11 +42,19 @@ #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; @@ -81,9 +88,16 @@ MTemplate MTemplateStore::getTemplate(QString f) if(tdir.size()==0)return MTemplate(); if(tdir.size()==1)return MTemplate(dname+"/"+tdir[0], set.value(tdir[0]+"/checksum").toString(), set.value(tdir[0]+"/description").toString(), set.value(tdir[0]+"/flags").toString()); //hmm, more than one choice - MTemplateChoice c(dname,f,tdir,"templates/"+profileid); - if(c.exec()==QDialog::Accepted)return c.choice(); - else return MTemplate(); + QListtemplst; + for(const QString&td:tdir) + templst<setRange(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(); @@ -158,9 +172,9 @@ void MTemplateStore::updateTemplates(bool force) //retrieve new files from server QStringList nfiles=nfmap.keys(); - progress.setRange(0,nfiles.size()); + progress->setRange(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])) @@ -303,23 +317,6 @@ MTemplate::MTemplate(QString fn){m_fname=fn;} MTemplate::MTemplate(QString fn,QString chk,QString dsc,QString flg) {m_fname=fn;m_checksum=chk;m_descr=dsc;m_flags=flg;} -MTemplate::MTemplate(const MTemplate& t) -{ - m_fname=t.m_fname; - m_checksum=t.m_checksum; - m_descr=t.m_descr; - m_flags=t.m_flags; -} - -MTemplate& MTemplate::operator=(const MTemplate&t) -{ - m_fname=t.m_fname; - m_checksum=t.m_checksum; - m_descr=t.m_descr; - m_flags=t.m_flags; - return *this; -} - void MTemplate::setFile(const QString& s) { m_fname=s; diff --git a/src/templates/templates.h b/iface/templates/templates.h similarity index 89% rename from src/templates/templates.h rename to iface/templates/templates.h index 233e880..b5b1396 100644 --- a/src/templates/templates.h +++ b/iface/templates/templates.h @@ -14,9 +14,15 @@ #define MAGICSMOKE_TEMPLATES_H #include +#include +#include + +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif /**this class wraps a single template*/ -class MTemplate +class MSIFACE_EXPORT MTemplate { public: /**creates an invalid template*/ @@ -26,10 +32,10 @@ class MTemplate MTemplate(QString fn); /**copies a template*/ - MTemplate(const MTemplate&); + MTemplate(const MTemplate&)=default; ///copies a template - MTemplate& operator=(const MTemplate&); + MTemplate& operator=(const MTemplate&)=default; ///reinitializes the template from the given file name void setFile(const QString&); @@ -107,6 +113,12 @@ class MTemplate /**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; @@ -124,7 +136,7 @@ class MTemplate 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 +class MSIFACE_EXPORT MTemplateStore { protected: friend class MSInterface; 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/src/wext/MOAddress b/iface/wext/MOAddress similarity index 100% rename from src/wext/MOAddress rename to iface/wext/MOAddress diff --git a/src/wext/MOCustomer b/iface/wext/MOCustomer similarity index 100% rename from src/wext/MOCustomer rename to iface/wext/MOCustomer diff --git a/src/wext/MOCustomerInfo b/iface/wext/MOCustomerInfo similarity index 100% rename from src/wext/MOCustomerInfo rename to iface/wext/MOCustomerInfo diff --git a/src/wext/MOEvent b/iface/wext/MOEvent similarity index 100% rename from src/wext/MOEvent rename to iface/wext/MOEvent diff --git a/src/wext/MOOrder b/iface/wext/MOOrder similarity index 100% rename from src/wext/MOOrder rename to iface/wext/MOOrder diff --git a/src/wext/MOOrderInfo b/iface/wext/MOOrderInfo similarity index 100% rename from src/wext/MOOrderInfo rename to iface/wext/MOOrderInfo diff --git a/src/wext/MOTicket b/iface/wext/MOTicket similarity index 100% rename from src/wext/MOTicket rename to iface/wext/MOTicket diff --git a/src/wext/MOVoucher b/iface/wext/MOVoucher similarity index 100% rename from src/wext/MOVoucher rename to iface/wext/MOVoucher diff --git a/src/wext/MTransaction b/iface/wext/MTransaction similarity index 100% rename from src/wext/MTransaction rename to iface/wext/MTransaction diff --git a/src/wext/address.cpp b/iface/wext/address.cpp similarity index 100% rename from src/wext/address.cpp rename to iface/wext/address.cpp diff --git a/src/wext/address.h b/iface/wext/address.h similarity index 87% rename from src/wext/address.h rename to iface/wext/address.h index 9dbb650..dccdf97 100644 --- a/src/wext/address.h +++ b/iface/wext/address.h @@ -17,7 +17,11 @@ #include -class MOAddress:public MOAddressAbstract +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + +class MSIFACE_EXPORT MOAddress:public MOAddressAbstract { Q_OBJECT WOBJECT(MOAddress) diff --git a/src/wext/customer.cpp b/iface/wext/customer.cpp similarity index 100% rename from src/wext/customer.cpp rename to iface/wext/customer.cpp diff --git a/src/wext/customer.h b/iface/wext/customer.h similarity index 88% rename from src/wext/customer.h rename to iface/wext/customer.h index cebb6e8..7ac7621 100644 --- a/src/wext/customer.h +++ b/iface/wext/customer.h @@ -15,9 +15,13 @@ #include "MOCustomerAbstract" +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + class MOCustomerInfo; -class MOCustomer:public MOCustomerAbstract +class MSIFACE_EXPORT MOCustomer:public MOCustomerAbstract { Q_OBJECT WOBJECT(MOCustomer) diff --git a/src/wext/customerinfo.cpp b/iface/wext/customerinfo.cpp similarity index 100% rename from src/wext/customerinfo.cpp rename to iface/wext/customerinfo.cpp diff --git a/src/wext/customerinfo.h b/iface/wext/customerinfo.h similarity index 84% rename from src/wext/customerinfo.h rename to iface/wext/customerinfo.h index 341e98a..8f635fa 100644 --- a/src/wext/customerinfo.h +++ b/iface/wext/customerinfo.h @@ -13,8 +13,13 @@ #ifndef MAGICSMOKE_MOCUSTOMERI_H #define MAGICSMOKE_MOCUSTOMERI_H +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + #include "MOCustomerInfoAbstract" -class MOCustomerInfo:public MOCustomerInfoAbstract +class MSIFACE_EXPORT MOCustomerInfo:public MOCustomerInfoAbstract { Q_OBJECT WOBJECT(MOCustomerInfo) diff --git a/src/wext/event.cpp b/iface/wext/event.cpp similarity index 100% rename from src/wext/event.cpp rename to iface/wext/event.cpp diff --git a/src/wext/event.h b/iface/wext/event.h similarity index 92% rename from src/wext/event.h rename to iface/wext/event.h index 00cb1cd..aca5cd0 100644 --- a/src/wext/event.h +++ b/iface/wext/event.h @@ -16,8 +16,13 @@ #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 MOEvent:public MOEventAbstract +class MSIFACE_EXPORT MOEvent:public MOEventAbstract { Q_OBJECT WOBJECT(MOEvent) diff --git a/src/wext/order.cpp b/iface/wext/order.cpp similarity index 100% rename from src/wext/order.cpp rename to iface/wext/order.cpp diff --git a/src/wext/order.h b/iface/wext/order.h similarity index 97% rename from src/wext/order.h rename to iface/wext/order.h index d00f36f..bf9d1d0 100644 --- a/src/wext/order.h +++ b/iface/wext/order.h @@ -18,8 +18,13 @@ #include +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + /**this class represents a complete order*/ -class MOOrder:public MOOrderAbstract +class MSIFACE_EXPORT MOOrder:public MOOrderAbstract { Q_OBJECT WOBJECT(MOOrder) diff --git a/src/wext/orderinfo.h b/iface/wext/orderinfo.h similarity index 91% rename from src/wext/orderinfo.h rename to iface/wext/orderinfo.h index 570d018..b6505ea 100644 --- a/src/wext/orderinfo.h +++ b/iface/wext/orderinfo.h @@ -16,7 +16,12 @@ #include "MOOrderInfoAbstract" #include "misc.h" -class MOOrderInfo:public MOOrderInfoAbstract +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOOrderInfo:public MOOrderInfoAbstract { Q_OBJECT WOBJECT(MOOrderInfo) diff --git a/src/wext/ticket.cpp b/iface/wext/ticket.cpp similarity index 100% rename from src/wext/ticket.cpp rename to iface/wext/ticket.cpp diff --git a/src/wext/ticket.h b/iface/wext/ticket.h similarity index 93% rename from src/wext/ticket.h rename to iface/wext/ticket.h index 7591786..eaf6e81 100644 --- a/src/wext/ticket.h +++ b/iface/wext/ticket.h @@ -17,7 +17,12 @@ #include "misc.h" #include "MOEvent" -class MOTicket:public MOTicketAbstract +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOTicket:public MOTicketAbstract { Q_OBJECT WOBJECT(MOTicket) 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/src/wext/transaction.h b/iface/wext/transaction.h similarity index 58% rename from src/wext/transaction.h rename to iface/wext/transaction.h index e212f7d..e533cdb 100644 --- a/src/wext/transaction.h +++ b/iface/wext/transaction.h @@ -4,7 +4,7 @@ // Description: // // -// Author: Konrad Rosenbaum , (C) 2010-2010 +// Author: Konrad Rosenbaum , (C) 2010-2013 // // Copyright: See COPYING.GPL file that comes with this distribution // @@ -14,8 +14,18 @@ #define MSMOKE_MTRANSACTION_H #include +#include -class MTransaction:public WTransaction{ +#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()); diff --git a/src/wext/voucher.h b/iface/wext/voucher.h similarity index 89% rename from src/wext/voucher.h rename to iface/wext/voucher.h index 70f6a9d..aa93bf8 100644 --- a/src/wext/voucher.h +++ b/iface/wext/voucher.h @@ -16,7 +16,12 @@ #include "MOVoucherAbstract" #include "misc.h" -class MOVoucher:public MOVoucherAbstract +#ifndef MSIFACE_EXPORT +#define MSIFACE_EXPORT Q_DECL_IMPORT +#endif + + +class MSIFACE_EXPORT MOVoucher:public MOVoucherAbstract { Q_OBJECT WOBJECT(MOVoucher) diff --git a/src/wext/wext.pri b/iface/wext/wext.pri similarity index 100% rename from src/wext/wext.pri rename to iface/wext/wext.pri 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/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) 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.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/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/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 @@ - +