Add experimental printer attribute override
This commit is contained in:
parent
a41fbe067f
commit
15a13d9648
4 changed files with 92 additions and 0 deletions
|
@ -44,6 +44,7 @@ SOURCES += src/harbour-seaprint.cpp \
|
|||
src/mimer.cpp \
|
||||
ppm2pwg/ppm2pwg.cpp \
|
||||
ppm2pwg/bytestream/bytestream.cpp \
|
||||
src/overrider.cpp \
|
||||
src/svgprovider.cpp
|
||||
|
||||
DISTFILES += qml/harbour-seaprint.qml \
|
||||
|
@ -90,6 +91,7 @@ HEADERS += \
|
|||
ppm2pwg/UrfPgHdr.codable \
|
||||
ppm2pwg/bytestream/bytestream.h \
|
||||
ppm2pwg/bytestream/codable.h \
|
||||
src/overrider.h \
|
||||
src/papersizes.h \
|
||||
src/svgprovider.h
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <seaprint_version.h>
|
||||
#include "mimer.h"
|
||||
#include "papersizes.h"
|
||||
#include "overrider.h"
|
||||
|
||||
IppPrinter::IppPrinter()
|
||||
{
|
||||
|
@ -114,6 +115,7 @@ void IppPrinter::refresh() {
|
|||
// These won't load anyway...r
|
||||
_attrs.remove("printer-icons");
|
||||
file.close();
|
||||
Overrider::instance()->apply(_attrs);
|
||||
}
|
||||
emit attrsChanged();
|
||||
UpdateAdditionalDocumentFormats();
|
||||
|
@ -168,6 +170,8 @@ void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
|
|||
IppMsg resp(reply);
|
||||
qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs();
|
||||
_attrs = resp.getPrinterAttrs();
|
||||
Overrider::instance()->apply(_attrs);
|
||||
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
|
|
62
src/overrider.cpp
Normal file
62
src/overrider.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include "overrider.h"
|
||||
#include <QMutex>
|
||||
#include <QStandardPaths>
|
||||
#include <QtDebug>
|
||||
|
||||
Overrider::Overrider()
|
||||
{
|
||||
// QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)+"/overrides");
|
||||
QFile file(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.seaprint_overrides");
|
||||
qDebug() << "AAAAAAAAAAAAAAA" << file.fileName();
|
||||
if(file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll());
|
||||
|
||||
_overrides = JsonDocument.object();
|
||||
qDebug() << "overides loaded" << _overrides;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
Overrider::~Overrider() {
|
||||
}
|
||||
|
||||
Overrider* Overrider::m_Instance = nullptr;
|
||||
|
||||
Overrider* Overrider::instance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (!m_Instance)
|
||||
{
|
||||
mutex.lock();
|
||||
|
||||
if (!m_Instance)
|
||||
m_Instance = new Overrider();
|
||||
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
return m_Instance;
|
||||
}
|
||||
|
||||
bool Overrider::apply(QJsonObject& attrs)
|
||||
{
|
||||
bool applied = false;
|
||||
foreach(const QString& key, _overrides.keys())
|
||||
{
|
||||
if(attrs.contains(key))
|
||||
{
|
||||
QString match = attrs[key].toObject()["value"].toString();
|
||||
if(match != "" && _overrides[key].toObject().contains(match))
|
||||
{
|
||||
QJsonObject overrideden_data = _overrides[key].toObject()[match].toObject();
|
||||
foreach(const QString& o_key, overrideden_data.keys())
|
||||
{
|
||||
attrs.insert(o_key, overrideden_data[o_key]);
|
||||
}
|
||||
applied=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return applied;
|
||||
}
|
24
src/overrider.h
Normal file
24
src/overrider.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef OVERRIDER_H
|
||||
#define OVERRIDER_H
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QFile>
|
||||
|
||||
class Overrider
|
||||
{
|
||||
public:
|
||||
static Overrider* instance();
|
||||
bool apply(QJsonObject& attrs);
|
||||
|
||||
private:
|
||||
Overrider();
|
||||
~Overrider();
|
||||
Overrider(const Overrider &);
|
||||
Overrider& operator=(const Overrider &);
|
||||
|
||||
static Overrider* m_Instance;
|
||||
QJsonObject _overrides;
|
||||
};
|
||||
|
||||
#endif // OVERRIDER_H
|
Loading…
Reference in a new issue