template manager:
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 25 Oct 2010 19:29:55 +0000 (19:29 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 25 Oct 2010 19:29:55 +0000 (19:29 +0000)
* add save template option
* start on template editor for labels

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@613 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/overview.cpp
src/templates/templatedlg.cpp
src/templates/templatedlg.h
src/templates/templates.cpp
src/templates/templates.h
src/templates/templates.pri
src/templates/ticketedit.cpp [new file with mode: 0644]
src/templates/ticketedit.h [new file with mode: 0644]

index d5a4f04..e3c7858 100644 (file)
@@ -526,8 +526,8 @@ void MOverview::aclWindow()
 
 void MOverview::editTemplates()
 {
-       MTemplateEditor te(MSInterface::instance()->templateStore());
-       te.exec();
+       MTemplateEditor *te=new MTemplateEditor(MSInterface::instance()->templateStore());
+       te->show();
 }
 
 void MOverview::wizardMode()
index 641b834..5b14dbb 100644 (file)
 //
 
 #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>
 
@@ -87,6 +89,11 @@ MTemplateEditor::MTemplateEditor(MTemplateStore*s)
        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);
@@ -226,3 +233,95 @@ void MTemplateEditor::forceUpdate()
        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."));
+       
+}
index b4e7fcb..b5a7bc8 100644 (file)
@@ -52,6 +52,8 @@ class MTemplateEditor:public QDialog
                void addItem();
                void changeDescr(QStandardItem*);
                void forceUpdate();
+               void editItem();
+               void saveItem();
        private:
                MTemplateStore*store;
                QTreeView*tree;
index 41271f4..aeddc64 100644 (file)
@@ -75,6 +75,25 @@ MTemplate MTemplateStore::getTemplate(QString f)
        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
@@ -291,7 +310,7 @@ QString MTemplate::targetExtension()const
        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
@@ -305,6 +324,8 @@ 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;
 }
@@ -328,7 +349,7 @@ MTemplate::Types MTemplate::legalTypes(QString bn)
        if(bn=="ticket" || bn=="voucher")
                return LabelTemplate;
        if(bn=="bill" || bn=="eventsummary")
-               return OdfTemplate;
+               return OdfTemplateMask;
        if(bn=="scripts")
                return ZipTemplate;
        return UnknownTemplate;
index b6b52ee..aaf8ad6 100644 (file)
@@ -73,7 +73,7 @@ class MTemplate
                        /**ODF DataBase*/
                        OdbTemplate=0x10,
                        /**ODF template*/
-                       OdfTemplate=0xff,
+                       OdfTemplateMask=0xff,
                        /**Label template*/
                        LabelTemplate=0x100,
                        /**Script-Zip template*/
@@ -135,8 +135,14 @@ class MTemplateStore
                bool retrieveFile(QString,QString);
                
        public:
-               /**returns a specific template, opens a template choice dialog if necessary*/
-               MTemplate getTemplate(QString);
+               /**returns a specific template by its base name, opens a template choice dialog if necessary
+               \param base the base name of the template to retrieve (eg. "ticket" or "voucher")*/
+               MTemplate getTemplate(QString base);
+               /**returns a specific template by its full name, opens a template choice dialog if necessary
+               \param full the base name of the template to retrieve (eg. "ticket.xtt,1")*/
+               MTemplate getTemplateByFile(QString full);
+               
+               
                
        private:
                QString profileid;
index 9085cb3..5ef18a9 100644 (file)
@@ -4,7 +4,8 @@ HEADERS += \
        templates/office.h \
        templates/labeldlg.h \
        templates/templates.h \
-       templates/templatedlg.h
+       templates/templatedlg.h \
+       templates/ticketedit.h
 
 SOURCES += \
        templates/odtrender.cpp \
@@ -12,6 +13,7 @@ SOURCES += \
        templates/office.cpp \
        templates/labeldlg.cpp \
        templates/templates.cpp \
-       templates/templatedlg.cpp
+       templates/templatedlg.cpp \
+       templates/ticketedit.cpp
 
 INCLUDEPATH += ./templates
\ No newline at end of file
diff --git a/src/templates/ticketedit.cpp b/src/templates/ticketedit.cpp
new file mode 100644 (file)
index 0000000..fe0d37a
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// C++ Implementation: ticket template editor
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "ticketedit.h"
+
+MTicketEditor::MTicketEditor(QWidget* parent, Qt::WindowFlags f): QMainWindow(parent, f)
+{
+
+}
+
+void MTicketEditor::loadFile(QString )
+{
+
+}
+
+void MTicketEditor::openFile()
+{
+
+}
+
+void MTicketEditor::rerender()
+{
+
+}
diff --git a/src/templates/ticketedit.h b/src/templates/ticketedit.h
new file mode 100644 (file)
index 0000000..bf7bc8a
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// C++ Interface: ticket template editor
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_TICKETEDIT_H
+#define MAGICSMOKE_TICKETEDIT_H
+
+#include <QMainWindow>
+
+class MTicketEditor:public QMainWindow
+{
+       Q_OBJECT
+       public:
+               MTicketEditor(QWidget* parent = 0, Qt::WindowFlags f = 0);
+               
+       public slots:
+               void loadFile(QString);
+               void openFile();
+       private slots:
+               void rerender();
+       private:
+               
+};
+
+#endif