backup works again
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 10 Aug 2009 18:44:34 +0000 (18:44 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 10 Aug 2009 18:44:34 +0000 (18:44 +0000)
loglevels work again

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@328 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/order.cpp
src/orderwin.cpp
src/overview.cpp
src/wbase/WTransaction.cpp

index 9384883..404ec6a 100644 (file)
@@ -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
 {
index 04e4d91..f6481a3 100644 (file)
@@ -1071,7 +1071,7 @@ MShippingChange::MShippingChange(QWidget*pa,MOShipping s)
        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);
index ea83dfb..6a41530 100644 (file)
@@ -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()
index 7a4cae5..099b26a 100644 (file)
@@ -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()<<log;
                return QByteArray();
        }else
@@ -130,7 +133,7 @@ QByteArray WTransaction::executeQuery(QString hreq,QByteArray data)
        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();
        }
@@ -141,18 +144,19 @@ QByteArray WTransaction::executeQuery(QString hreq,QByteArray data)
                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;
 }