basic template retrieval
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 14:52:52 +0000 (14:52 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 14:52:52 +0000 (14:52 +0000)
ticket/voucher printing
minor fixups in config dialog

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

14 files changed:
src/dialogs/configdialog.cpp
src/templates/templates.cpp
src/templates/ticketrender.cpp
src/wbase/WTransaction.cpp
src/wext/MOTicket.cpp [new file with mode: 0644]
src/wext/MOTicket.h
src/wext/wext.pri
wob/basics.wolf
wob/event.wolf
wob/magicsmoke.wolf
wob/template.wolf [new file with mode: 0644]
woc/qtout.cpp
www/inc/wext/autoload.php
www/inc/wext/template.php [new file with mode: 0644]

index 3b827b0..431f2dd 100644 (file)
@@ -114,6 +114,7 @@ MConfigDialog::MConfigDialog()
        proxypass->setEchoMode(QLineEdit::Password);
        connect(useproxy,SIGNAL(toggled(bool)),proxyuser,SLOT(setEnabled(bool)));
        connect(useproxy,SIGNAL(toggled(bool)),proxypass,SLOT(setEnabled(bool)));
+       gl->setRowStretch(++lctr,10);
        
        tab->addTab(w=new QWidget,tr("Authentication"));
        w->setLayout(gl=new QGridLayout);
@@ -145,6 +146,8 @@ MConfigDialog::MConfigDialog()
        hl->addWidget(pb=new QPushButton(tr("Probe Server")));
        connect(pb,SIGNAL(clicked()),this,SLOT(serverProbe()));
        
+       setSizeGripEnabled(true);
+       
        initProfiles();
        loadProfile();
 }
index e4b0646..489b868 100644 (file)
@@ -75,14 +75,8 @@ MTemplate MTemplateStore::getTemplate(QString f)
        else return MTemplate();
 }
 
-struct STemp{
-       STemp(QString f,QString c,QString d){fname=f;checksum=c;descr=d;}
-       STemp(){}
-       QString fname,checksum,descr;
-};
-
 void MTemplateStore::updateTemplates(bool force)
-{/*TODO
+{
        //basics
        QString dname=req->dataDir()+"/templates/";
        QSettings set;
@@ -95,9 +89,11 @@ void MTemplateStore::updateTemplates(bool force)
        
        //get local info
        QStringList files=set.childGroups();
-       QMap<QString,STemp> fmap;
+       QMap<QString,MOTemplateInfo> fmap;
        for(int i=0;i<files.size();i++){
-               STemp t(files[i],set.value(files[i]+"/checksum").toString(), set.value(files[i]+"/description").toString());
+               MOTemplateInfo t;
+               t.setfilename(files[i]);
+               t.sethash(set.value(files[i]+"/checksum").toString()); t.setdescription(set.value(files[i]+"/description").toString());
                fmap.insert(files[i],t);
        }
        
@@ -108,24 +104,15 @@ void MTemplateStore::updateTemplates(bool force)
        progress.setValue(0);
        
        //get remote info, assume it is still valid if unable to retrieve it
-       if(!req->request("gettemplatelist",""))return;
-       if(req->responseStatus()!=MWebRequest::Ok)return;
+       MTGetTemplateList gtl=req->queryGetTemplateList();
+       if(gtl.hasError())return;
        //remember update time
        set.setValue("lastupdate",QDateTime::currentDateTime().toTime_t());
-       //parse info
-       QDomDocument doc;
-       if(!doc.setContent(req->responseBody()))return;
        //scan and create new list
-       QDomNodeList nl=doc.elementsByTagName("Template");
-       QMap<QString,STemp>nfmap;
-       for(int i=0;i<nl.size();i++){
-               QDomElement el=nl.at(i).toElement();
-               if(el.isNull())continue;
-               QString f=el.attribute("name","");
-               QString h=el.attribute("hash","");
-               QString d=el.text();
-               if(f=="")continue;
-               nfmap.insert(f,STemp(f,h,d));
+       QList<MOTemplateInfo>nf=gtl.gettemplates();
+       QMap<QString,MOTemplateInfo>nfmap;
+       for(int i=0;i<nf.size();i++){
+               nfmap.insert(nf[i].filename(),nf[i]);
        }
        
        //check old list for removed or changed entries; remove them
@@ -133,7 +120,7 @@ void MTemplateStore::updateTemplates(bool force)
                if(!nfmap.contains(files[i]))
                        fmap.remove(files[i]);
                else
-               if(nfmap[files[i]].checksum != fmap[files[i]].checksum)
+               if(nfmap[files[i]].hash() != fmap[files[i]].hash())
                        fmap.remove(files[i]);
        }
        files=fmap.keys();
@@ -149,7 +136,7 @@ void MTemplateStore::updateTemplates(bool force)
                                fmap.insert(nfiles[i],nfmap[nfiles[i]]);
                }else{
                        //file is already up to date, still copy the current description
-                       fmap[nfiles[i]].descr=nfmap[nfiles[i]].descr;
+                       fmap[nfiles[i]].setdescription(nfmap[nfiles[i]].description());
                }
        }
        files=fmap.keys();
@@ -165,23 +152,22 @@ void MTemplateStore::updateTemplates(bool force)
        set.remove("");
        //settings: create new entries
        for(int i=0;i<files.size();i++){
-               STemp s=fmap[files[i]];
-               set.setValue(s.fname+"/checksum",s.checksum);
-               set.setValue(s.fname+"/description",s.descr);
-       }*/
+               MOTemplateInfo s=fmap[files[i]];
+               set.setValue(s.filename()+"/checksum",s.hash().value());
+               set.setValue(s.filename()+"/description",s.description().value());
+       }
 }
 
 bool MTemplateStore::retrieveFile(QString dname,QString fn)
-{/*TODO
+{
        //request
-       if(!req->request("gettemplate",fn.toUtf8()))return false;
-       if(req->responseStatus()!=MWebRequest::Ok)return false;
+       MTGetTemplate gt=req->queryGetTemplate(fn);
+       if(gt.hasError())return false;
        //store
        QFile f(dname+"/"+fn);
        if(!f.open(QIODevice::WriteOnly|QIODevice::Truncate))return false;
-       f.write(req->responseBody());
+       f.write(gt.gettemplatefile().value().content());
        return true;
-       */return false;
 }
 
 bool MTemplateStore::setTemplate(QString n,QString f)
index 7de714b..fd4d4f0 100644 (file)
@@ -525,11 +525,11 @@ class MTicketLabel:public MLabel
 QString MTicketLabel::getVariable(QString var)const
 {
        if(var=="TICKETID"||var=="BARCODE")return tick.ticketid();
-       /*if(var=="PRICE")return tick.priceString();
+       if(var=="PRICE")return tick.priceString();
        if(var=="DATETIME")return tick.event().startTimeString();
        if(var=="ROOM")return tick.event().room();
        if(var=="TITLE")return tick.event().title();
-       if(var=="ARTIST")return tick.event().artist().value().name();*/
+       if(var=="ARTIST")return tick.event().artist().value().name();
        return "";
 }
 
@@ -551,8 +551,8 @@ class MVoucherLabel:public MLabel
 QString MVoucherLabel::getVariable(QString var)const
 {
        if(var=="VOUCHERID"||var=="BARCODE")return vouc.voucherid();
-       /*if(var=="PRICE")return vouc.priceString();
-       if(var=="VALUE")return vouc.valueString();*/
+       if(var=="PRICE")return vouc.priceString();
+       if(var=="VALUE")return vouc.valueString();
        return "";
 }
 
index 22d5fc6..8005179 100644 (file)
@@ -179,8 +179,8 @@ void WTransaction::webTimeout()
 
 void WTransaction::webReady(int i,bool e)
 {
-       qDebug("finished req %i",i);
        if(i!=m_httpid)return;
+       qDebug("finished req %i",i);
        if(e){
                m_stage=Error;
                m_errtype="_web";
diff --git a/src/wext/MOTicket.cpp b/src/wext/MOTicket.cpp
new file mode 100644 (file)
index 0000000..990d322
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// C++ Implementation: MOTicket
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "MOTicket.h"
+#include "msinterface.h"
+
+MOEvent MOTicket::event()const
+{
+       //if I am valid...
+       if(!ticketid().isNull() && !eventid().isNull())
+               //...and the event is not...
+               if(m_event.eventid().isNull()){
+                       //...then retrieve the event
+                       MTGetEvent ge=req->queryGetEvent(eventid());
+                       if(!ge.hasError())
+                       m_event=ge.getevent();
+               }
+       //return whatever we have by now
+       return m_event;
+}
index 175ad2d..0332fab 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "MOTicketAbstract.h"
 #include "misc.h"
+#include "MOEvent.h"
 
 class MOTicket:public MOTicketAbstract
 {
@@ -28,6 +29,12 @@ class MOTicket:public MOTicketAbstract
                
                /**returns the ticket status as localized string*/
                QString statusString()const{return TicketState2locstr(status());}
+               
+               /**returns the event that this ticket belongs to - does a roundtrip to the database the first time this is called!*/
+               MOEvent event()const;
+       private:
+               //this must be mutable, since event() is semantically and technically const
+               mutable MOEvent m_event;
 };
 
 #endif
index 6ab44cb..b47c22b 100644 (file)
@@ -12,5 +12,6 @@ HEADERS += \
 SOURCES += \
        wext/MOCustomerInfo.cpp \
        wext/MOOrder.cpp \
+       wext/MOTicket.cpp \
        wext/MOAddress.cpp \
        wext/MOEvent.cpp
\ No newline at end of file
index 90a3e41..30a7715 100644 (file)
        </Table>
        
        
-       <Table name="template" backup="yes">
-               <Column name="filename" type="string" primarykey="yes"/>
-               <Column name="description" type="string"/>
-               <Column name="content" type="blob"/>
-               <Column name="hash" type="string:32" notnull="yes"/> <!--md5-->
-               <Column name="dolog" type="bool" default="0"/>
-               <Column name="flags" type="string"/>
-       </Table>
-       
        <Transaction name="Backup">
                <Doc>This transaction allows to make a complete database backup. The backup file is replayed into the database via the admin.php interface.</Doc>
                <Input/>
index 26d513e..0c474d7 100644 (file)
                <Input>
                        <Var name="eventid" type="int"/>
                </Input>
-               <Call lang="php" method="$this->setevent(WOEvent::fromTableevent(WTEvent::getFromDB($this->geteventid())));"/>
+               <Call lang="php" method="$this->setevent(WOEvent::fromTableevent(WTevent::getFromDB($this->geteventid())));"/>
                <Output>
                        <Var name="event" type="Event"/>
                </Output>
index 232f398..d1304fc 100644 (file)
@@ -44,5 +44,6 @@
        <Include file="event.wolf"/>
        <Include file="order.wolf"/>
        <Include file="cart.wolf"/>
+       <Include file="template.wolf"/>
        <Include file="audit.wolf"/>
 </Wolf>
\ No newline at end of file
diff --git a/wob/template.wolf b/wob/template.wolf
new file mode 100644 (file)
index 0000000..59e4eab
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Template MagicSmoke WOLF
+  - template tables
+  -
+  - (c) Konrad Rosenbaum, 2009
+  - this file is protected under the GNU AGPLv3 or at your option any newer
+  - see COPYING.AGPL for details
+  -->
+<Wolf>
+       <Table name="template" backup="yes">
+               <Column name="filename" type="string" primarykey="yes"/>
+               <Column name="description" type="string"/>
+               <Column name="content" type="blob"/>
+               <Column name="hash" type="string:32" notnull="yes"/> <!--md5-->
+               <Column name="dolog" type="bool" default="0"/>
+               <Column name="flags" type="string"/>
+       </Table>
+       
+       <Class name="Template">
+               <Abstract lang="php"/>
+               <Property name="filename" type="astring"/>
+               <Property name="description" type="string"/>
+               <Property name="content" type="blob"/>
+               <Property name="hash" type="astring"/> <!--md5-->
+               <Property name="dolog" type="bool"/>
+               <Property name="flags" type="string"/>
+               <Mapping table="template">
+                       <Map column="filename"/>
+                       <Map column="description"/>
+                       <Map column="content"/>
+                       <Map column="hash"/>
+                       <Map column="dolog"/>
+                       <Map column="flags"/>
+               </Mapping>
+       </Class>
+       
+       <Class name="TemplateInfo">
+               <Property name="filename" type="astring"/>
+               <Property name="description" type="string"/>
+               <Property name="hash" type="astring"/> <!--md5-->
+               <Mapping table="template">
+                       <Map column="filename"/>
+                       <Map column="description"/>
+                       <Map column="hash"/>
+               </Mapping>
+       </Class>
+       
+       <Transaction name="GetTemplateList">
+               <Call lang="php" method="WOTemplate::getList($this);"/>
+               <Output>
+                       <Var name="templates" type="List:TemplateInfo"/>
+               </Output>
+       </Transaction>
+       
+       <Transaction name="GetTemplate">
+               <Input>
+                       <Var name="filename" type="astring"/>
+               </Input>
+               <Call lang="php" method="WOTemplate::getFile($this);"/>
+               <Output>
+                       <Var name="templatefile" type="Template"/>
+               </Output>
+       </Transaction>
+</Wolf>
index 1d9bbf1..3be218d 100644 (file)
@@ -456,12 +456,12 @@ void WocQtClientOut::classSerializers(const WocClass&cls,MFile&hdr,MFile&src,QSt
                                }else
                                if(cls.propertyIsString(prop)){
                                        scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
-                                       scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+"));\n";
+                                       scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+".value()));\n";
                                        scd+="\t\tr.appendChild(el);\n";
                                }else
                                if(cls.propertyIsBlob(prop)){
                                        scd+="\t\tQDomElement el=doc.createElement(\""+prop+"\");\n";
-                                       scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+".toBase64()));\n";
+                                       scd+="\t\tel.appendChild(doc.createTextNode(mp_"+prop+".value().toBase64()));\n";
                                        scd+="\t\tr.appendChild(el);\n";
                                }else{
                                        qDebug("Error: cannot generate serializer for class %s property %s.",cls.name().toAscii().data(),prop.toAscii().data());
index ae21d53..22a289d 100644 (file)
@@ -15,4 +15,5 @@ $AUTOCLASS["WORole"]="inc/wext/role.php";
 $AUTOCLASS["WOOrderInfo"]="inc/wext/order.php";
 $AUTOCLASS["WOOrder"]="inc/wext/order.php";
 $AUTOCLASS["WOTicket"]="inc/wext/ticket.php";
+$AUTOCLASS["WOTemplate"]="inc/wext/template.php";
 ?>
\ No newline at end of file
diff --git a/www/inc/wext/template.php b/www/inc/wext/template.php
new file mode 100644 (file)
index 0000000..5044ad2
--- /dev/null
@@ -0,0 +1,31 @@
+<?
+//
+// PHP Implementation: template
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class WOTemplate extends WOTemplateAbstract
+{
+       /**called by the TemplateList transaction*/
+       static public function getList($trans)
+       {
+               //TODO: filter by flags
+               $trans->settemplates(WOTemplateInfo::fromTableArraytemplate(WTtemplate::selectFromDB()));
+       }
+       
+       /**called by the GetTemplate transaction*/
+       static public function getFile($trans)
+       {
+               //TODO: filter by flags
+               $trans->settemplatefile(WOTemplate::fromTabletemplate(WTtemplate::getFromDB($trans->getfilename())));
+       }
+};
+
+?>
\ No newline at end of file