close ticket #66: port template dialog
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Apr 2010 11:01:26 +0000 (11:01 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 4 Apr 2010 11:01:26 +0000 (11:01 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@431 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/iface/msinterface.cpp
src/iface/msinterface.h
src/mwin/overview.cpp
src/mwin/overview.h
src/templates/templates.cpp
wob/template.wolf
www/inc/wext/template.php

index 374efee..e26a6e0 100644 (file)
@@ -195,3 +195,8 @@ void MSInterface::sslErrors(const QList<QSslError>&errs)
                QMessageBox::warning(0,tr("Connection Error"),tr("There were problems while authenticating the server. Aborting. Check your configuration."));
        }
 }
+
+void MSInterface::updateTemplates()
+{
+       if(temp)temp->updateTemplates(true);
+}
index 1afda98..fd2aacc 100644 (file)
@@ -84,7 +84,9 @@ class MSInterface:public MInterface
                void setSessionId(QString sid){m_sessid=sid;}
                /**handles SSL errors*/
                virtual void sslErrors(const QList<QSslError>&);
-       
+               /**force template store to update its templates*/
+               void updateTemplates();
+               
        private:
                QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey;
                mutable QList<Right>userrights;
index 652d7d7..17b1bed 100644 (file)
@@ -14,6 +14,7 @@
 #include "msinterface.h"
 #include "passwdchg.h"
 #include "customerdlg.h"
+#include "templatedlg.h"
 
 #include "overview.h"
 #include "eventstab.h"
@@ -67,7 +68,7 @@ MOverview::MOverview(QString pk)
        m->addAction(tr("Change my &Password"),this,SLOT(setMyPassword()))
         ->setEnabled(req->hasRight(req->RChangeMyPassword));
        m->addSeparator();
-       m->addAction(tr("&Edit Templates..."),req,SLOT(editTemplates()));
+       m->addAction(tr("&Edit Templates..."),this,SLOT(editTemplates()));
        m->addAction(tr("&Update Templates Now"),req,SLOT(updateTemplates()));
        m->addSeparator();
        m->addAction(tr("&Close Session"),this,SLOT(close()));
@@ -506,6 +507,12 @@ void MOverview::aclWindow()
        MAclWindow::showWindow(this);
 }
 
+void MOverview::editTemplates()
+{
+       MTemplateEditor te(MSInterface::instance()->templateStore());
+       te.exec();
+}
+
 /**********************************************/
 
 MBackupDialog::MBackupDialog(QWidget*par,QString pk)
index 559c858..7aeda85 100644 (file)
@@ -97,6 +97,9 @@ class MOverview:public QMainWindow
                /**open ACL/user admin window*/
                void aclWindow();
                
+               /**open template editor*/
+               void editTemplates();
+               
        private:
                //the profile associated with this session
                QString profilekey;
index 489b868..d58f243 100644 (file)
@@ -171,7 +171,7 @@ bool MTemplateStore::retrieveFile(QString dname,QString fn)
 }
 
 bool MTemplateStore::setTemplate(QString n,QString f)
-{/*TODO
+{
        //very rough sanity check
        QRegExp fregexp("[a-z0-9_\\.,]+");
        if(!fregexp.exactMatch(n))return false;
@@ -182,9 +182,8 @@ bool MTemplateStore::setTemplate(QString n,QString f)
        QByteArray ba=fl.readAll();
        fl.close();
        //send to server
-       if(!req->request("settemplate",n.toUtf8()+"\n"+ba))
-               return false;
-       if(req->responseStatus()!=MWebRequest::Ok)
+       MTSetTemplate st=req->querySetTemplate(n,ba,"");
+       if(st.hasError())
                return false;
        //delete it from cache, so it is retrieved again; force retrieval
        //TODO: the server returns the hash (since dec08), use it and update the cache without retrieval
@@ -193,28 +192,27 @@ bool MTemplateStore::setTemplate(QString n,QString f)
        set.setValue("templates/"+profileid+"/lastupdate",0);
        QFile(req->dataDir()+"/templates/"+n).remove();
        //return success
-       return true;*/return false;
+       return true;
 }
 
 bool MTemplateStore::deleteTemplate(QString n)
-{/*TODO
+{
        //very rough sanity check
        QRegExp fregexp("[a-z0-9_\\.,]+");
        if(!fregexp.exactMatch(n))return false;
        //send to server
-       if(!req->request("deletetemplate",n.toUtf8()))
-               return false;
-       if(req->responseStatus()!=MWebRequest::Ok)
+       MTDeleteTemplate dt=req->queryDeleteTemplate(n);
+       if(dt.hasError())
                return false;
        //delete it from cache
        QSettings set;
        set.remove("templates/"+profileid+"/"+n);
        QFile(req->dataDir()+"/templates/"+n).remove();
-       return true;*/return false;
+       return true;
 }
 
 bool MTemplateStore::setTemplateDescription(QString n,QString d)
-{/*TODO
+{
        //very rough sanity check
        QRegExp fregexp("[a-z0-9_\\.,]+");
        if(!fregexp.exactMatch(n))return false;
@@ -225,14 +223,13 @@ bool MTemplateStore::setTemplateDescription(QString n,QString d)
        qDebug("setting %s '%s' -> '%s'",n.toAscii().data(),o.toAscii().data(),d.toAscii().data());
        if(o==d)return true;
        //send to server
-       if(!req->request("settemplatedescription",n.toUtf8()+"\n"+d.toUtf8()))
-               return false;
-       if(req->responseStatus()!=MWebRequest::Ok)
+       MTSetTemplateDescription std=req->querySetTemplateDescription(n,d);
+       if(std.hasError())
                return false;
        //update internal description
        set.setValue("description",d);
        //return success
-       return true;*/return false;
+       return true;
 }
 
 QList<MTemplate> MTemplateStore::allTemplates()
index 59e4eab..694ba91 100644 (file)
                        <Var name="templatefile" type="Template"/>
                </Output>
        </Transaction>
+       
+       <Transaction name="SetTemplate">
+               <Input>
+                       <Var name="filename" type="astring"/>
+                       <Var name="templatedata" type="blob"/>
+                       <Var name="description" type="string"/>
+               </Input>
+               <Call lang="php" method="WOTemplate::setFile($this);"/>
+               <Output>
+                       <Var name="templatefile" type="Template"/>
+               </Output>
+       </Transaction>
+       <Transaction name="SetTemplateDescription">
+               <Input>
+                       <Var name="filename" type="astring"/>
+                       <Var name="description" type="string"/>
+               </Input>
+               <Call lang="php" method="WOTemplate::setTemplateDescription($this);"/>
+       </Transaction>
+       <Transaction name="DeleteTemplate">
+               <Input>
+                       <Var name="filename" type="astring"/>
+               </Input>
+               <Call lang="php" method="WOTemplate::deleteTemplate($this);"/>
+       </Transaction>
 </Wolf>
index 5044ad2..6492645 100644 (file)
@@ -26,6 +26,51 @@ class WOTemplate extends WOTemplateAbstract
                //TODO: filter by flags
                $trans->settemplatefile(WOTemplate::fromTabletemplate(WTtemplate::getFromDB($trans->getfilename())));
        }
+       
+       /**called by the SetTemplate transaction*/
+       static public function setFile($trans)
+       {
+               //find it
+               $tm=WTtemplate::getFromDB($trans->getfilename());
+               if($tm===false)
+                       $tm=WTtemplate::newRow();
+               //set data
+               $tm->filename=$trans->getfilename();
+               $tm->description=$trans->getdescription();
+               $tm->content=$trans->gettemplatedata();
+               $tm->hash=md5($trans->gettemplatedata());
+               $tm->dolog=false;
+               $tm->flags="";
+               //update
+               $tm->insertOrUpdate();
+               //return
+               $trans->settemplatefile(WOTemplate::fromTabletemplate($tm));
+       }
+       /**called by the SetTemplateDescription transaction*/
+       static public function setTemplateDescription($trans)
+       {
+               //find it
+               $tm=WTtemplate::getFromDB($trans->getfilename());
+               if($tm===false){
+                       $trans->abortWithError(tr("No such template."));
+                       return;
+               }
+               //overwrite
+               $tm->description=$trans->getdescription();
+               $tm->update();
+       }
+       /**called by the DeleteTemplate transaction*/
+       static public function deleteTemplate($trans)
+       {
+               //find it
+               $tm=WTtemplate::getFromDB($trans->getfilename());
+               if($tm===false){
+                       $trans->abortWithError(tr("No such template."));
+                       return;
+               }
+               //delete
+               $tm->deleteFromDb();
+       }
 };
 
 ?>
\ No newline at end of file