Allow adding fake printers from file

This commit is contained in:
Anton Thomasson 2021-02-13 14:59:38 +01:00
parent 1ef3d590fc
commit 187fd4226e
2 changed files with 43 additions and 23 deletions

View file

@ -64,7 +64,7 @@ void IppPrinter::setUrl(QString url_s)
qDebug() << url.scheme();
if(url.scheme() != "ipp" /* or ipps */)
if(url.scheme() != "ipp" /* or ipps */ && url.scheme() != "file")
{
//if https -> ipps, else:
if(url.scheme() == "")
@ -100,34 +100,33 @@ void IppPrinter::refresh() {
// _additionalDocumentFormats = QStringList();
// emit additionalDocumentFormatsChanged();
if(_url.scheme() == "file")
{
QFile file(_url.toLocalFile());
if(file.open(QIODevice::ReadOnly))
{
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll());
QNetworkRequest request = mkReq();
QJsonObject o = opAttrs();
IppMsg msg = IppMsg(o);
_nam->post(request, msg.encode(IppMsg::GetPrinterAttrs));
_attrs = JsonDocument.object();
file.close();
}
emit attrsChanged();
UpdateAdditionalDocumentFormats();
}
else
{
QNetworkRequest request = mkReq();
QJsonObject o = opAttrs();
IppMsg msg = IppMsg(o);
_nam->post(request, msg.encode(IppMsg::GetPrinterAttrs));
}
}
void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
void IppPrinter::UpdateAdditionalDocumentFormats()
{
qDebug() << reply->error() << reply->errorString() << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
_attrs = QJsonObject();
_additionalDocumentFormats = QStringList();
if(reply->error() == QNetworkReply::NoError)
{
try {
IppMsg resp(reply);
qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs();
_attrs = resp.getPrinterAttrs();
}
catch(const std::exception& e)
{
qDebug() << e.what();
}
}
if(_attrs.contains("printer-device-id"))
{
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
@ -150,10 +149,30 @@ void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
}
qDebug() << "additionalDocumentFormats" << _additionalDocumentFormats;
}
emit additionalDocumentFormatsChanged();
}
void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
{
qDebug() << reply->error() << reply->errorString() << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
_attrs = QJsonObject();
if(reply->error() == QNetworkReply::NoError)
{
try {
IppMsg resp(reply);
qDebug() << resp.getStatus() << resp.getOpAttrs() << resp.getPrinterAttrs();
_attrs = resp.getPrinterAttrs();
}
catch(const std::exception& e)
{
qDebug() << e.what();
}
}
emit attrsChanged();
emit additionalDocumentFormatsChanged();
UpdateAdditionalDocumentFormats();
}
void IppPrinter::printRequestFinished(QNetworkReply *reply)

View file

@ -58,6 +58,7 @@ public slots:
void onUrlChanged();
void UpdateAdditionalDocumentFormats();
void getPrinterAttributesFinished(QNetworkReply* reply);
void printRequestFinished(QNetworkReply* reply);
void getJobsRequestFinished(QNetworkReply* reply);