//
#include "templatedlg.h"
+#include "ticketedit.h"
-#include <QComboBox>
#include <QBoxLayout>
+#include <QComboBox>
+#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
+#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>
-#include <QLabel>
#include <QStandardItemModel>
#include <QTreeView>
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")));
+ connect(p,SIGNAL(clicked()),this,SLOT(saveItem()));
+ vl2->addWidget(p=new QPushButton(tr("Edit Template")));
+ connect(p,SIGNAL(clicked()),this,SLOT(editItem()));
vl2->addStretch(1);
vl->addSpacing(15);
store->updateTemplates(true);
updateView();
}
+
+void MTemplateEditor::editItem()
+{
+ //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();
+ qDebug()<<"editing base"<<base<<"fn"<<fn;
+ //check extension
+ if(fn!=""){
+ MTemplate tmp=store->getTemplateByFile(fn);
+ MTemplate::Type tp=tmp.type();
+ if(tp&MTemplate::OdfTemplateMask){
+ QMessageBox::warning(this,"Sorry","Sorry, no ODF editor yet.");
+ }else
+ if(tp==MTemplate::LabelTemplate){
+ MTicketEditor *ed=new MTicketEditor(this);
+ ed->loadFile(tmp.cacheFileName());
+ ed->show();
+ }else
+ if(tp==MTemplate::ZipTemplate){
+ QMessageBox::warning(this,"Sorry","Sorry, no ZIP selection");
+ }else{
+ QMessageBox::warning(this,tr("Warning"),tr("Unknown template type, cannot edit it."));
+ }
+ }else{
+ }
+ /*QString ext=QFileInfo(fn).completeSuffix();
+ if(!MTemplate::legalSuffixes(base).contains(ext)){
+ QMessageBox::warning(this,tr("Warning"),tr("Files with this extension (%1) are not legal for this template.").arg(ext));
+ return;
+ }
+ //get new variant name
+ QStringList lst;
+ for(int i=0;i<model->rowCount(pidx);i++){
+ QStringList f=model->data(model->index(i,0,pidx),NAMEROLE).toString().split(",");
+ if(f.size()>1)
+ lst<<f[1];
+ }
+ QString nvar;
+ for(int i=0;i<1000000000;i++){
+ nvar=QString::number(i,16).toLower();
+ if(!lst.contains(nvar))break;
+ }
+ //send up
+ if(store->setTemplate(base+"."+ext+","+nvar,fn))
+ forceUpdate();
+ else
+ QMessageBox::warning(this,tr("Warning"),tr("Unable to upload file."));*/
+}
+
+void MTemplateEditor::saveItem()
+{
+ //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);
+ fn=tmp.cacheFileName();
+ if(fn==""){
+ QMessageBox::warning(this,tr("Warning"),tr("Ooops. Lost the template file, cannot store it."));
+ return;
+ }
+ //get file name
+ QString nfn;
+ {
+ QFileDialog fd(this,tr("Save template as..."));
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.setDefaultSuffix(tmp.extension());
+ fd.selectFile(tmp.baseName());
+ if(fd.exec()!=QDialog::Accepted)
+ return;
+ nfn=fd.selectedFiles().at(0);
+ if(nfn=="")return;
+ }
+ //store it
+ if(!QFile::copy(fn,nfn))
+ QMessageBox::warning(this,tr("Error"),tr("Unable to save the template file."));
+
+}
else return MTemplate();
}
+MTemplate MTemplateStore::getTemplateByFile(QString f)
+{
+ //syntax check
+ f=f.toLower();
+ QRegExp fregexp("[a-z0-9_\\.,]+");
+ if(!fregexp.exactMatch(f))return MTemplate();
+ //update directory (no force)
+ updateTemplates(false);
+ //find files matching the pattern
+ //basics
+ QString dname=req->dataDir()+"/templates/";
+ QSettings set;
+ set.beginGroup("templates/"+profileid);
+ //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());
+}
+
void MTemplateStore::updateTemplates(bool force)
{
//basics
return "";
}
-bool MTemplate::isOdf()const{return (type()&OdfTemplate)!=0;}
+bool MTemplate::isOdf()const{return (type()&OdfTemplateMask)!=0;}
bool MTemplate::isLabel()const{return type()==LabelTemplate;}
MTemplate::Type MTemplate::type()const
if(x=="odbt")return OdbTemplate;
//label?
if(x=="xtt")return LabelTemplate;
+ //script?
+ if(x=="zip")return ZipTemplate;
//hmm, unknown one
return UnknownTemplate;
}
if(bn=="ticket" || bn=="voucher")
return LabelTemplate;
if(bn=="bill" || bn=="eventsummary")
- return OdfTemplate;
+ return OdfTemplateMask;
if(bn=="scripts")
return ZipTemplate;
return UnknownTemplate;