From 3ad02c6823e2b72e27d0ddf56a3ef862b1007ff7 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Tue, 27 Dec 2011 23:07:34 +0100 Subject: [PATCH] flags for templates --- src/iface/msinterface.cpp | 4 +++ src/templates/templatedlg.cpp | 50 ++++++++++++++++++++++++++++++++++++---- src/templates/templatedlg.h | 1 + src/templates/templates.cpp | 38 ++++++++++++++++++++++++++----- src/templates/templates.h | 11 +++++++- wob/transact/template.wolf | 8 ++++++ www/inc/wext/template.php | 16 +++++++++++++ 7 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/iface/msinterface.cpp b/src/iface/msinterface.cpp index ba9e43d..54bbd80 100644 --- a/src/iface/msinterface.cpp +++ b/src/iface/msinterface.cpp @@ -213,6 +213,10 @@ void MSInterface::updateTemplates() bool MSInterface::checkFlags(const QStringList& fl) const { + //shortcut for admins + if(userflags.contains("_admin") || userroles.contains("_admin")) + return true; + //check actual flags foreach(QString f,fl){ f=f.trimmed(); if(f.isEmpty())continue; diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index ea0f786..2997212 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -12,6 +12,7 @@ #include "templatedlg.h" #include "ticketedit.h" +#include "flagedit.h" #include #include @@ -60,7 +61,7 @@ MTemplate MTemplateChoice::choice()const QString fn=box->itemData(box->currentIndex()).toString(); QSettings set; set.beginGroup(sgroup+"/"+fn); - return MTemplate(cachedir+"/"+fn, set.value("checksum").toString(), set.value("description").toString()); + return MTemplate(cachedir+"/"+fn, set.value("checksum").toString(), set.value("description").toString(), set.value("flags").toString()); } @@ -87,12 +88,16 @@ MTemplateEditor::MTemplateEditor(MTemplateStore*s) hl->addLayout(vl2=new QVBoxLayout); vl2->addWidget(p=new QPushButton(tr("Update Now"))); connect(p,SIGNAL(clicked()),this,SLOT(forceUpdate())); + vl2->addSpacing(20); vl2->addWidget(p=new QPushButton(tr("Add Variant"))); connect(p,SIGNAL(clicked()),this,SLOT(addItem())); vl2->addWidget(p=new QPushButton(tr("Delete Variant"))); connect(p,SIGNAL(clicked()),this,SLOT(deleteItem())); vl2->addSpacing(20); - vl2->addWidget(p=new QPushButton(tr("Save Template"))); + vl2->addWidget(p=new QPushButton(tr("Change Flags"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeFlags())); + vl2->addSpacing(20); + vl2->addWidget(p=new QPushButton(tr("Save Template..."))); connect(p,SIGNAL(clicked()),this,SLOT(saveItem())); vl2->addWidget(p=new QPushButton(tr("Edit Template"))); connect(p,SIGNAL(clicked()),this,SLOT(editItem())); @@ -115,8 +120,8 @@ void MTemplateEditor::updateView() //basic cleanup nochange=true; model->clear(); - model->insertColumns(0,3); - model->setHorizontalHeaderLabels(QStringList()<insertColumns(0,4); + model->setHorizontalHeaderLabels(QStringList() <sub=hier[base[i]]; model->insertRows(0,sub.size(),idx); - model->insertColumns(0,3,idx); + model->insertColumns(0,4,idx); for(int j=0;jindex(j,0,idx); model->setData(idx2,sub[j].fileName()+" ("+sub[j].variantID()+")"); @@ -155,6 +160,8 @@ void MTemplateEditor::updateView() model->setData(model->index(j,1,idx),sub[j].description()); model->setData(model->index(j,2,idx),sub[j].checksum()); model->itemFromIndex(model->index(j,2,idx))->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + model->setData(model->index(j,3,idx),sub[j].flags()); + model->itemFromIndex(model->index(j,3,idx))->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); } } //expand all @@ -162,6 +169,7 @@ void MTemplateEditor::updateView() tree->resizeColumnToContents(0); tree->resizeColumnToContents(1); tree->resizeColumnToContents(2); + tree->resizeColumnToContents(3); nochange=false; } void MTemplateEditor::deleteItem() @@ -312,3 +320,35 @@ void MTemplateEditor::saveItem() QMessageBox::warning(this,tr("Error"),tr("Unable to save the template file.")); } + +void MTemplateEditor::changeFlags() +{ + //get selection + QModelIndex idx=tree->currentIndex(); + if(!idx.isValid())return; + QModelIndex pidx=idx.parent(); + QModelIndex bidx=model->index(idx.row(),0,pidx); + QString base=model->data(bidx,BASEROLE).toString(); + if(base=="")return; + //query file name + QString fn=model->data(bidx,NAMEROLE).toString(); + if(fn=="")return; + //get it + MTemplate tmp=store->getTemplateByFile(fn); + if(tmp.cacheFileName()==""){ + QMessageBox::warning(this,tr("Warning"),tr("Ooops. Lost the template file, cannot alter it.")); + return; + } + //edit flags + MFlagEditor fe(this,tmp.flags(),tr("Edit flags of template '%1'").arg(fn)); + if(fe.exec()!=QDialog::Accepted)return; + //send to server + QString nflags=fe.currentFlags(); + if(!store->setTemplateFlags(fn,nflags)){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to send updated flags to server.")); + return; + } + //update locally + bidx=model->index(idx.row(),3,pidx); + model->setData(bidx,nflags); +} diff --git a/src/templates/templatedlg.h b/src/templates/templatedlg.h index 22aac15..640689d 100644 --- a/src/templates/templatedlg.h +++ b/src/templates/templatedlg.h @@ -52,6 +52,7 @@ class MTemplateEditor:public QDialog void deleteItem(); void addItem(); void changeDescr(QStandardItem*); + void changeFlags(); void forceUpdate(); void editItem(); void saveItem(); diff --git a/src/templates/templates.cpp b/src/templates/templates.cpp index c7655a6..5f1f1bb 100644 --- a/src/templates/templates.cpp +++ b/src/templates/templates.cpp @@ -62,13 +62,17 @@ MTemplate MTemplateStore::getTemplate(QString f) //get directory QStringList dir=set.childGroups(); QStringList tdir; + MSInterface*ifc=MSInterface::instance(); for(int i=0;icheckFlags(set.value(dir[i]+"/flags").toString())) + tdir< '%s'",n.toAscii().data(),o.toAscii().data(),flags.toAscii().data()); + if(o==flags)return true; + //send to server + MTSetTemplateFlags std=req->querySetTemplateFlags(n,flags); + if(std.hasError()) + return false; + //update internal description + set.setValue("flags",flags); + //return success + return true; +} + QList MTemplateStore::allTemplates() { updateTemplates(false); @@ -260,7 +285,7 @@ QList MTemplateStore::allTemplates() QStringList names=set.childGroups(); QList ret; for(int i=0;i MTemplateStore::allTemplates() MTemplate::MTemplate(){} MTemplate::MTemplate(QString fn){m_fname=fn;} -MTemplate::MTemplate(QString fn,QString chk,QString dsc){m_fname=fn;m_checksum=chk;m_descr=dsc;} +MTemplate::MTemplate(QString fn,QString chk,QString dsc,QString flg) +{m_fname=fn;m_checksum=chk;m_descr=dsc;m_flags=flg;} QString MTemplate::cacheFileName()const{return m_fname;} QString MTemplate::fileName()const diff --git a/src/templates/templates.h b/src/templates/templates.h index 7ee685b..02bcece 100644 --- a/src/templates/templates.h +++ b/src/templates/templates.h @@ -61,6 +61,9 @@ class MTemplate /**returns whether this is a label template*/ bool isLabel()const; + ///returns the flags of this template + QString flags()const{return m_flags;} + /**template type; currently only ODF and Labels are known*/ enum Type{ /**uninitialized or unknown label type*/ @@ -103,10 +106,11 @@ class MTemplate \param fn physical file name of the template \param chk server side check sum of the template \param dsc description of the template + \param flg flags of the template */ - MTemplate(QString fn,QString chk,QString dsc); + MTemplate(QString fn,QString chk,QString dsc,QString flg); private: - QString m_fname,m_checksum,m_descr; + QString m_fname,m_checksum,m_descr,m_flags; }; Q_DECLARE_OPERATORS_FOR_FLAGS(MTemplate::Types) @@ -125,6 +129,9 @@ class MTemplateStore /**stores a new description for a template*/ bool setTemplateDescription(QString templatename,QString description); + ///stores a change of flags for a template + bool setTemplateFlags(QString templatename,QString flags); + /**deletes a template (requires full name), used by MTemplateEditor*/ bool deleteTemplate(QString); diff --git a/wob/transact/template.wolf b/wob/transact/template.wolf index 5bdb780..31cdb87 100644 --- a/wob/transact/template.wolf +++ b/wob/transact/template.wolf @@ -53,4 +53,12 @@ + + Changes the flags of the template. + + + + + + diff --git a/www/inc/wext/template.php b/www/inc/wext/template.php index 05e5850..46b3dc0 100644 --- a/www/inc/wext/template.php +++ b/www/inc/wext/template.php @@ -63,6 +63,22 @@ class WOTemplate extends WOTemplateAbstract //delete $tm->deleteFromDb(); } + + ///called by the SetTemplateFlags transaction + static public function changeFlags($trans) + { + //find it + $tm=WTtemplate::getFromDB($trans->getfilename()); + if($tm===false){ + $trans->abortWithError(tr("No such template.")); + return; + } + //set + $tm->flags=$trans->getflags(); + //delete + if(!$tm->update()) + $trans->abortWithError(tr("Unable to set flags - DB error.")); + } }; ?> \ No newline at end of file -- 1.7.2.5