--- /dev/null
+//
+// 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
--- /dev/null
+//
+// 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;
+}
--- /dev/null
+//
+// 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