From: konrad Date: Sun, 4 Apr 2010 11:01:26 +0000 (+0000) Subject: close ticket #66: port template dialog X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=e9f393a37f53d2715aa79d6e8662a333f2a81667;p=web%2Fkonrad%2Fsmoke.git close ticket #66: port template dialog git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@431 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/iface/msinterface.cpp b/src/iface/msinterface.cpp index 374efee..e26a6e0 100644 --- a/src/iface/msinterface.cpp +++ b/src/iface/msinterface.cpp @@ -195,3 +195,8 @@ void MSInterface::sslErrors(const QList&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); +} diff --git a/src/iface/msinterface.h b/src/iface/msinterface.h index 1afda98..fd2aacc 100644 --- a/src/iface/msinterface.h +++ b/src/iface/msinterface.h @@ -84,7 +84,9 @@ class MSInterface:public MInterface void setSessionId(QString sid){m_sessid=sid;} /**handles SSL errors*/ virtual void sslErrors(const QList&); - + /**force template store to update its templates*/ + void updateTemplates(); + private: QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey; mutable QListuserrights; diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 652d7d7..17b1bed 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -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) diff --git a/src/mwin/overview.h b/src/mwin/overview.h index 559c858..7aeda85 100644 --- a/src/mwin/overview.h +++ b/src/mwin/overview.h @@ -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; diff --git a/src/templates/templates.cpp b/src/templates/templates.cpp index 489b868..d58f243 100644 --- a/src/templates/templates.cpp +++ b/src/templates/templates.cpp @@ -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 MTemplateStore::allTemplates() diff --git a/wob/template.wolf b/wob/template.wolf index 59e4eab..694ba91 100644 --- a/wob/template.wolf +++ b/wob/template.wolf @@ -61,4 +61,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/www/inc/wext/template.php b/www/inc/wext/template.php index 5044ad2..6492645 100644 --- a/www/inc/wext/template.php +++ b/www/inc/wext/template.php @@ -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