configuration for print@home, partially functional
authorKonrad Rosenbaum <konrad@silmor.de>
Sun, 18 Dec 2016 19:32:53 +0000 (20:32 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Sun, 18 Dec 2016 19:32:53 +0000 (20:32 +0100)
Change-Id: Ib738eaa2c11f68671704c29a018cecf09ed917db

14 files changed:
iface/templates/templates.h
iface/wext/MOKeyValuePair [new file with mode: 0644]
iface/wext/keyvalue.h [new file with mode: 0644]
iface/wext/wext.pri
printathome/clientcfg.cpp [moved from printathome/client.cpp with 99% similarity]
printathome/clientcfg.h [moved from printathome/client.h with 100% similarity]
printathome/pah.cpp
printathome/pah.h
printathome/printathome.pro
printathome/servercfg.cpp [new file with mode: 0644]
printathome/servercfg.h [new file with mode: 0644]
wob/classes/basics.wolf
wob/transact/order.wolf
www/inc/wext/order.php

index b9c0a7b..9e3f410 100644 (file)
@@ -167,9 +167,6 @@ class MSIFACE_EXPORT MTemplateStore
                /**updates the template directory, does not do anything if force==false and the last update was less than 5min ago*/
                void updateTemplates(bool force);
                
-               /**returns all templates (for MTemplateEditor)*/
-               QList<MTemplate> allTemplates();
-               
        private:
                /**unused, just here to remove it from accessability*/
                MTemplateStore()=delete;
@@ -187,7 +184,8 @@ class MSIFACE_EXPORT MTemplateStore
                \param full the base name of the template to retrieve (eg. "ticket.xtt,1")*/
                MTemplate getTemplateByFile(QString full);
                
-               
+               /**returns all templates (for MTemplateEditor)*/
+               QList<MTemplate> allTemplates();
                
        private:
                QString profileid;
diff --git a/iface/wext/MOKeyValuePair b/iface/wext/MOKeyValuePair
new file mode 100644 (file)
index 0000000..a7ca73b
--- /dev/null
@@ -0,0 +1 @@
+#include"keyvalue.h"
diff --git a/iface/wext/keyvalue.h b/iface/wext/keyvalue.h
new file mode 100644 (file)
index 0000000..f294ff2
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// C++ Interface: unabstract
+//
+// Description: removes abstract flag from classes that only need to be abstract in PHP
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2009-2011
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_MOORDER_H
+#define MAGICSMOKE_MOORDER_H
+
+#include "MOKeyValuePairAbstract"
+#include "misc.h"
+
+#include <TimeStamp>
+
+#ifndef MSIFACE_EXPORT
+#define MSIFACE_EXPORT Q_DECL_IMPORT
+#endif
+
+
+/**this class represents a key value pair or part of a map/dictionary.*/
+class MSIFACE_EXPORT MOKeyValuePair:public MOKeyValuePairAbstract
+{
+       Q_GADGET
+       WOBJECT(MOKeyValuePair)
+public:
+       MOKeyValuePair(QString k,QString v){setkey(k);setvalue(v);setisnull(false);}
+       MOKeyValuePair(QString k,nullptr_t){setkey(k);setisnull(true);}
+       
+       inline operator QPair<QString,QString> ()
+       {
+               return QPair<QString,QString>(key(),value());
+       }
+
+};
+
+
+
+Q_DECLARE_METATYPE(MOKeyValuePair)
+Q_DECLARE_METATYPE(QList<MOKeyValuePair>)
+Q_DECLARE_METATYPE(Nullable<MOKeyValuePair>)
+
+#include <QPair>
+#include <QMap>
+
+inline
+QMap<QString,QString>& mergeToMap(QMap<QString,QString>&map, const QList<MOKeyValuePair>pl)
+{
+       for(auto p:pl)
+               if(p.isnull())
+                       map.remove(p.key());
+               else
+                       map.insert(p.key(),p.value());
+       return map;
+}
+
+inline
+QMap<QString,QString> toMap(const QList<MOKeyValuePair>pl)
+{
+       QMap<QString,QString>map;
+       return mergeToMap(map,pl);
+}
+
+#endif
index f9f30b6..fc013be 100644 (file)
@@ -9,7 +9,8 @@ HEADERS += \
        wext/address.h \
        wext/event.h \
        wext/customer.h \
-       wext/transaction.h
+       wext/transaction.h \
+       wext/keyvalue.h
 
 SOURCES += \
        wext/customerinfo.cpp \
similarity index 99%
rename from printathome/client.cpp
rename to printathome/clientcfg.cpp
index d1f4a38..5ade69e 100644 (file)
@@ -10,7 +10,7 @@
 //
 //
 
-#include "client.h"
+#include "clientcfg.h"
 
 #include "scli.h"
 
similarity index 100%
rename from printathome/client.h
rename to printathome/clientcfg.h
index 0874a3b..04cc513 100644 (file)
@@ -16,7 +16,8 @@
 #include <WTransaction>
 
 #include "pah.h"
-#include "client.h"
+#include "clientcfg.h"
+#include "servercfg.h"
 
 #include <QIcon>
 #include <QMenu>
@@ -30,7 +31,7 @@ PrintIcon::PrintIcon()
        ctx->addAction(tr("Start &Printing now"));
        ctx->addSeparator();
        ctx->addAction(tr("&Client Configuration..."),this,SLOT(clientConfig()));
-       ctx->addAction(tr("&Server Configuration..."));
+       ctx->addAction(tr("&Server Configuration..."),this,SLOT(serverConfig()));
        ctx->addSeparator();
        ctx->addAction(tr("&Quit"),qApp,SLOT(quit()));
        setContextMenu(ctx);
@@ -69,6 +70,11 @@ void PrintIcon::clientConfig()
        cc.exec();
 }
 
+void PrintIcon::serverConfig()
+{
+       MPServerConfig sc;
+       sc.exec();
+}
 
 
 int main(int argc,char**argv)
index f1faadf..e47ce53 100644 (file)
@@ -32,6 +32,7 @@ public:
 public slots:
        void setPrintMode(PrintMode);
        void clientConfig();
+       void serverConfig();
 };
 
-#endif
\ No newline at end of file
+#endif
index 68806e3..e55a7ca 100644 (file)
@@ -7,8 +7,8 @@ include(../iface/iface.pri)
 include(../commonlib/commonlib.pri)
 
 #sources
-SOURCES += pah.cpp client.cpp
-HEADERS += pah.h client.h
+SOURCES += pah.cpp clientcfg.cpp servercfg.cpp
+HEADERS += pah.h clientcfg.h servercfg.h
 
 RESOURCES += files.qrc
 
diff --git a/printathome/servercfg.cpp b/printathome/servercfg.cpp
new file mode 100644 (file)
index 0000000..bf92f50
--- /dev/null
@@ -0,0 +1,186 @@
+//
+// C++ Implementation: print @ home
+//
+// Description: Client Settings
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2016
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#include "servercfg.h"
+
+#include "msinterface.h"
+#include "templates.h"
+
+#include "MTGetAllContactTypes"
+#include "MTGetPrintAtHomeSettings"
+#include "MTSetPrintAtHomeSettings"
+
+#include <QFormLayout>
+#include <QBoxLayout>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QComboBox>
+#include <QSpinBox>
+#include <QLineEdit>
+#include <QSettings>
+#include <QDebug>
+#include <QMessageBox>
+
+#define TICKETCS "TicketChecksum"
+#define VOUCHERCS "VoucherChecksum"
+#define INVOICECS "InvoiceChecksum"
+#define MAILCONTACTS "MailContactTypes"
+
+//seconds between forced re-inits
+#define INIT_TIMER 5*60
+
+QList<MOContactType> MPServerConfig::mcontacttypes;
+QDateTime MPServerConfig::mlastinit;
+QMap<QString,QString> MPServerConfig::msettings;
+
+
+MPServerConfig::MPServerConfig(QWidget* parent)
+:QDialog(parent)
+{
+       setWindowTitle(tr("Print@Home Server Configuration"));
+       QVBoxLayout*vl,*vl2;
+       setLayout(vl=new QVBoxLayout);
+       QFormLayout*fl;
+       vl->addLayout(fl=new QFormLayout);
+       //template for tickets
+       fl->addRow(tr("Ticket Template:"),mticket=new QComboBox);
+       //template for vouchers
+       fl->addRow(tr("Voucher Template:"),mvoucher=new QComboBox);
+       //template for invoice
+       fl->addRow(tr("Invoice Template:"),minvoice=new QComboBox);
+       //contacts
+       fl->addRow(tr("eMail Contacts:"),vl2=new QVBoxLayout);
+       //get settings
+       init();
+       //update templates
+       QList<MTemplate>tpl=req->templateStore()->allTemplates();
+       int tp=-1,vp=-1,ip=-1;
+       const QString tc=ticketTemplateCS(),vc=voucherTemplateCS(),ic=invoiceTemplateCS();
+       qDebug()<<"DEFAULTS tick"<<tc<<", vouch"<<vc<<", inv"<<ic;
+       for(MTemplate tmp:tpl){
+               qDebug()<<"JFF"<<tmp.baseName()<<tmp.description()<<tmp.checksum()<<tmp.completeFileName();
+               if(tmp.baseName()=="ticket"){
+                       mticket->addItem(tmp.description(),tmp.checksum());
+                       if(tc==tmp.checksum())tp=mticket->count()-1;
+               }
+               if(tmp.baseName()=="voucher"){
+                       mvoucher->addItem(tmp.description(),tmp.checksum());
+                       if(vc==tmp.checksum())vp=mvoucher->count()-1;
+               }
+               if(tmp.baseName()=="bill"){
+                       minvoice->addItem(tmp.description(),tmp.checksum());
+                       if(ic==tmp.checksum())ip=minvoice->count()-1;
+               }
+       }
+       mticket->setCurrentIndex(tp);
+       mvoucher->setCurrentIndex(vp);
+       minvoice->setCurrentIndex(ip);
+       //update contacts
+       QList<int> mcont=mailContactTypeIds();
+       qDebug()<<"DEFAULT contacts"<<mcont;
+       for(auto ctc:mcontacttypes){
+               const QString cn=ctc.contacttype();
+               QCheckBox*cb=new QCheckBox(cn);
+               cb->setChecked(mcont.contains(ctc.contacttypeid()));
+               vl2->addWidget(cb);
+               mcontacts.insert(ctc.contacttypeid(),cb);
+       }
+       
+       vl->addSpacing(15);
+       QHBoxLayout*hl;
+       vl->addLayout(hl=new QHBoxLayout);
+       hl->addStretch(1);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("&OK")));
+       connect(p,SIGNAL(clicked()),this,SLOT(save()),Qt::DirectConnection);
+       connect(p,SIGNAL(clicked()),this,SLOT(accept()),Qt::QueuedConnection);
+       hl->addWidget(p=new QPushButton(tr("&Cancel")));
+       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+       
+}
+
+void MPServerConfig::init(bool force)
+{
+       if(!force && mlastinit>=QDateTime::currentDateTime().addSecs(-(INIT_TIMER)))return;
+       
+       auto getsettings=req->queryGetPrintAtHomeSettings();
+       if(getsettings.hasError())
+               QMessageBox::warning(nullptr,tr("Warning"),tr("Unable to retrieve Print@Home Settings: %1").arg(getsettings.errorString()));
+       else
+               msettings=toMap(getsettings.getsettings());
+       qDebug()<<"NEW-SETTINGS"<<msettings;
+       
+       mcontacttypes=req->queryGetAllContactTypes().gettypes();
+       
+       mlastinit=QDateTime::currentDateTime();
+}
+
+void MPServerConfig::save()
+{
+       //gather data
+       QList<MOKeyValuePair> settings;
+       settings.append(MOKeyValuePair(TICKETCS,mticket->currentData().toString()));
+       settings.append(MOKeyValuePair(VOUCHERCS,mvoucher->currentData().toString()));
+       settings.append(MOKeyValuePair(INVOICECS,minvoice->currentData().toString()));
+       QString mct;
+       for(int cid:mcontacts.keys())
+               if(mcontacts[cid]->isChecked())
+                       mct+=QString("%1 ").arg(cid);
+       settings.append(MOKeyValuePair(MAILCONTACTS,mct));
+       qDebug()<<"SAVING"<<toMap(settings);
+       
+       //save
+       auto setsettings=req->querySetPrintAtHomeSettings(settings);
+       if(setsettings.hasError())
+               QMessageBox::warning(nullptr,tr("Warning"),tr("Unable to store Print@Home Settings: %1").arg(setsettings.errorString()));
+
+       //force re-init
+       init(true);
+}
+
+// TODO: THIS SHOULD REALLY BE STORED ON THE SERVER AS CONFIG VALUE!!!!!!
+QString MPServerConfig::ticketTemplateCS()
+{
+       init();
+       return msettings.value(TICKETCS);
+}
+
+QString MPServerConfig::voucherTemplateCS()
+{
+       init();
+       return msettings.value(VOUCHERCS);
+}
+
+QString MPServerConfig::invoiceTemplateCS()
+{
+       init();
+       return msettings.value(INVOICECS);
+}
+
+QStringList MPServerConfig::mailContactTypes()
+{
+       QStringList ret;
+       for(int id:mailContactTypeIds())
+               for(auto ct:mcontacttypes)
+                       if(ct.contacttypeid()==id)
+                               ret.append(ct.contacttype());
+       return ret;
+}
+
+QList<int> MPServerConfig::mailContactTypeIds()
+{
+       init();
+       QList<int>ret;
+       for(auto s:msettings.value(MAILCONTACTS).split(' ',QString::SkipEmptyParts))
+               ret.append(s.toInt());
+       return ret;
+}
diff --git a/printathome/servercfg.h b/printathome/servercfg.h
new file mode 100644 (file)
index 0000000..da31ad7
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// C++ Interface: print @ home, client config
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2016
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#ifndef MSMOKE_PAH_SERVER_H
+#define MSMOKE_PAH_SERVER_H
+
+#include <QDialog>
+#include <QMap>
+#include <QList>
+#include <QDateTime>
+
+#include "MOContactType"
+
+class QCheckBox;
+class QLineEdit;
+class QComboBox;
+class QSpinBox;
+
+class MPServerConfig:public QDialog
+{
+       Q_OBJECT
+public:
+       MPServerConfig(QWidget*parent=nullptr);
+       
+       static QStringList mailContactTypes();
+       static QList<int> mailContactTypeIds();
+public slots:
+       void save();
+       
+private:
+       QComboBox*mticket,*mvoucher,*minvoice;
+       QMap<int,QCheckBox*>mcontacts;
+       static QMap<QString,QString>msettings;
+       static QList<MOContactType>mcontacttypes;
+       static QDateTime mlastinit;
+               
+       static QString ticketTemplateCS();
+       static QString voucherTemplateCS();
+       static QString invoiceTemplateCS();
+       static void init(bool force=false);
+};
+
+#endif
index 47ba998..4d62b18 100644 (file)
@@ -60,6 +60,7 @@
        </Class>
        
        <Class name="KeyValuePair">
+               <Abstract lang="qt"/>
                <Property name="key" type="string"/>
                <Property name="value" type="string"/>
                <Property name="isnull" type="bool"/>
index d55d46d..ab555c6 100644 (file)
        <Transaction name="GetPrintAtHomeSettings" update="no">
                <Doc>Gets all settings pertaining to Print@Home</Doc>
                <Input/>
-               <Call lang="php" method=";"/><!-- TODO -->
+               <Call lang="php" method="WOOrder::getPrintAtHomeSettings($this);"/><!-- TODO -->
                <Output>
                        <Var name="settings" type="List:KeyValuePair"/>
                </Output>
                <Input>
                        <Var name="settings" type="List:KeyValuePair"/>
                </Input>
-               <Call lang="php" method=";"/><!-- TODO -->
+               <Call lang="php" method="WOOrder::setPrintAtHomeSettings($this);"/><!-- TODO -->
                <Output/>
        </Transaction>
 </Wolf>
index 4c0e669..cfcb061 100644 (file)
@@ -1001,6 +1001,35 @@ class WOOrder extends WOOrderAbstract
                //get items
                $trans->setitems(WOItemAudit::fromTableArrayitem_audit(WTitem_audit::selectFromDB("audituname=".$db->escapeString($uname)." AND audittime>=".$db->escapeInt($oldest),"ORDER BY auditid")));
        }
+       
+       static public function getPrintAtHomeSettings($trans)
+       {
+               $res=array();
+               $cfg=WTconfig::selectFromDB();
+               foreach($cfg as $c) {
+                       if(strncmp($c->ckey,"printathome:",12)==0)
+                               $r=new WOKeyValuePair();
+                               $r->setkey(substr($c->ckey,12));
+                               $r->setvalue($c->cval);
+                               $res[]=$r;
+               }
+               $trans->setsettings($res);
+               
+       }
+       
+       static public function setPrintAtHomeSettings($trans)
+       {
+               foreach($trans->getsettings() as $cfg) {
+                       if($cfg->getisnull()){
+                               $ct=WTconfig::getFromDB("printathome:".$cfg->getkey());
+                               $ct->deleteFromDb();
+                       }else{
+                               $ct=WTconfig::newRow(array("ckey"=> ("printathome:".$cfg->getkey()), "cval"=>$cfg->getvalue()));
+                               $ct->insertOrUpdate();
+                       }
+               }
+               
+       }
 };