From 9dabf729d0c67adeadd8f3300515360d7309b43b Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 27 Mar 2009 07:18:42 +0000 Subject: [PATCH] ...converting main app to new iface, does not compile yet git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@280 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/centbox.cpp | 126 --------- src/centbox.h | 60 ---- src/checkdlg.cpp | 104 ------- src/checkdlg.h | 87 ------ src/eventedit.h | 3 +- src/eventsummary.cpp | 3 +- src/eventsummary.h | 4 +- src/main.cpp | 10 - src/main.h | 10 - src/mainwindow.cpp | 10 +- src/msinterface.cpp | 19 ++ src/msinterface.h | 36 +++ src/overview.cpp | 60 +++-- src/overview.h | 8 +- src/smoke.pro | 7 +- src/wbase/WInterface.cpp | 1 + src/wbase/WInterface.h | 37 ++- src/wbase/WTransaction.cpp | 3 +- src/webrequest.cpp | 649 -------------------------------------------- src/webrequest.h | 197 -------------- src/widgets/centbox.cpp | 126 +++++++++ src/widgets/centbox.h | 60 ++++ src/widgets/checkdlg.cpp | 104 +++++++ src/widgets/checkdlg.h | 87 ++++++ src/widgets/waitcursor.cpp | 26 ++ src/widgets/waitcursor.h | 27 ++ src/widgets/widgets.pri | 11 + wob/event.wolf | 34 +++ wob/magicsmoke.wolf | 2 +- woc/phpout.cpp | 37 +++- woc/processor.cpp | 2 +- woc/processor.h | 12 +- woc/qtout.cpp | 32 ++- 33 files changed, 679 insertions(+), 1315 deletions(-) delete mode 100644 src/centbox.cpp delete mode 100644 src/centbox.h delete mode 100644 src/checkdlg.cpp delete mode 100644 src/checkdlg.h create mode 100644 src/msinterface.cpp create mode 100644 src/msinterface.h delete mode 100644 src/webrequest.cpp delete mode 100644 src/webrequest.h create mode 100644 src/widgets/centbox.cpp create mode 100644 src/widgets/centbox.h create mode 100644 src/widgets/checkdlg.cpp create mode 100644 src/widgets/checkdlg.h create mode 100644 src/widgets/waitcursor.cpp create mode 100644 src/widgets/waitcursor.h create mode 100644 src/widgets/widgets.pri diff --git a/src/centbox.cpp b/src/centbox.cpp deleted file mode 100644 index a8db050..0000000 --- a/src/centbox.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// -// C++ Implementation: centbox -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "centbox.h" -#include "misc.h" - -#include -#include -#include -#include - -MCentSpinBox::MCentSpinBox(QWidget*parent,int value,int maxValue) - :QAbstractSpinBox(parent),mvalid(priceRegExp(),this) -{ - mmin=0; - mmax=maxValue; - if(mmin>mmax)mmin=mmax; - mval=value; - if(mvalmmax)mval=mmax; - - setButtonSymbols(UpDownArrows); - lineEdit()->setText(cent2str(mval)); - connect(this,SIGNAL(editingFinished()),this,SLOT(fixup())); -} - -int MCentSpinBox::value()const -{ -// qDebug("current value: %i",mval); - return mval; -} - -void MCentSpinBox::setValue(int m) -{ - if(m>mmax)m=mmax; - if(msetText(cent2str(m)); - emit valueChanged(m); -} - -MCentSpinBox::StepEnabled MCentSpinBox::stepEnabled () const -{ - return (mval>mmin?StepDownEnabled:StepNone)|(mvalma)return; - mmin=mi; - mmax=ma; - if(mval>mmax){ - setValue(mmax); - }else - if(mvaladdWidget(new QLabel(label)); - vl->addWidget(box=new MCentSpinBox(this,val,maxValue)); - QHBoxLayout *hl; - vl->addLayout(hl=new QHBoxLayout); - hl->addStretch(10); - QPushButton*p; - hl->addWidget(p=new QPushButton(tr("OK"))); - p->setDefault(true); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel"))); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); -} - -int MCentDialog::value()const -{ - return box->value(); -} - -int MCentDialog::getCents(QWidget*parent,QString title,QString label,int val,int maxValue,bool*ok) -{ - MCentDialog d(parent,title,label,val,maxValue); - bool b=d.exec()==QDialog::Accepted; - if(ok)*ok=b; - if(b) - return d.value(); - else - return 0; -} diff --git a/src/centbox.h b/src/centbox.h deleted file mode 100644 index 4193737..0000000 --- a/src/centbox.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// C++ Interface: centbox -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef MAGICSMOKE_CENTBOX_H -#define MAGICSMOKE_CENTBOX_H - -#include -#include -#include - -class MCentSpinBox:public QAbstractSpinBox -{ - Q_OBJECT - public: - MCentSpinBox(QWidget*parent=0,int value=0,int maxValue=2147483647); - - virtual int value()const; - virtual void setValue(int); - - virtual void setRange(int,int); - - virtual int minimumValue()const; - virtual int maximumValue()const; - - void stepBy(int); - protected: - virtual QValidator::State validate(QString &input, int &pos) const; - virtual StepEnabled stepEnabled () const; - signals: - void valueChanged(int); - private slots: - void fixup(); - private: - int mval,mmax,mmin; - QRegExpValidator mvalid; -}; - -class MCentDialog:public QDialog -{ - Q_OBJECT - public: - MCentDialog(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647); - - virtual int value()const; - - static int getCents(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647,bool *ok=0); - private: - MCentSpinBox*box; -}; - -#endif diff --git a/src/checkdlg.cpp b/src/checkdlg.cpp deleted file mode 100644 index 2d5a3f6..0000000 --- a/src/checkdlg.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// -// C++ Implementation: checkdlg -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "checkdlg.h" - -#include -#include -#include -#include - -MCheckDialog::MCheckDialog(QWidget*parent,const MCheckList&checks,QString title) - :QDialog(parent),m_list(checks) -{ - setWindowTitle(title); - //basic layout - QVBoxLayout *vl=new QVBoxLayout; - setLayout(vl); - QScrollArea *sa=new QScrollArea; - vl->addWidget(sa,10); - QHBoxLayout *hl=new QHBoxLayout; - vl->addLayout(hl,0); - hl->addStretch(10); - QPushButton*p; - hl->addWidget(p=new QPushButton(tr("Ok")),0); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel")),0); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); - //fill area - QWidget*w=new QWidget; - w->setLayout(vl=new QVBoxLayout); - for(int i=0;isetChecked(m_list[i].isSet()); - vl->addWidget(cb); - m_boxes.append(cb); - } - sa->setWidget(w); -} - -MCheckList MCheckDialog::getCheckList()const -{ - for(int i=0;iisChecked()); - return m_list; -} - -/**************************************************/ - -MCheckItem::MCheckItem(){} -MCheckItem::~MCheckItem(){} - -QString MCheckItem::key()const{qDebug("???????????");return label();} - -MCheckList::MCheckList(){} - -MCheckList::MCheckList(const MCheckList&l) -{ - for(int i=0;icopy()); -} - -MCheckList& MCheckList::operator=(const MCheckList&l) -{ - for(int i=0;icopy()); -} - -MCheckList::~MCheckList() -{ - for(int i=0;i, (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef MAGICSMOKE_CHECKDLG_H -#define MAGICSMOKE_CHECKDLG_H - -#include -#include - -class QCheckBox; - -/**abstract base class for items that can be displayed in a MCheckDialog*/ -class MCheckItem -{ - public: - /**constructs an empty check item*/ - MCheckItem(); - /**deletes the check item*/ - virtual ~MCheckItem(); - - /**overwrite this to return a label that can be displayed*/ - virtual QString label()const=0; - /**overwrite this to return a key string that identifies the item (default implementation returns the label)*/ - virtual QString key()const; - /**overwrite this to return whether the item is checked*/ - virtual bool isSet()const=0; - /**overwrite this to change the checking status of the item*/ - virtual void set(bool)=0; - - protected: - friend class MCheckList; - /**overwrite this to creat an exact copy of the item (must be implemented and must return non-NULL)*/ - virtual MCheckItem* copy()const=0; -}; - -/**implements a list of checkable items*/ -class MCheckList -{ - public: - /**instantiate an empty list*/ - MCheckList(); - /**creates an exact copy of the list (uses MCheckItem::copy() )*/ - MCheckList(const MCheckList&); - /**deletes the list*/ - ~MCheckList(); - - /**adds an item to the list*/ - void addItem(MCheckItem*); - /**returns the size of the list*/ - int size()const; - - /**returns a writable reference to an item*/ - MCheckItem& operator[](int); - /**returns a const reference to an item*/ - const MCheckItem& operator[](int)const; - - /**makes this list an exact copy of the argument*/ - MCheckList& operator=(const MCheckList&); - private: - QList m_items; -}; - -/**a dialog that consists of check boxes in a QScrollArea */ -class MCheckDialog:public QDialog -{ - Q_OBJECT - public: - /**creates the dialog*/ - MCheckDialog(QWidget*parent,const MCheckList&checks,QString title); - - /**returns the current state of all check boxes, the return value is an exact copy of the check list from the constructor with updated check settings*/ - MCheckList getCheckList()const; - private: - QListm_boxes; - mutable MCheckList m_list; -}; - -#endif diff --git a/src/eventedit.h b/src/eventedit.h index af4e681..d795a9d 100644 --- a/src/eventedit.h +++ b/src/eventedit.h @@ -30,7 +30,7 @@ class MEventEditor:public QDialog { Q_OBJECT public: - MEventEditor(QWidget*,MWebRequest*,qint32 id=-1); + MEventEditor(QWidget*,qint32 id=-1); private slots: void writeBack(); void selectRoom(); @@ -39,7 +39,6 @@ class MEventEditor:public QDialog void startTimeChanged(const QDateTime&); void endTimeChanged(const QDateTime&); private: - MWebRequest*req; MEvent event; QDateTimeEdit*starttime,*endtime; QLineEdit*title,*artist,*room,*price,*cancelreason; diff --git a/src/eventsummary.cpp b/src/eventsummary.cpp index 81f389e..07d6f00 100644 --- a/src/eventsummary.cpp +++ b/src/eventsummary.cpp @@ -27,10 +27,9 @@ #include #include -MEventSummary::MEventSummary(QWidget*par,MWebRequest*rq,int eid) +MEventSummary::MEventSummary(QWidget*par,int eid) :QDialog(par),event(rq,eid) { - req=rq; nreserved=ncancelled=ntotaltickets=ntotalmoney=0; //get event data getSummaryData(); diff --git a/src/eventsummary.h b/src/eventsummary.h index b5ce8cd..99c956e 100644 --- a/src/eventsummary.h +++ b/src/eventsummary.h @@ -19,7 +19,6 @@ #include "order.h" #include "odtrender.h" -class MWebRequest; class QTableView; class QStandardItemModel; class QLabel; @@ -30,7 +29,7 @@ class MEventSummary:public QDialog Q_OBJECT public: /**creates a new summary dialog, requests data from server*/ - MEventSummary(QWidget*parent,MWebRequest*req,int eventid); + MEventSummary(QWidget*parent,int eventid); /**deletes MEventSummary*/ ~MEventSummary(); @@ -46,7 +45,6 @@ class MEventSummary:public QDialog void getLoopVariable(QString,int,QString,MOdtRenderer::VarType&,QVariant&); private: - MWebRequest*req; int eventid; MEvent event; int nreserved,ncancelled,ntotaltickets,ntotalmoney; diff --git a/src/main.cpp b/src/main.cpp index f6d1972..3595d95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,6 @@ // #include -#include #include #include #include @@ -28,15 +27,6 @@ #include "main.h" #include "debug.h" -WaitCursor::WaitCursor() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -} - -WaitCursor::~WaitCursor() -{ - QApplication::restoreOverrideCursor(); -} QString choseLanguage(bool warn) { diff --git a/src/main.h b/src/main.h index bd7eee0..7be4ad9 100644 --- a/src/main.h +++ b/src/main.h @@ -21,14 +21,4 @@ QString choseLanguage(bool warn=true); /**contains the directory that is used for external data storage*/ extern QString dataDir; -/**simple class to show a busy-cursor while an instance of it exists*/ -class WaitCursor -{ - public: - /**displays a wait cursor (Qt::WaitCursor)*/ - WaitCursor(); - /**restores the last normal cursor*/ - ~WaitCursor(); -}; - #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 35cfae5..9ac8dee 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,9 +13,9 @@ #include "keygen.h" #include "main.h" #include "mainwindow.h" +#include "msinterface.h" #include "office.h" #include "overview.h" -#include "webrequest.h" #include #include @@ -205,7 +205,7 @@ void MMainWindow::startLogin() //make it impossible for the user to interfere setEnabled(false); //create request object - MWebRequest *mw=new MWebRequest(profiles->itemData(profiles->currentIndex()).toString()); + MSInterface *mw=new MSInterface(profiles->itemData(profiles->currentIndex()).toString()); mw->setUrl(serverurl->text()); if(useproxy->isChecked()) mw->setProxy(proxyname->text(),proxyport->value(),proxyuser->text(),proxypass->text()); @@ -214,16 +214,16 @@ void MMainWindow::startLogin() if(usealterhost->isChecked())hn=alterhostname->text(); else hn=QSettings().value("hostname").toString(); if(!mw->login(username->text(),password->text(),hn)){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to log in. Error: %1").arg(mw->errorString())); + QMessageBox::warning(this,tr("Warning"),tr("Unable to log in.")); mw->deleteLater(); setEnabled(true); return; } //open window - MOverview *mo=new MOverview(mw,profiles->itemData(profiles->currentIndex()).toString()); + MOverview *mo=new MOverview(profiles->itemData(profiles->currentIndex()).toString()); mo->show(); - //make sure the application exits after everything is cleaned up + //make sure the application exits (only) after everything is cleaned up qApp->setQuitOnLastWindowClosed(false); connect(mw,SIGNAL(destroyed(QObject*)),qApp,SLOT(quit())); diff --git a/src/msinterface.cpp b/src/msinterface.cpp new file mode 100644 index 0000000..92b6eca --- /dev/null +++ b/src/msinterface.cpp @@ -0,0 +1,19 @@ +// +// C++ Implementation: msinterface +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "msinterface.h" + +MSInterface::MSInterface(QString pid) + :MInterface() +{ + profileid=pid; +} \ No newline at end of file diff --git a/src/msinterface.h b/src/msinterface.h new file mode 100644 index 0000000..1cea735 --- /dev/null +++ b/src/msinterface.h @@ -0,0 +1,36 @@ +// +// C++ Interface: msinterface +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MSINTERFACE_H +#define MAGICSMOKE_MSINTERFACE_H + +#include "MInterface.h" + +class MSInterface:public MInterface +{ + Q_OBJECT + public: + MSInterface(QString); + + static MSInterface* instance(){return qobject_cast(MInterface::instance());} + + bool login(QString,QString,QString); + void logout(); + bool relogin(); + QString currentUser()const; + bool hasRole(QString)const; + private: + QString profileid; +}; + + +#endif diff --git a/src/overview.cpp b/src/overview.cpp index 2d0b24a..2e4e4a0 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -16,9 +16,12 @@ #include "eventsummary.h" #include "misc.h" #include "moneylog.h" +#include "msinterface.h" #include "orderwin.h" #include "overview.h" -#include "webrequest.h" + +#include "user.h" +#include "host.h" #include #include @@ -52,12 +55,13 @@ #define ORDERUNSENT 4 #define ORDERRESERVE 8 -MOverview::MOverview(MWebRequest*mw,QString pk) +#define req (MSInterface::instance()) + +MOverview::MOverview(QString pk) { profilekey=pk; - req=mw; setAttribute(Qt::WA_DeleteOnClose); - setWindowTitle("MagicSmoke: "+mw->currentUser()+"@"+QSettings().value("profiles/"+pk+"/name").toString()); + setWindowTitle("MagicSmoke: "+req->currentUser()+"@"+QSettings().value("profiles/"+pk+"/name").toString()); rtimer.setInterval(QSettings().value("profiles/"+pk+"/refresh",300).toInt()*1000); rtimer.start(); connect(&rtimer,SIGNAL(timeout()),this,SLOT(refreshData())); @@ -367,22 +371,22 @@ MOverview::MOverview(MWebRequest*mw,QString pk) void MOverview::updateEvents() { - QListevl=req->getAllEvents(); + QListevl=req->queryGetAllEvents().getevents(); eventmodel->clear(); eventmodel->insertColumns(0,6); eventmodel->setHorizontalHeaderLabels(QStringList()<isChecked())continue; eventmodel->insertRow(j); - eventmodel->setData(eventmodel->index(j,0),evl[i].eventId(),Qt::UserRole); + eventmodel->setData(eventmodel->index(j,0),evl[i].id().value(),Qt::UserRole); eventmodel->setData(eventmodel->index(j,0),stime.toString(tr("ddd MMMM d yyyy, h:mm ap","time format"))); - eventmodel->setData(eventmodel->index(j,1),evl[i].title()); + eventmodel->setData(eventmodel->index(j,1),evl[i].title().value()); eventmodel->setData(eventmodel->index(j,2),evl[i].capacity()-evl[i].amountSold()-evl[i].amountReserved()); - eventmodel->setData(eventmodel->index(j,3),evl[i].amountReserved()); - eventmodel->setData(eventmodel->index(j,4),evl[i].amountSold()); - eventmodel->setData(eventmodel->index(j,5),evl[i].capacity()); + eventmodel->setData(eventmodel->index(j,3),evl[i].amountReserved().value()); + eventmodel->setData(eventmodel->index(j,4),evl[i].amountSold().value()); + eventmodel->setData(eventmodel->index(j,5),evl[i].capacity().value()); j++; } eventtable->resizeColumnsToContents(); @@ -408,13 +412,13 @@ void MOverview::relogin() { setEnabled(false); if(!req->relogin()) - QMessageBox::warning(this,tr("Warning"),tr("I was unable to renew the login at the server, the error was: %1").arg(req->errorString())); + QMessageBox::warning(this,tr("Warning"),tr("I was unable to renew the login at the server.")); setEnabled(true); } void MOverview::newEvent() { - MEventEditor ed(this,req); + MEventEditor ed(this); ed.exec(); updateEvents(); } @@ -427,7 +431,7 @@ void MOverview::editEvent() QModelIndex idx=eventmodel->index(ilst[0].row(),0); id=eventmodel->data(idx,Qt::UserRole).toInt(); if(id<0)return; - MEventEditor ed(this,req,id); + MEventEditor ed(this,id); ed.exec(); updateEvents(); } @@ -440,7 +444,7 @@ void MOverview::eventSummary() QModelIndex idx=eventmodel->index(ilst[0].row(),0); id=eventmodel->data(idx,Qt::UserRole).toInt(); if(id<0)return; - MEventSummary ed(this,req,id); + MEventSummary ed(this,id); ed.exec(); } @@ -1005,7 +1009,7 @@ void MOverview::cartOrder() QMessageBox::warning(this,tr("Error"),tr("The request failed.")); return; } - if(req->responseStatus()!=MWebRequest::Ok){ + if(req->responseStatus()!=MSInterface::Ok){ QMessageBox::warning(this,tr("Error"),tr("A problem occurred during the order: %1").arg(qApp->translate("php::",req->responseBody()))); return; } @@ -1183,7 +1187,7 @@ void MOverview::orderByTicket() QMessageBox::warning(this,tr("Warning"),tr("Unable to query server.")); return; } - if(req->responseStatus()!=MWebRequest::Ok){ + if(req->responseStatus()!=MSInterface::Ok){ QMessageBox::warning(this,tr("Warning"),qApp->translate("php::",req->responseBody())); return; } @@ -1386,7 +1390,7 @@ void MOverview::deductVoucher() QMessageBox::warning(this,tr("Warning"),tr("Request failed.")); return; } - if(req->responseStatus()!=MWebRequest::Ok){ + if(req->responseStatus()!=MSInterface::Ok){ QMessageBox::warning(this,tr("Warning"),tr("Request failed.")); return; } @@ -1463,7 +1467,7 @@ void MOverview::webSettings(bool showdlg) QSettings set; set.beginGroup("profiles/"+profilekey); //get settings - MWebRequest::LogLevel lvl=MWebRequest::LogLevel(set.value("webloglevel", MWebRequest::LogOnError).toInt()); + MSInterface::LogLevel lvl=MSInterface::LogLevel(set.value("webloglevel", MSInterface::LogOnError).toInt()); int timeout=set.value("webtimeout",30).toInt(); //dialog if(showdlg){ @@ -1480,13 +1484,13 @@ void MOverview::webSettings(bool showdlg) QComboBox *log; gl->addWidget(new QLabel(tr("Log Level:")),1,0); gl->addWidget(log=new QComboBox,1,1); - log->addItem(tr("Minimal Logging"),MWebRequest::LogMinimal); - log->addItem(tr("Log Details on Error"),MWebRequest::LogOnError); - log->addItem(tr("Always Log Details"),MWebRequest::LogDetailed); + log->addItem(tr("Minimal Logging"),MSInterface::LogMinimal); + log->addItem(tr("Log Details on Error"),MSInterface::LogOnError); + log->addItem(tr("Always Log Details"),MSInterface::LogDetailed); switch(lvl){ - case MWebRequest::LogMinimal:log->setCurrentIndex(0);break; - case MWebRequest::LogOnError:log->setCurrentIndex(1);break; - case MWebRequest::LogDetailed:log->setCurrentIndex(2);break; + case MSInterface::LogMinimal:log->setCurrentIndex(0);break; + case MSInterface::LogOnError:log->setCurrentIndex(1);break; + case MSInterface::LogDetailed:log->setCurrentIndex(2);break; } gl->setRowMinimumHeight(2,15); gl->addLayout(hl=new QHBoxLayout,3,0,1,2); @@ -1498,7 +1502,7 @@ void MOverview::webSettings(bool showdlg) connect(p,SIGNAL(clicked()),&d,SLOT(reject())); if(d.exec()!=QDialog::Accepted)return; //write settings - lvl=MWebRequest::LogLevel(log->itemData(log->currentIndex()).toInt()); + lvl=MSInterface::LogLevel(log->itemData(log->currentIndex()).toInt()); timeout=tmout->value(); set.setValue("webloglevel",lvl); set.setValue("webtimeout",timeout); @@ -1520,7 +1524,7 @@ void MOverview::doBackup() int gens=set.value("backupgenerations",3).toInt(); //get data bool ok=req->request("backup"); - if(ok)ok=req->responseStatus()==MWebRequest::Ok; + if(ok)ok=req->responseStatus()==MSInterface::Ok; if(!ok){ QMessageBox::warning(this,tr("Warning"),tr("Backup failed with error: %1").arg(req->errorString())); return; @@ -1580,7 +1584,7 @@ void MOverview::moneylogUser() /**********************************************/ -MBackupDialog::MBackupDialog(QWidget*par,QString pk,MWebRequest*req) +MBackupDialog::MBackupDialog(QWidget*par,QString pk,MSInterface*req) :QDialog(par),profilekey(pk) { QSettings set; diff --git a/src/overview.h b/src/overview.h index fa426e9..b3bea8e 100644 --- a/src/overview.h +++ b/src/overview.h @@ -17,12 +17,10 @@ #include #include #include -#include #include #include "customer.h" -class MWebRequest; class QAction; class QCheckBox; class QComboBox; @@ -40,7 +38,7 @@ class MOverview:public QMainWindow Q_OBJECT public: /**construct the window with web-request/session handler and QSettings-key for current profile*/ - MOverview(MWebRequest*,QString); + MOverview(QString); ~MOverview(); protected: /**handle closing the window: close the session too*/ @@ -162,8 +160,6 @@ class MOverview:public QMainWindow void backupSettings(); private: - //my session object - QPointerreq; //the profile associated with this session QString profilekey; //widgets @@ -222,7 +218,7 @@ class MBackupDialog:public QDialog { Q_OBJECT public: - MBackupDialog(QWidget*,QString,MWebRequest*); + MBackupDialog(QWidget*,QString); private slots: void getpath(); diff --git a/src/smoke.pro b/src/smoke.pro index 5fb39bd..8be0349 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -28,7 +28,6 @@ SOURCES = \ mainwindow.cpp \ hmac.cpp \ code39.cpp \ - webrequest.cpp \ overview.cpp \ eventedit.cpp \ event.cpp \ @@ -38,7 +37,6 @@ SOURCES = \ order.cpp \ shipping.cpp \ customer.cpp \ - checkdlg.cpp \ eventsummary.cpp \ odtrender.cpp \ ticketrender.cpp \ @@ -48,7 +46,6 @@ SOURCES = \ templates.cpp \ templatedlg.cpp \ office.cpp \ - centbox.cpp \ moneylog.cpp \ autoupdate.cpp \ domquery.cpp @@ -58,7 +55,6 @@ HEADERS = \ debug.h \ mainwindow.h \ hmac.h \ - webrequest.h \ overview.h \ eventedit.h \ event.h \ @@ -68,7 +64,6 @@ HEADERS = \ order.h \ shipping.h \ customer.h \ - checkdlg.h \ eventsummary.h \ odtrender.h \ ticketrender.h \ @@ -78,7 +73,6 @@ HEADERS = \ templates.h \ templatedlg.h \ office.h \ - centbox.h \ moneylog.h \ autoupdate.h \ domquery.h @@ -96,6 +90,7 @@ TRANSLATIONS = \ include(../zip/zip.pri) +include(widgets/widgets.pri) include(wbase/wbase.pri) include(wob/wob.pri) diff --git a/src/wbase/WInterface.cpp b/src/wbase/WInterface.cpp index 04b191d..40d9d43 100644 --- a/src/wbase/WInterface.cpp +++ b/src/wbase/WInterface.cpp @@ -30,6 +30,7 @@ WInterface::WInterface(QString name) { m_proxyport=0; m_wtimeout=30; + loglvl=LogOnError; QMutexLocker ml(&mtx); if(inst.contains(name)){ delete inst[name]; diff --git a/src/wbase/WInterface.h b/src/wbase/WInterface.h index 5c3625b..29b2983 100644 --- a/src/wbase/WInterface.h +++ b/src/wbase/WInterface.h @@ -30,17 +30,11 @@ class WInterface:public QObject /**returns the URL of the interface*/ QUrl url()const{return m_url;} - /**sets the URL of the interface*/ - void setUrl(QUrl u){m_url=u;} /**returns whether the interface uses a proxy*/ bool useProxy()const{return m_proxyhost!="";} /**returns whether the proxy needs authentication*/ bool useProxyAuth()const{return m_proxyuser!="";} - /**resets the proxy settings to no proxy use*/ - void resetProxy(){m_proxyhost="";m_proxyport=0;m_proxyuser="";m_proxypass="";} - /**sets the proxy settings*/ - void setProxy(QString proxyhost,unsigned short proxyport,QString proxyuser="",QString proxypassword=""){m_proxyhost=proxyhost;m_proxyport=proxyport;m_proxyuser=proxyuser;m_proxypass=proxypassword;} /**returns the proxy host name*/ QString proxyHost()const{return m_proxyhost;} /**returns the proxy port*/ @@ -52,8 +46,6 @@ class WInterface:public QObject /**return timeout in seconds*/ int webTimeout()const{return m_wtimeout;} - /**set timeout for page loads in seconds*/ - void setWebTimeout(int t){if(t>0)m_wtimeout=t;} /**get the name for this interface (returns empty string if not registered*/ QString name()const; @@ -61,12 +53,41 @@ class WInterface:public QObject /**returns the instance registered under that name*/ static WInterface*instance(QString); + /**log settings*/ + enum LogLevel { + /**minimal logging*/ + LogMinimal=0, + /**log details on error*/ + LogOnError=1, + /**always log details*/ + LogDetailed=0xf + }; + + /**returns the current log level*/ + LogLevel logLevel()const{return loglvl;} + + public slots: + /**set log level*/ + void setLogLevel(WInterface::LogLevel l){loglvl=l;} + + /**set timeout for page loads in seconds*/ + void setWebTimeout(int t){if(t>0)m_wtimeout=t;} + + /**resets the proxy settings to no proxy use*/ + void resetProxy(){m_proxyhost="";m_proxyport=0;m_proxyuser="";m_proxypass="";} + /**sets the proxy settings*/ + void setProxy(QString proxyhost,unsigned short proxyport,QString proxyuser="",QString proxypassword=""){m_proxyhost=proxyhost;m_proxyport=proxyport;m_proxyuser=proxyuser;m_proxypass=proxypassword;} + + /**sets the URL of the interface*/ + void setUrl(QUrl u){m_url=u;} + private: static QMapinst; QUrl m_url; QString m_proxyhost,m_proxyuser,m_proxypass; unsigned short m_proxyport; int m_wtimeout; + LogLevel loglvl; }; #endif diff --git a/src/wbase/WTransaction.cpp b/src/wbase/WTransaction.cpp index f5f2eba..232c0a3 100644 --- a/src/wbase/WTransaction.cpp +++ b/src/wbase/WTransaction.cpp @@ -13,8 +13,7 @@ #include "WTransaction.h" #include "WInterface.h" -//WaitCursor, TODO: refactor this -#include "main.h" +#include "waitcursor.h" #include #include diff --git a/src/webrequest.cpp b/src/webrequest.cpp deleted file mode 100644 index 2156e87..0000000 --- a/src/webrequest.cpp +++ /dev/null @@ -1,649 +0,0 @@ -// -// C++ Implementation: webrequest -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "hmac.h" -#include "keygen.h" -#include "main.h" -#include "templatedlg.h" -#include "version.h" -#include "webrequest.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -static QPointersinst; - -MWebRequest::MWebRequest(QString pid) - :temp(this,pid) -{ - sinst=this; - profileid=pid; - webtimeout=QSettings().value("profiles/"+pid+"/webtimeout",30).toInt()*1000; - loglvl=LogLevel(QSettings().value("profiles/"+pid+"/webloglevel",LogOnError).toInt()); - finid=0;finerr=fin=false; - proxyport=-1; - sessiontimeout=0; - connect(&req,SIGNAL(requestFinished(int,bool)),this,SLOT(httpFin(int,bool))); - QTimer*tm=new QTimer(this); - tm->setSingleShot(false); - tm->start(10000); - connect(tm,SIGNAL(timeout()),this,SLOT(reloginCheck())); -} -MWebRequest::~MWebRequest(){} - -MWebRequest* MWebRequest::instance(){return sinst;} - -QString MWebRequest::dataDir()const -{ - QString dd="profile."+profileid; - QDir dir(::dataDir); - if(!dir.exists(dd)) - if(!dir.mkpath(dd)) - qDebug("Warning: oh dir! Can't create my data directory!"); - return ::dataDir+"/"+dd; -} - -QString MWebRequest::settingsGroup()const -{ - return "profsettings/"+profileid; -} - -MWebRequest::LogLevel MWebRequest::logLevel()const -{ - return loglvl; -} - -void MWebRequest::setLogLevel(LogLevel l) -{ - loglvl=l; -} - -static inline QString esc(const QByteArray ar) -{ - QString r; - for(int i=0;i=32 && a<=127))r+=(char)a; - else r+="\\x"+QByteArray((char*)&a,1).toHex(); - } - return r; -} - -bool MWebRequest::request(QString hreq,QByteArray data) -{ - //show the user we are waiting - WaitCursor wc; - //set up request - QString log; - QEventLoop loop(this); - connect(this,SIGNAL(requestFinInt()),&loop,SLOT(quit())); - int port=url.port(); - if(port<=0){ - if(url.scheme().toLower()=="http")port=80; - else port=443; - } - qDebug()<0)req.setProxy(proxyname,proxyport,proxyuser,proxypass); - QString pathspec=url.path();if(pathspec=="")pathspec="/"; - if(url.encodedQuery()!="")pathspec+="?"+url.encodedQuery(); - QHttpRequestHeader hrh("POST",url.path()); - QString hostspec=url.host(); - if(url.port()>0)hostspec+=":"+QString::number(port); - hrh.setValue("Host",hostspec); - hrh.setValue("X-MagicSmoke-Request",hreq); - hrh.setValue("X-MagicSmoke-Session",sessionid); - hrh.setContentLength(data.size()); - hrh.setContentType("application/x-magicsmoke; charset=UTF-8"); - waitid=req.request(hrh,data); - if(loglvl>LogMinimal) - log=QString("Request %3 with header:\n%1\n\nRequest Body:\n%2\n<---->\n").arg(hrh.toString()).arg(esc(data)).arg(waitid); - qDebug("started req %i",waitid); - fin=false;errstr=""; - rspstatus="";rspdata.clear(); - //start loop - QTimer::singleShot(webtimeout,&loop,SLOT(quit())); - loop.exec(); - //process result - if(!fin){ - //it did not finish yet, caught a timeout. - req.abort(); - errstr="Web Request timed out."; - rspstatus="HTTP"; - qDebug("Request %i timed out.",waitid); - if(loglvl&LogOnError) - qDebug()<\nHTTP Response %3 Headers:\n%1\nHTTP Response %3 Body:\n%2\n<------------------").arg(rsph.toString()).arg(esc(rspdata)).arg(waitid); - qDebug()<0) - webtimeout=t; -} - -bool MWebRequest::setUrl(QUrl u) -{ - QString s=u.scheme().toLower(); - if(s!="http"&&s!="https")return false; - url=u; - return true; -} - -void MWebRequest::httpFin(int i,bool e) -{ - qDebug("finished req %i",i); - if(i!=waitid)return; - finid=i;finerr=e;fin=true; - emit requestFinInt(); -} - -void MWebRequest::setProxy(QString h,quint16 p,QString u,QString pw) -{ - proxyname=h;proxyport=p; - proxyuser=u;proxypass=pw; -} - -static inline QString calcAuth(QString algo,QString cha,QString pwd) -{ - QString ret; - if(algo=="md5") - return QCryptographicHash::hash(cha.toUtf8()+pwd.toUtf8(),QCryptographicHash::Md5).toHex(); - if(algo=="sha1") - return QCryptographicHash::hash(cha.toUtf8()+pwd.toUtf8(),QCryptographicHash::Sha1).toHex(); - if(algo=="hmac-md5") - return SMHmac::hmac(cha.toUtf8(),pwd.toUtf8(),QCryptographicHash::Md5).toHex(); - if(algo=="hmac-sha1") - return SMHmac::hmac(cha.toUtf8(),pwd.toUtf8(),QCryptographicHash::Sha1).toHex(); - //unreachable - return QByteArray(); -} - -bool MWebRequest::login(QString usr,QString pwd,QString hn) -{ - user=usr;passwd=pwd;hostname=hn; - return doLogin(); -} - -bool MWebRequest::doLogin() -{ - sessiontimeout=0; - //get authentication algo - if(!request("serverinfo"))return false; - if(rspstatus.toLower()!="ok"){ - errstr=tr("Unable to get server info."); - return false; - } - QString algo; - QDomDocument doc; - QString err;int ln,cl; - if(!doc.setContent(rspdata,&err,&ln,&cl)){ - errstr=tr("Error while parsing server info (line %1 col %2): %3").arg(ln).arg(cl).arg(err); - return false; - } - QDomNodeList nl=doc.documentElement().elementsByTagName("AuthAlgorithm"); - if(nl.size()!=1){ - errstr=tr("Error in server info: missing authentication algorithm info."); - return false; - } - algo=nl.at(0).toElement().text().trimmed().toLower(); - if(algo!="md5"&&algo!="sha1"&&algo!="hmac-md5"&&algo!="hmac-sha1"){ - errstr=tr("The server requested an unsupported hash algorithm: %1.").arg(algo); - return false; - } - //get challenge - if(!request("startsession",getRandom(32).toHex()))return false; - if(rspstatus.toLower()!="ok"){ - errstr=tr("Unable to get authentication challenge."); - return false; - } - if(!doc.setContent(rspdata,&err,&ln,&cl)){ - errstr=tr("Error while parsing session challenge (line %1 col %2): %3").arg(ln).arg(cl).arg(err); - return false; - } - QDomElement del=doc.documentElement(); - nl=del.elementsByTagName("ID"); - if(nl.size()!=1){ - errstr=tr("Error in session challenge: missing session ID."); - return false; - } - sessionid=nl.at(0).toElement().text().trimmed(); - nl=del.elementsByTagName("HostChallenge"); - if(nl.size()!=1){ - errstr=tr("Error in session challenge: missing host challenge."); - return false; - } - QString hcha=nl.at(0).toElement().text().trimmed(); - nl=del.elementsByTagName("UserChallenge"); - if(nl.size()!=1){ - errstr=tr("Error in session challenge: missing user challenge."); - return false; - } - QString ucha=nl.at(0).toElement().text().trimmed(); - //calculate auth - hcha=calcAuth(algo,hcha,QSettings().value("hostkey").toString()); - ucha=calcAuth(algo,ucha,passwd); - //create auth msg - QDomDocument adoc("Authenticate"); - del=adoc.createElement("SessionAuth"); - QDomElement el=adoc.createElement("HostName"); - el.appendChild(adoc.createTextNode(hostname)); - del.appendChild(el); - el=adoc.createElement("HostAuth"); - el.appendChild(adoc.createTextNode(hcha)); - del.appendChild(el); - el=adoc.createElement("UserName"); - el.appendChild(adoc.createTextNode(user)); - del.appendChild(el); - el=adoc.createElement("UserAuth"); - el.appendChild(adoc.createTextNode(ucha)); - del.appendChild(el); - adoc.appendChild(del); - //authenticate - if(!request("sessionauth",adoc.toByteArray()))return false; - if(rspstatus.toLower()=="unauthenticated"){ - errstr=tr("Failed to log in: user/password mismatch, non-allowed host key, or challenge timed out."); - return false; - } - if(rspstatus.toLower()!="ok"){ - errstr=tr("Unable to authenticate."); - return false; - } - //get timestamps from server - QStringList tlst=QString::fromAscii(rspdata).trimmed().split("\n",QString::SkipEmptyParts); - qint64 tout=-1,tcur=-1; - bool b; - if(tlst.size()>=1){ - tout=tlst[0].trimmed().toInt(&b); - if(!b)tout=-1; - } - if(tlst.size()>=2){ - tcur=tlst[1].trimmed().toInt(&b); - if(!b)tcur=-1; - } - //correct timeout - if(tcur>=0){ - int toff=QDateTime::currentDateTime().toTime_t()-tcur; - tout+=toff; - } - //store new timeout (don't store if this is less than 5min in the future, - // to prevent endless loops) - if((tout-300)>QDateTime::currentDateTime().toTime_t()) - sessiontimeout=tout-30;//safety range of 20s + 10s timer delay - //all ok - return true; -} - -void MWebRequest::logout() -{ - sessiontimeout=0; - request("closesession"); -} - -bool MWebRequest::relogin() -{ - request("closesession"); - return doLogin(); -} - -QString MWebRequest::changeMyPassword(QString o,QString n) -{ - //check old - if(passwd!=o)return tr("Cannot change password, old password does not match!"); - //create DOM tree - QDomDocument doc; - QDomElement el=doc.createElement("SetMyPasswd"); - el.setAttribute("oldpwd",o); - el.setAttribute("newpwd",n); - doc.appendChild(el); - //request - request("setmypasswd",doc.toByteArray()); - if(responseStatus()==MWebRequest::Ok)return ""; - else return tr(rspdata.data()); -} - -QString MWebRequest::errorString() -{ - return errstr; -} - -bool MWebRequest::hasRole(QString r) -{ - //get roles - if(roles.size()==0){ - //get roles from server - if(!request("getmyroles"))return false; - //parse data - QStringList rls=QString::fromAscii(rspdata).split("\n",QString::SkipEmptyParts); - for(int i=0;i MWebRequest::getAllEvents() -{ - errstr=""; - if(!request("geteventlist"))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing EventList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Event"); - QListret; - for(int i=0;i MWebRequest::getAllRooms() -{ - errstr=""; - if(!request("getroomdata",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing RoomList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Room"); - QListret; - for(int i=0;i MWebRequest::getAllUsers() -{ - errstr=""; - if(!request("getusers",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing UserList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("User"); - QListret; - for(int i=0;i MWebRequest::getAllHosts() -{ - errstr=""; - if(!request("gethosts",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing HostList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Host"); - QListret; - for(int i=0;i MWebRequest::getAllCustomers() -{ - errstr=""; - if(!request("getcustomerlist",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing CustomerList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Customer"); - QListret; - for(int i=0;i MWebRequest::getAllOrders() -{ - errstr=""; - if(!request("getorderlist",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing OrderList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Order"); - QListret; - for(int i=0;i MWebRequest::getAllShipping() -{ - if(!hasRole("getshipping"))return QList(); - errstr=""; - if(!request("getshipping",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing ShippingList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("ShippingOption"); - QListret; - for(int i=0;iMWebRequest::getVoucherPrices() -{ - if(!hasRole("getvoucherprices"))return QList(); - errstr=""; - if(!request("getvoucherprices",""))return QList(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QStringList lst=QString::fromAscii(responseBody()).split(" "); - QListret; - for(int i=0;i MWebRequest::getOrdersByEvents(QListevids) -{ - errstr=""; - QString evs; - for(int i=0;i(); - if(responseStatus()!=Ok)return QList(); - //parse return document - QDomDocument doc; - QString msg;int ln,cl; - if(!doc.setContent(rspdata,&msg,&ln,&cl)){ - errstr=tr("Error parsing OrderList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg); - return QList(); - } - QDomElement root=doc.documentElement(); - QDomNodeList nl=root.elementsByTagName("Order"); - QListret; - for(int i=0;i, (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef MAGICSMOKE_WEBREQUEST_H -#define MAGICSMOKE_WEBREQUEST_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "customer.h" -#include "event.h" -#include "host.h" -#include "order.h" -#include "room.h" -#include "shipping.h" -#include "templates.h" -#include "user.h" - -/**abstraction of requests to the web server, handles sessions and all data transfer; singleton*/ -class MWebRequest:public QObject -{ - Q_OBJECT - public: - MWebRequest(QString profileid); - ~MWebRequest(); - - static MWebRequest* instance(); - - /**returns the data directory of this profile; it makes sure the directory exists*/ - QString dataDir()const; - - /**returns the settings group of this profile; this group is free to be filled by other entities, it is not used by the webrequest itself or the mainwindow*/ - QString settingsGroup()const; - - /**generic request method, use the macro functions if possible; this function blocks until the request either succeeds, times out or fails; returns false if the request failed or timed out*/ - bool request(QString requestName,QByteArray data=QByteArray()); - /**returns the body returned by the server for the last request*/ - QByteArray responseBody(); - - enum ResponseStatus{ - /**Everything was ok*/ - Ok=0, - /**an unknown error occurred*/ - Error=1, - /**the request was not a POST method (should never happen)*/ - NonPost=2, - /**the session expired or was never established*/ - Unauthorized=3, - /**the user does not have this right*/ - NotAllowed=4, - /**the request name was invalid, the request does not exist*/ - InvalidRequest=5, - /**the request data had syntactical errors*/ - SyntaxError=6, - /**the HTTP transport failed (time out) or the server was unable to execute the script; this code is set in all cases in which request returns false*/ - HttpError=100 - }; - - /**returns the (lower-case) response status of the last request*/ - ResponseStatus responseStatus(); - - /**returns the last error as string*/ - QString errorString(); - - /**returns whether the user has a specific role/right*/ - bool hasRole(QString); - - /**returns a list of all events (in incomplete state)*/ - QListgetAllEvents(); - - /**returns a list of all rooms (without description, which is loaded dynamically if requested)*/ - QListgetAllRooms(); - - /**returns a list of all users**/ - QListgetAllUsers(); - - /**returns a list of all hosts**/ - QListgetAllHosts(); - - /**returns a list of all customers*/ - QListgetAllCustomers(); - - /**returns a list of all orders*/ - QListgetAllOrders(); - - /**returns a list of all available shipping methods*/ - QListgetAllShipping(); - - /**returns valid voucher prices in cents*/ - QListgetVoucherPrices(); - - /**returns a list of all orders that order from one of the specified events*/ - QListgetOrdersByEvents(QList); - - /**return current host name of this session*/ - QString hostName(); - - /**returns the requested template as cached locally (see MTemplateStore for details)*/ - MTemplate getTemplate(QString); - - /**log settings*/ - enum LogLevel { - /**minimal logging*/ - LogMinimal=0, - /**log details on error*/ - LogOnError=1, - /**always log details*/ - LogDetailed=0xf - }; - - /**returns the current log level*/ - LogLevel logLevel()const; - - /**returns currently logged in user*/ - QString currentUser()const{return user;} - - public slots: - /**set how long to wait for a web request*/ - void setTimeout(int); - /**set URL to connect to*/ - bool setUrl(QUrl); - /**set proxy to be used*/ - void setProxy(QString,quint16,QString u=QString(),QString p=QString()); - - /**set log level*/ - void setLogLevel(MWebRequest::LogLevel); - - /**log in to web server; requires username/password and the local host name as arguments*/ - bool login(QString user,QString passwd,QString hostname); - /**re-log in to web server with previously set values*/ - bool relogin(); - /**log out of web server*/ - void logout(); - /**change password; returns error string if it fails, empty if it succeeds*/ - QString changeMyPassword(QString oldpwd,QString newpwd); - - /**force an update of templates*/ - void updateTemplates(); - - /**opens the template editor*/ - void editTemplates(); - - private slots: - /**internal: used by wait loop for web requests*/ - void httpFin(int,bool); - /**internal: check whether we need to redo the login*/ - void reloginCheck(); - - signals: - /**internal: used by wait loop for web request*/ - void requestFinInt(); - - private: - //central request object - QHttp req; - QString proxyname,proxyuser,proxypass; - QUrl url; - int webtimeout,proxyport; - LogLevel loglvl; - //login data - QString user,passwd,sessionid,hostname; - //accounting data - QStringList roles; - //error data - QString errstr; - bool finerr,fin; - //response data - QString rspstatus; - QByteArray rspdata; - int finid,waitid; - //session timeout for relogin - qint64 sessiontimeout; - //profile name for lookups - QString profileid; - //template subsystem - MTemplateStore temp; - - /**used by login and relogin to do the actual work*/ - bool doLogin(); -}; - -#endif diff --git a/src/widgets/centbox.cpp b/src/widgets/centbox.cpp new file mode 100644 index 0000000..a8db050 --- /dev/null +++ b/src/widgets/centbox.cpp @@ -0,0 +1,126 @@ +// +// C++ Implementation: centbox +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "centbox.h" +#include "misc.h" + +#include +#include +#include +#include + +MCentSpinBox::MCentSpinBox(QWidget*parent,int value,int maxValue) + :QAbstractSpinBox(parent),mvalid(priceRegExp(),this) +{ + mmin=0; + mmax=maxValue; + if(mmin>mmax)mmin=mmax; + mval=value; + if(mvalmmax)mval=mmax; + + setButtonSymbols(UpDownArrows); + lineEdit()->setText(cent2str(mval)); + connect(this,SIGNAL(editingFinished()),this,SLOT(fixup())); +} + +int MCentSpinBox::value()const +{ +// qDebug("current value: %i",mval); + return mval; +} + +void MCentSpinBox::setValue(int m) +{ + if(m>mmax)m=mmax; + if(msetText(cent2str(m)); + emit valueChanged(m); +} + +MCentSpinBox::StepEnabled MCentSpinBox::stepEnabled () const +{ + return (mval>mmin?StepDownEnabled:StepNone)|(mvalma)return; + mmin=mi; + mmax=ma; + if(mval>mmax){ + setValue(mmax); + }else + if(mvaladdWidget(new QLabel(label)); + vl->addWidget(box=new MCentSpinBox(this,val,maxValue)); + QHBoxLayout *hl; + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("OK"))); + p->setDefault(true); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel"))); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); +} + +int MCentDialog::value()const +{ + return box->value(); +} + +int MCentDialog::getCents(QWidget*parent,QString title,QString label,int val,int maxValue,bool*ok) +{ + MCentDialog d(parent,title,label,val,maxValue); + bool b=d.exec()==QDialog::Accepted; + if(ok)*ok=b; + if(b) + return d.value(); + else + return 0; +} diff --git a/src/widgets/centbox.h b/src/widgets/centbox.h new file mode 100644 index 0000000..4193737 --- /dev/null +++ b/src/widgets/centbox.h @@ -0,0 +1,60 @@ +// +// C++ Interface: centbox +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_CENTBOX_H +#define MAGICSMOKE_CENTBOX_H + +#include +#include +#include + +class MCentSpinBox:public QAbstractSpinBox +{ + Q_OBJECT + public: + MCentSpinBox(QWidget*parent=0,int value=0,int maxValue=2147483647); + + virtual int value()const; + virtual void setValue(int); + + virtual void setRange(int,int); + + virtual int minimumValue()const; + virtual int maximumValue()const; + + void stepBy(int); + protected: + virtual QValidator::State validate(QString &input, int &pos) const; + virtual StepEnabled stepEnabled () const; + signals: + void valueChanged(int); + private slots: + void fixup(); + private: + int mval,mmax,mmin; + QRegExpValidator mvalid; +}; + +class MCentDialog:public QDialog +{ + Q_OBJECT + public: + MCentDialog(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647); + + virtual int value()const; + + static int getCents(QWidget*parent=0,QString title=QString(),QString label=QString(),int value=0,int maxValue=2147483647,bool *ok=0); + private: + MCentSpinBox*box; +}; + +#endif diff --git a/src/widgets/checkdlg.cpp b/src/widgets/checkdlg.cpp new file mode 100644 index 0000000..2d5a3f6 --- /dev/null +++ b/src/widgets/checkdlg.cpp @@ -0,0 +1,104 @@ +// +// C++ Implementation: checkdlg +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "checkdlg.h" + +#include +#include +#include +#include + +MCheckDialog::MCheckDialog(QWidget*parent,const MCheckList&checks,QString title) + :QDialog(parent),m_list(checks) +{ + setWindowTitle(title); + //basic layout + QVBoxLayout *vl=new QVBoxLayout; + setLayout(vl); + QScrollArea *sa=new QScrollArea; + vl->addWidget(sa,10); + QHBoxLayout *hl=new QHBoxLayout; + vl->addLayout(hl,0); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("Ok")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + //fill area + QWidget*w=new QWidget; + w->setLayout(vl=new QVBoxLayout); + for(int i=0;isetChecked(m_list[i].isSet()); + vl->addWidget(cb); + m_boxes.append(cb); + } + sa->setWidget(w); +} + +MCheckList MCheckDialog::getCheckList()const +{ + for(int i=0;iisChecked()); + return m_list; +} + +/**************************************************/ + +MCheckItem::MCheckItem(){} +MCheckItem::~MCheckItem(){} + +QString MCheckItem::key()const{qDebug("???????????");return label();} + +MCheckList::MCheckList(){} + +MCheckList::MCheckList(const MCheckList&l) +{ + for(int i=0;icopy()); +} + +MCheckList& MCheckList::operator=(const MCheckList&l) +{ + for(int i=0;icopy()); +} + +MCheckList::~MCheckList() +{ + for(int i=0;i, (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_CHECKDLG_H +#define MAGICSMOKE_CHECKDLG_H + +#include +#include + +class QCheckBox; + +/**abstract base class for items that can be displayed in a MCheckDialog*/ +class MCheckItem +{ + public: + /**constructs an empty check item*/ + MCheckItem(); + /**deletes the check item*/ + virtual ~MCheckItem(); + + /**overwrite this to return a label that can be displayed*/ + virtual QString label()const=0; + /**overwrite this to return a key string that identifies the item (default implementation returns the label)*/ + virtual QString key()const; + /**overwrite this to return whether the item is checked*/ + virtual bool isSet()const=0; + /**overwrite this to change the checking status of the item*/ + virtual void set(bool)=0; + + protected: + friend class MCheckList; + /**overwrite this to creat an exact copy of the item (must be implemented and must return non-NULL)*/ + virtual MCheckItem* copy()const=0; +}; + +/**implements a list of checkable items*/ +class MCheckList +{ + public: + /**instantiate an empty list*/ + MCheckList(); + /**creates an exact copy of the list (uses MCheckItem::copy() )*/ + MCheckList(const MCheckList&); + /**deletes the list*/ + ~MCheckList(); + + /**adds an item to the list*/ + void addItem(MCheckItem*); + /**returns the size of the list*/ + int size()const; + + /**returns a writable reference to an item*/ + MCheckItem& operator[](int); + /**returns a const reference to an item*/ + const MCheckItem& operator[](int)const; + + /**makes this list an exact copy of the argument*/ + MCheckList& operator=(const MCheckList&); + private: + QList m_items; +}; + +/**a dialog that consists of check boxes in a QScrollArea */ +class MCheckDialog:public QDialog +{ + Q_OBJECT + public: + /**creates the dialog*/ + MCheckDialog(QWidget*parent,const MCheckList&checks,QString title); + + /**returns the current state of all check boxes, the return value is an exact copy of the check list from the constructor with updated check settings*/ + MCheckList getCheckList()const; + private: + QListm_boxes; + mutable MCheckList m_list; +}; + +#endif diff --git a/src/widgets/waitcursor.cpp b/src/widgets/waitcursor.cpp new file mode 100644 index 0000000..09959b8 --- /dev/null +++ b/src/widgets/waitcursor.cpp @@ -0,0 +1,26 @@ +// +// C++ Implementation: waitcursor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "waitcursor.h" + +#include +#include + +WaitCursor::WaitCursor() +{ + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); +} + +WaitCursor::~WaitCursor() +{ + QApplication::restoreOverrideCursor(); +} diff --git a/src/widgets/waitcursor.h b/src/widgets/waitcursor.h new file mode 100644 index 0000000..fa69615 --- /dev/null +++ b/src/widgets/waitcursor.h @@ -0,0 +1,27 @@ +// +// C++ Interface: waitcursor +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2009 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_WAITCURSOR_H +#define MAGICSMOKE_WAITCURSOR_H + +/**simple class to show a busy-cursor while an instance of it exists*/ +class WaitCursor +{ + public: + /**displays a wait cursor (Qt::WaitCursor)*/ + WaitCursor(); + /**restores the last normal cursor*/ + ~WaitCursor(); +}; + + +#endif diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri new file mode 100644 index 0000000..5409f0f --- /dev/null +++ b/src/widgets/widgets.pri @@ -0,0 +1,11 @@ +HEADERS += \ + widgets/waitcursor.h \ + widgets/centbox.h \ + widgets/checkdlg.h + +SOURCES += \ + widgets/waitcursor.cpp \ + widgets/centbox.cpp \ + widgets/checkdlg.cpp + +INCLUDEPATH += ./widgets \ No newline at end of file diff --git a/wob/event.wolf b/wob/event.wolf index 03fa4d1..0cb4a3f 100644 --- a/wob/event.wolf +++ b/wob/event.wolf @@ -30,4 +30,38 @@ + + + + + + + + + + + + + + + id start end capacity defaultprice cancelled title artist room cancelreason + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wob/magicsmoke.wolf b/wob/magicsmoke.wolf index 46e7b4c..0e90d05 100644 --- a/wob/magicsmoke.wolf +++ b/wob/magicsmoke.wolf @@ -13,7 +13,7 @@ - + diff --git a/woc/phpout.cpp b/woc/phpout.cpp index 8fbda4a..2eb1d90 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -354,6 +354,9 @@ QString WocPHPServerOut::classPropertyValidator(const WocClass&cls,QString prop) if(cls.propertyIsString(prop)) code+="\treturn true;\n";//TODO: special handling for astring else + if(cls.propertyIsBool(prop)) + code+="\treturn is_bool($value);\n"; + else if(cls.propertyIsObject(prop)) code+="\treturn is_a($value,\"WO"+cls.propertyPlainType(prop)+"\");\n"; else{ @@ -375,6 +378,11 @@ QString WocPHPServerOut::classPropertyListGetters(const WocClass&cls,QString pro code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=\"\".$p;\n"; code+="\treturn $ret;\n}\n"; }else + if(cls.propertyIsBool(prop)){ + code+="public function getstrlist_"+prop+"(){\n"; + code+="\t$ret=array();\n\tforeach($this->prop_"+prop+" as $p)$ret[]=$p?\"yes\":\"no\";\n"; + code+="\treturn $ret;\n}\n"; + }else if(cls.propertyIsEnum(prop)){ code+="public function getstrlist_"+prop+"(){\n"; code+="\t$ret=array();\n"; @@ -426,11 +434,20 @@ QString WocPHPServerOut::classPropertyListSetters(const WocClass&cls,QString pro }else if(cls.propertyIsInt(prop)){ code+="\t$prop=array();\n\tforeach($values as $value)\n"; - code+="\t\tif(is_numeric($value)){\n\t\t\t$prop=0+$value;\n\t\t}else return false;\n"; + code+="\t\tif(is_numeric($value)){\n\t\t\t$prop[]=0+$value;\n\t\t}else return false;\n"; code+="\t$this->prop_"+prop+"=$prop;\n\treturn true;\n"; acode+="\tif(is_numeric($value)){\n"; acode+="\t\t$this->prop_"+prop+"=0+$value;\n\t\treturn true;\n\t}else return false;\n"; }else + if(cls.propertyIsBool(prop)){ + code+="\t$prop=array();\n\tforeach($values as $value)\n"; + code+="\t\tif(is_bool($value))$prop[]=$value!=false;else\n"; + code+="\t\tif($value==\"yes\")$prop[]=true;else\n"; + code+="\t\tif($value==\"no\")$prop[]=false;else return false;\n"; + code+="\t$this->prop_"+prop+"=$prop;\n\treturn true;\n"; + acode+="\tif(is_bool($value)){\n"; + acode+="\t\t$this->prop_"+prop+"=$value!=false;\n\t\treturn true;\n\t}else return false;\n"; + }else if(cls.propertyIsString(prop)){ code+="\t$prop=array();\n\tforeach($values as $value)$prop[]=\"\".$value;\n"; code+="\t$this->prop_"+prop+"=$prop;\n\treturn true;\n"; @@ -465,6 +482,8 @@ QString WocPHPServerOut::classPropertyScalarGetters(const WocClass&cls,QString p else if(cls.propertyIsInt(prop))code+="public function getstr_"+prop+"(){return \"\".$this->prop_"+prop+";}\n"; else + if(cls.propertyIsBool(prop))code+="public function getstr_"+prop+"(){return $this->prop_"+prop+"?\"yes\":\"no\";}\n"; + else if(cls.propertyIsEnum(prop)){ code+="public function getstr_"+prop+"(){\n\tswitch($this->prop_"+prop+"){\n"; QList > ev=cls.enumValues(cls.propertyPlainType(prop)); @@ -500,6 +519,12 @@ QString WocPHPServerOut::classPropertyScalarSetters(const WocClass&cls,QString p if(cls.propertyIsInt(prop)) code+="\tif(is_numeric($value)){\n\t\t$this->prop_"+prop+"=0+$value;\n\t\treturn true;\n\t}else return false;\n"; else + if(cls.propertyIsBool(prop)){ + code+="\tif(is_bool($value))$this->prop_"+prop+"=$value!=false;else\n"; + code+="\tif($value==\"yes\")$this->prop_"+prop+"=true;else\n"; + code+="\tif($value==\"no\")$this->prop_"+prop+"=false;\n\telse return false;\n"; + code+="\treturn true;\n"; + }else if(cls.propertyIsString(prop)) code+="\t$this->prop_"+prop+"=\"\".$value;\n\treturn true;\n"; //TODO: special handling for astring @@ -576,6 +601,7 @@ QString WocPHPServerOut::classDeserializers(const WocClass&cls,QString cn) } } } + //TODO: use setters code+="\treturn new "+cn+"($data);\n}\n"; return code; } @@ -747,6 +773,7 @@ QString WocPHPServerOut::trnInput(const WocTransaction&trn) if(trn.isAttributeType(t)){ code+="\t\t$this->ainput[\""+sl[i]+"\"]=$root->getAttribute(\""+sl[i]+"\")"; if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; code+=";\n"; }else{ if(trn.isListType(t)){ @@ -757,6 +784,7 @@ QString WocPHPServerOut::trnInput(const WocTransaction&trn) }else{ code+="\t\t\t$this->ainput[\""+sl[i]+"\"][]=$el->textContent"; if(trn.isIntType(t))code+="+0"; + if(trn.isBoolType(t))code+="==\"yes\""; code+=";\n"; } code+="\t\t}\n"; @@ -834,6 +862,10 @@ QString WocPHPServerOut::trnGetSet(const WocTransaction&trn) code+="\t\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; add+="\tif(is_numeric($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv+0;\n"; }else + if(trn.isBoolType(t)){ + code+="\t\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; + add+="\tif(is_bool($vv))$this->aoutput[\""+sl[i]+"\"][]=$vv!=false;\n"; + }else if(trn.isObjectType(t)){ code+="\t\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; add+="\tif(is_a($vv,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"][]=$vv;\n"; @@ -847,6 +879,9 @@ QString WocPHPServerOut::trnGetSet(const WocTransaction&trn) if(trn.isIntType(t)){ code+="\tif(is_numeric($v))$this->aoutput[\""+sl[i]+"\"]=$v+0;\n"; }else + if(trn.isIntType(t)){ + code+="\tif(is_bool($v))$this->aoutput[\""+sl[i]+"\"]=$v!=false;\n"; + }else if(trn.isObjectType(t)){ code+="\tif(is_a($v,\"WO"+trn.plainType(t)+"\"))$this->aoutput[\""+sl[i]+"\"]=$v;\n"; }else{ diff --git a/woc/processor.cpp b/woc/processor.cpp index fff55db..49d12be 100644 --- a/woc/processor.cpp +++ b/woc/processor.cpp @@ -480,7 +480,7 @@ QString WocClass::propertyPlainType(QString p)const else return r; } -const QStringList WocClass::attrtypes=QStringList()<<"astring"<<"int"; +const QStringList WocClass::attrtypes=QStringList()<<"astring"<<"int"<<"int32"<<"int64"<<"bool"; bool WocClass::propertyIsAttribute(QString p)const { QString t=propertyPlainType(p); diff --git a/woc/processor.h b/woc/processor.h index 209cc9b..07831b4 100644 --- a/woc/processor.h +++ b/woc/processor.h @@ -72,7 +72,9 @@ class WocClass /**returns whether the property is a list of values (false for scalars)*/ bool propertyIsList(QString)const; /**returns whether the property type is integer*/ - bool propertyIsInt(QString p)const{return propertyPlainType(p)=="int";} + bool propertyIsInt(QString p)const{QString pt=propertyPlainType(p);return pt=="int" || pt=="int32" || pt=="int64";} + /**returns whether the property type is boolean*/ + bool propertyIsBool(QString p)const{return propertyPlainType(p)=="bool";} /**returns whether the property type is string*/ bool propertyIsString(QString p)const{QString pt=propertyPlainType(p);return pt=="string"||pt=="astring";} @@ -253,15 +255,17 @@ class WocTransaction else return ""; } /**returns true if the type is integer*/ - bool isIntType(QString t)const{return plainType(t)=="int";} + bool isIntType(QString t)const{QString pt=plainType(t);return pt=="int" || pt=="int32" || pt=="int64";} + /**returns true if the type is boolean*/ + bool isBoolType(QString t)const{return plainType(t)=="bool";} /**returns true if the type is a string*/ bool isStringType(QString t)const{QString p=plainType(t);return p=="astring"||p=="string";} /**returns true if the type is to be encoded as attribute*/ - bool isAttributeType(QString t)const{return t=="astring"||t=="int";} + bool isAttributeType(QString t)const{return t=="astring"||t=="int"||t=="int32"||t=="int64"||t=="bool";} /**returns true if the type is to be encoded as element*/ bool isElementType(QString t)const{return !isAttributeType(t);} /**return true if the type is an object type*/ - bool isObjectType(QString t)const{QString p=plainType(t);return p!="astring"&&p!="string"&&p!="int";} + bool isObjectType(QString t)const{QString p=plainType(t);return p!="astring"&&p!="string"&&p!="int"&&p!="int32"&&p!="int64"&&p!="bool";} private: QString m_name; bool m_valid; diff --git a/woc/qtout.cpp b/woc/qtout.cpp index fc4323c..b67e70c 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -62,7 +62,8 @@ WocQtClientOut::WocQtClientOut(QDomElement&el) m_pri.write(QByteArray("#AUTOMATICALLY GENERATED FILE - DONT CHANGE!\n")); //create interface class - QString pn=WocProcessor::instance()->projectName(); + WocProcessor*woc=WocProcessor::instance(); + QString pn=woc->projectName(); m_iface.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Interface.cpp"); if(!m_iface.open(QIODevice::WriteOnly|QIODevice::Truncate)){ qDebug("Error: cannot create Qt interface file %s.",m_iface.fileName().toAscii().data()); @@ -83,6 +84,10 @@ WocQtClientOut::WocQtClientOut(QDomElement&el) m_iface.write(QString("class "+m_prefix+"Interface:public WInterface\n{\n Q_OBJECT\n").toAscii()); m_iface.write(QString(" public:\n "+m_prefix+"Interface(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii()); m_iface.write(QString(" static "+m_prefix+"Interface*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+m_prefix+"Interface*>(WInterface::instance(name));}\n\n").toAscii()); + m_iface.write(QString(" QString commVersion()const{return \""+woc->verComm()+"\";}\n").toAscii()); + m_iface.write(QString(" QString needCommVersion()const{return \""+woc->verNeedComm()+"\";}\n").toAscii()); + m_iface.write(QString(" QString version()const{return \""+woc->verHR()+"\";}\n").toAscii()); + m_iface.write(QString(" QString svnVersion()const{return \""+woc->svnRevision()+"\";}\n\n").toAscii()); //create all includer m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Include.h"); @@ -232,6 +237,7 @@ QString WocQtClientOut::qttype(const WocClass&cls,QString p,bool dolist) else r="Nullable<"; if(cls.propertyIsString(p))r+="QString";else if(cls.propertyIsInt(p))r+="qint64";else + if(cls.propertyIsBool(p))r+="bool";else if(cls.propertyIsObject(p))r+=m_prefix+"O"+cls.propertyPlainType(p); else r+=cls.propertyPlainType(p); r+=">"; @@ -272,6 +278,9 @@ void WocQtClientOut::classDeserializer(const WocClass&cls,QFile&hdr,QFile&src,QS scd+="\t\tif(b)add"+k[i]+"(ct);\n"; scd+="\t\telse throw WDeserializerException(\"Class "+cn+" property "+k[i]+" is integer list, but non-integer was found.\");\n"; }else + if(cls.propertyIsBool(k[i])){ + scd+="\t\tadd"+k[i]+"(el.text()==\"yes\");\n"; + }else if(cls.propertyIsString(k[i])){ scd+="\t\tadd"+k[i]+"(el.text());\n"; }else @@ -301,6 +310,9 @@ void WocQtClientOut::classDeserializer(const WocClass&cls,QFile&hdr,QFile&src,QS scd+="\t\tif(b)set"+k[i]+"(ct);\n"; scd+="\t\telse throw WDeserializerException(\"Class "+cn+" property "+k[i]+" is integer, but non-integer was found.\");\n"; }else + if(cls.propertyIsBool(k[i])){ + scd+="\t\tset"+k[i]+"(root.attribute(\""+k[i]+"\")==\"yes\");\n"; + }else if(cls.propertyIsString(k[i])){ scd+="\t\tset"+k[i]+"(root.attribute(\""+k[i]+"\"));\n"; }else @@ -384,6 +396,11 @@ void WocQtClientOut::classSerializers(const WocClass&cls,QFile&hdr,QFile&src,QSt scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+"[i]));\n"; scd+="\t\tr.appendChild(el);\n"; }else + if(cls.propertyIsBool(prop)){ + scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n"; + scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+"[i]?\"yes\":\"no\"));\n"; + scd+="\t\tr.appendChild(el);\n"; + }else if(cls.propertyIsInt(prop)){ scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n"; scd+="\t\tel.appendChild(doc.createTextNode(QString::number(mp_"+prop+"[i])));\n"; @@ -398,7 +415,10 @@ void WocQtClientOut::classSerializers(const WocClass&cls,QFile&hdr,QFile&src,QSt //non lists scd+="\tif(!mp_"+prop+".isNull()){\n"; if(cls.propertyIsAttribute(prop)){ - scd+="\t\tr.setAttribute(\""+prop+"\",mp_"+prop+".value());\n"; + if(cls.propertyIsBool(prop)) + scd+="\t\tr.setAttribute(\""+prop+"\",mp_"+prop+".value()?\"yes\":\"no\");\n"; + else + scd+="\t\tr.setAttribute(\""+prop+"\",mp_"+prop+".value());\n"; }else{ if(cls.propertyIsObject(prop)){ scd+="\t\tr.appendChild(mp_"+prop+".toXml"+var+"(doc,\""+prop+"\"));\n"; @@ -507,6 +527,11 @@ void WocQtClientOut::newTransaction(const WocTransaction&trn) //create copy constructor hcd=" public:\n"; hcd+="\t"+cn+"(const "+cn+"&);\n"; + //create getters + for(int i=0;i