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;
#include "templatedlg.h"
#include "ticketedit.h"
+#include "flagedit.h"
#include <QBoxLayout>
#include <QComboBox>
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());
}
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()));
//basic cleanup
nochange=true;
model->clear();
- model->insertColumns(0,3);
- model->setHorizontalHeaderLabels(QStringList()<<tr("Template/Variant")<<tr("Description")<<tr("Checksum"));
+ model->insertColumns(0,4);
+ model->setHorizontalHeaderLabels(QStringList() <<tr("Template/Variant") <<tr("Description") <<tr("Checksum") <<tr("Flags"));
//get base names
QStringList base=MTemplate::legalBaseNames();
//get all templates, sort them into buckets
if(hier[base[i]].size()<1)continue;
QList<MTemplate>sub=hier[base[i]];
model->insertRows(0,sub.size(),idx);
- model->insertColumns(0,3,idx);
+ model->insertColumns(0,4,idx);
for(int j=0;j<sub.size();j++){
QModelIndex idx2=model->index(j,0,idx);
model->setData(idx2,sub[j].fileName()+" ("+sub[j].variantID()+")");
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
tree->resizeColumnToContents(0);
tree->resizeColumnToContents(1);
tree->resizeColumnToContents(2);
+ tree->resizeColumnToContents(3);
nochange=false;
}
void MTemplateEditor::deleteItem()
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);
+}
void deleteItem();
void addItem();
void changeDescr(QStandardItem*);
+ void changeFlags();
void forceUpdate();
void editItem();
void saveItem();
//get directory
QStringList dir=set.childGroups();
QStringList tdir;
+ MSInterface*ifc=MSInterface::instance();
for(int i=0;i<dir.size();i++){
+ //filter by base name
if(dir[i].split(".")[0].startsWith(f,Qt::CaseInsensitive))
- tdir<<dir[i];
+ //filter by flags
+ if(ifc->checkFlags(set.value(dir[i]+"/flags").toString()))
+ tdir<<dir[i];
}
//check dir size
if(tdir.size()==0)return MTemplate();
- if(tdir.size()==1)return MTemplate(dname+"/"+tdir[0], set.value(tdir[0]+"/checksum").toString(), set.value(tdir[0]+"/description").toString());
+ if(tdir.size()==1)return MTemplate(dname+"/"+tdir[0], set.value(tdir[0]+"/checksum").toString(), set.value(tdir[0]+"/description").toString(), set.value(tdir[0]+"/flags").toString());
//hmm, more than one choice
MTemplateChoice c(dname,f,tdir,"templates/"+profileid);
if(c.exec()==QDialog::Accepted)return c.choice();
//check directory
if(!set.childGroups().contains(f))return MTemplate();
//return if found
- return MTemplate(dname+"/"+f, set.value(f+"/checksum").toString(), set.value(f+"/description").toString());
+ return MTemplate(dname+"/"+f, set.value(f+"/checksum").toString(), set.value(f+"/description").toString(), set.value(f+"/flags").toString());
}
void MTemplateStore::updateTemplates(bool force)
MOTemplateInfo t;
t.setfilename(files[i]);
t.sethash(set.value(files[i]+"/checksum").toString()); t.setdescription(set.value(files[i]+"/description").toString());
+ t.setflags(set.value(files[i]+"/flags").toString());
fmap.insert(files[i],t);
}
if(retrieveFile(dname,nfiles[i]))
fmap.insert(nfiles[i],nfmap[nfiles[i]]);
}else{
- //file is already up to date, still copy the current description
+ //file is already up to date, still copy the current description and flags
fmap[nfiles[i]].setdescription(nfmap[nfiles[i]].description());
+ fmap[nfiles[i]].setflags(nfmap[nfiles[i]].flags());
}
}
files=fmap.keys();
MOTemplateInfo s=fmap[files[i]];
set.setValue(s.filename()+"/checksum",s.hash().value());
set.setValue(s.filename()+"/description",s.description().value());
+ set.setValue(s.filename()+"/flags",s.flags().value());
}
}
return true;
}
+bool MTemplateStore::setTemplateFlags(QString n, QString flags)
+{
+ //check that we have a real change
+ QSettings set;
+ set.beginGroup("templates/"+profileid+"/"+n);
+ QString o=set.value("flags").toString();
+ qDebug("setting %s '%s' -> '%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<MTemplate> MTemplateStore::allTemplates()
{
updateTemplates(false);
QStringList names=set.childGroups();
QList<MTemplate> ret;
for(int i=0;i<names.size();i++)
- ret.append(MTemplate(dname+"/"+names[i],set.value(names[i]+"/checksum").toString(),set.value(names[i]+"/description").toString()));
+ ret.append(MTemplate(dname+"/"+names[i], set.value(names[i]+"/checksum").toString(), set.value(names[i]+"/description").toString(), set.value(names[i]+"/flags").toString()));
return ret;
}
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
/**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*/
\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)
/**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);
</Input>
<Call lang="php" method="WOTemplate::deleteTemplate($this);"/>
</Transaction>
+ <Transaction name="SetTemplateFlags">
+ <Doc>Changes the flags of the template.</Doc>
+ <Input>
+ <Var name="filename" type="astring"/>
+ <Var name="flags" type="astring"/>
+ </Input>
+ <Call lang="php" method="WOTemplate::changeFlags($this);"/>
+ </Transaction>
</Wolf>
//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