Enable raw/binary fake-printers

This commit is contained in:
Anton Thomasson 2022-06-04 14:43:53 +02:00
parent 9ff8775fab
commit 8c6344eef8

View file

@ -4,6 +4,7 @@
#include "papersizes.h" #include "papersizes.h"
#include "overrider.h" #include "overrider.h"
#include "settings.h" #include "settings.h"
#include <fstream>
Q_DECLARE_METATYPE(QMargins) Q_DECLARE_METATYPE(QMargins)
@ -96,18 +97,35 @@ void IppPrinter::refresh() {
if(_url.scheme() == "file") if(_url.scheme() == "file")
{ {
_attrs = QJsonObject(); _attrs = QJsonObject();
QString localFile = _url.toLocalFile();
QFile file(_url.toLocalFile()); if(localFile.endsWith(".raw") || localFile.endsWith(".bin"))
if(file.open(QIODevice::ReadOnly))
{ {
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll()); try
{
_attrs = JsonDocument.object(); std::ifstream ifs = std::ifstream(localFile.toStdString(), std::ios::in | std::ios::binary);
// These won't load anyway...r Bytestream InBts(ifs);
_attrs.remove("printer-icons"); IppMsg resp(InBts);
file.close(); qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs();
Overrider::instance()->apply(_attrs); _attrs = resp.getPrinterAttrs();
}
catch(const std::exception& e)
{
qDebug() << e.what();
}
} }
else
{
QFile file(localFile);
if(file.open(QIODevice::ReadOnly))
{
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll());
_attrs = JsonDocument.object();
file.close();
}
}
_attrs.remove("printer-icons");
Overrider::instance()->apply(_attrs);
emit attrsChanged(); emit attrsChanged();
// MaybeGetStrings(); - for testing fake file-prinetrs with a strings file hosted elsewhere // MaybeGetStrings(); - for testing fake file-prinetrs with a strings file hosted elsewhere