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"));
}
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"));
}
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"));
}
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"));
}
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
{
int scid=0;
for(int i=0;i<all.size();i++){
opt->addItem(all[i].description());
- if(all[i].id()==cid)
+ if(all[i].id().value()==cid)
scid=i+1;
}
opt->setCurrentIndex(scid);
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();
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());
}
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
//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;
else btm-=iv;
//start timer
baktimer.start(btm*1000);
- }*/
+ }
}
void MOverview::moneylogVoucher()
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()<<log;
return QByteArray();
}else
if(m_stage==Error){
m_errstr="HTTP Error: "+req.errorString();
log+=QString("Request %2 finished with HTTP level error: %1").arg(m_errstr).arg(m_httpid);
- //TODO: if(loglvl&LogOnError)
+ if(loglvl&WInterface::LogOnError)
qDebug()<<log;
return QByteArray();
}
m_errtype="_HTTP";
m_stage=Error;
log+=QString("Request %2 finished with HTTP level error: %1").arg(m_errstr).arg(m_httpid);
- //TODO: if(loglvl&LogOnError)
+ if(loglvl&WInterface::LogOnError)
qDebug()<<log;
return QByteArray();
}
//get data
QByteArray rspdata=req.readAll();
- //
- //TODO: if(loglvl==LogDetailed){
+ //log
+ if(loglvl==WInterface::LogDetailed){
log+=QString ("----->\nHTTP Response %3 Headers:\n%1\nHTTP Response %3 Body:\n%2\n<------------------").arg(rsph.toString()).arg(esc(rspdata)).arg(m_httpid);
qDebug()<<log;
- //}
+ }
if(m_stage!=Error)m_stage=Success;
+ //remaining high level errors are handled by the generated code
return rspdata;
}