From 78fb85084b502b4a67c25180f90aabd8c5fc593c Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 10 Aug 2009 18:44:34 +0000 Subject: [PATCH] backup works again loglevels work again git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@328 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/order.cpp | 12 ++++++------ src/orderwin.cpp | 2 +- src/overview.cpp | 34 ++++++++++++++++++++-------------- src/wbase/WTransaction.cpp | 22 +++++++++++++--------- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/order.cpp b/src/order.cpp index 9384883..404ec6a 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -155,7 +155,7 @@ void MOrder::pruneInvalid() QString MOrder::orderDateTimeStr() { - if(ordertime()==0)return ""; + if(ordertime().value()==0)return ""; return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOrder","yyyy-MM-dd hh:mm ap","date/time format")); } @@ -166,7 +166,7 @@ QDate MOrder::orderDate() QString MOrder::orderDateStr() { - if(ordertime()==0)return ""; + if(ordertime().value()==0)return ""; return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOrder","yyyy-MM-dd","date format")); } @@ -177,7 +177,7 @@ QDateTime MOrder::sentDateTime() QString MOrder::sentDateTimeStr() { - if(senttime()==0)return ""; + if(senttime().value()==0)return ""; return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOrder","yyyy-MM-dd hh:mm ap","date/time format")); } @@ -188,7 +188,7 @@ QDate MOrder::sentDate() QString MOrder::sentDateStr() { - if(senttime()==0)return ""; + if(senttime().value()==0)return ""; return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOrder","yyyy-MM-dd","date format")); } @@ -424,9 +424,9 @@ QString MVoucher::valueString(int off)const{return cent2str(value()+off);} bool MVoucher::isValid()const{return voucherid().value()!="";} -bool MVoucher::isCancelled()const{return price()==0 && value()==0;} +bool MVoucher::isCancelled()const{return price().value()==0 && value().value()==0;} -bool MVoucher::isEmpty()const{return value()==0;} +bool MVoucher::isEmpty()const{return value().value()==0;} QString MVoucher::statusString()const { diff --git a/src/orderwin.cpp b/src/orderwin.cpp index 04e4d91..f6481a3 100644 --- a/src/orderwin.cpp +++ b/src/orderwin.cpp @@ -1071,7 +1071,7 @@ MShippingChange::MShippingChange(QWidget*pa,MOShipping s) int scid=0; for(int i=0;iaddItem(all[i].description()); - if(all[i].id()==cid) + if(all[i].id().value()==cid) scid=i+1; } opt->setCurrentIndex(scid); diff --git a/src/overview.cpp b/src/overview.cpp index ea83dfb..6a41530 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -85,7 +85,6 @@ MOverview::MOverview(QString pk) QMenuBar*mb=menuBar(); QMenu*m=mb->addMenu(tr("&Session")); m->addAction(tr("&Re-Login"),this,SLOT(relogin())); - m->addAction(tr("&Offline mode"))->setEnabled(false); m->addAction(tr("Change my &Password"),this,SLOT(setMyPassword())) ->setEnabled(req->hasRight(req->RChangeMyPassword)); m->addSeparator(); @@ -134,9 +133,9 @@ MOverview::MOverview(QString pk) m=mb->addMenu(tr("&Admin")); m->addAction(tr("Backup &Settings..."),this,SLOT(backupSettings())) - ->setEnabled(req->hasRole("backup")); + ->setEnabled(req->hasRight(req->RBackup)); m->addAction(tr("&Backup now..."),this,SLOT(doBackup())) - ->setEnabled(req->hasRole("backup")); + ->setEnabled(req->hasRight(req->RBackup)); mb->addMenu(MApplication::helpMenu()); @@ -1540,20 +1539,27 @@ void MOverview::webSettings(bool showdlg) } void MOverview::doBackup() -{/*TODO +{ baktimer.stop(); //sanity check - if(!req->hasRole("backup"))return; + if(!req->hasRight(req->RBackup))return; //get settings QSettings set; set.beginGroup("profiles/"+profilekey); QString path=set.value("backupfile",req->dataDir()+"/backup").toString(); int gens=set.value("backupgenerations",3).toInt(); //get data - bool ok=req->request("backup"); - if(ok)ok=req->responseStatus()==MSInterface::Ok; - if(!ok){ - QMessageBox::warning(this,tr("Warning"),tr("Backup failed with error: %1").arg(req->errorString())); + MTBackup bc; + try{bc=MTBackup::query();}catch(WException e){ + QMessageBox::warning(this,tr("Warning"),tr("Error while executing backup (%1): %2").arg(e.component()).arg(e.error())); + return; + } + if(bc.stage()!=bc.Success){ + QMessageBox::warning(this,tr("Warning"),tr("Backup failed with error (%2): %1").arg(bc.errorString()).arg(bc.errorType())); + return; + } + if(bc.getbackup().isNull()||bc.getbackup().value().isEmpty()){ + QMessageBox::warning(this,tr("Warning"),tr("Backup returned empty.")); return; } //rotate files @@ -1567,20 +1573,20 @@ void MOverview::doBackup() //store new data QFile fd(path); if(fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - fd.write(req->responseBody()); + fd.write(bc.getbackup().value().toAscii()); fd.close(); set.setValue("backuptime",QDateTime::currentDateTime().toTime_t()); QMessageBox::information(this,tr("Backup"),tr("The backup was successful.")); int tm=set.value("backupinterval",0).toInt()*86400000; if(tm)baktimer.start(tm); }else - QMessageBox::warning(this,tr("Warning"),tr("Cannot create backup file."));*/ + QMessageBox::warning(this,tr("Warning"),tr("Cannot create backup file.")); } void MOverview::backupSettings() -{/*TODO +{ //show dialog - MBackupDialog d(this,profilekey,req); + MBackupDialog d(this,profilekey); d.exec(); //reset timer int btm=QSettings().value("profiles/"+profilekey+"/backupinterval",0).toInt()*86400; @@ -1591,7 +1597,7 @@ void MOverview::backupSettings() else btm-=iv; //start timer baktimer.start(btm*1000); - }*/ + } } void MOverview::moneylogVoucher() diff --git a/src/wbase/WTransaction.cpp b/src/wbase/WTransaction.cpp index 7a4cae5..099b26a 100644 --- a/src/wbase/WTransaction.cpp +++ b/src/wbase/WTransaction.cpp @@ -108,21 +108,24 @@ QByteArray WTransaction::executeQuery(QString hreq,QByteArray data) hrh.setValue("X-WobRequest",hreq); hrh.setContentLength(data.size()); hrh.setContentType("application/x-webobject; charset=UTF-8"); + WInterface::LogLevel loglvl=iface->logLevel(); m_httpid=req.request(hrh,data); - //if(loglvl>LogMinimal) + if(loglvl>WInterface::LogMinimal) log=QString("Request %3 with header:\n%1\n\nRequest Body:\n%2\n<---->\n").arg(hrh.toString()).arg(esc(data)).arg(m_httpid); qDebug("started req %i",m_httpid); //start loop - QTimer::singleShot(iface->webTimeout()*1000,this,SLOT(webTimeout())); + QTimer tmr; + tmr.setSingleShot(true);tmr.start(iface->webTimeout()*1000); + connect(&tmr,SIGNAL(timeout()),this,SLOT(webTimeout())); loop.exec(); - m_httpid=-1; + tmr.stop();tmr.disconnect(SIGNAL(timeout()),this,SLOT(webTimeout())); //process result if(m_stage==Error && m_errtype=="_timeout"){ //it did not finish yet, caught a timeout. req.abort(); m_errstr="Web Request timed out."; qDebug("Request %i timed out.",m_httpid); - //TODO: if(loglvl&LogOnError) + if(loglvl&WInterface::LogOnError) qDebug()<\nHTTP Response %3 Headers:\n%1\nHTTP Response %3 Body:\n%2\n<------------------").arg(rsph.toString()).arg(esc(rspdata)).arg(m_httpid); qDebug()<