Allow adding fake printers from file
This commit is contained in:
parent
1ef3d590fc
commit
187fd4226e
2 changed files with 43 additions and 23 deletions
|
@ -64,7 +64,7 @@ void IppPrinter::setUrl(QString url_s)
|
||||||
|
|
||||||
qDebug() << url.scheme();
|
qDebug() << url.scheme();
|
||||||
|
|
||||||
if(url.scheme() != "ipp" /* or ipps */)
|
if(url.scheme() != "ipp" /* or ipps */ && url.scheme() != "file")
|
||||||
{
|
{
|
||||||
//if https -> ipps, else:
|
//if https -> ipps, else:
|
||||||
if(url.scheme() == "")
|
if(url.scheme() == "")
|
||||||
|
@ -100,34 +100,33 @@ void IppPrinter::refresh() {
|
||||||
// _additionalDocumentFormats = QStringList();
|
// _additionalDocumentFormats = QStringList();
|
||||||
// emit additionalDocumentFormatsChanged();
|
// emit additionalDocumentFormatsChanged();
|
||||||
|
|
||||||
|
if(_url.scheme() == "file")
|
||||||
|
{
|
||||||
|
QFile file(_url.toLocalFile());
|
||||||
|
if(file.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
QJsonDocument JsonDocument = QJsonDocument::fromJson(file.readAll());
|
||||||
|
|
||||||
|
_attrs = JsonDocument.object();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
emit attrsChanged();
|
||||||
|
UpdateAdditionalDocumentFormats();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
QNetworkRequest request = mkReq();
|
QNetworkRequest request = mkReq();
|
||||||
QJsonObject o = opAttrs();
|
QJsonObject o = opAttrs();
|
||||||
|
|
||||||
IppMsg msg = IppMsg(o);
|
IppMsg msg = IppMsg(o);
|
||||||
_nam->post(request, msg.encode(IppMsg::GetPrinterAttrs));
|
_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();
|
_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"))
|
if(_attrs.contains("printer-device-id"))
|
||||||
{
|
{
|
||||||
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
QJsonArray supportedMimeTypes = _attrs["document-format-supported"].toObject()["value"].toArray();
|
||||||
|
@ -150,10 +149,30 @@ void IppPrinter::getPrinterAttributesFinished(QNetworkReply *reply)
|
||||||
}
|
}
|
||||||
qDebug() << "additionalDocumentFormats" << _additionalDocumentFormats;
|
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 attrsChanged();
|
||||||
emit additionalDocumentFormatsChanged();
|
|
||||||
|
|
||||||
|
UpdateAdditionalDocumentFormats();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IppPrinter::printRequestFinished(QNetworkReply *reply)
|
void IppPrinter::printRequestFinished(QNetworkReply *reply)
|
||||||
|
|
|
@ -58,6 +58,7 @@ public slots:
|
||||||
|
|
||||||
|
|
||||||
void onUrlChanged();
|
void onUrlChanged();
|
||||||
|
void UpdateAdditionalDocumentFormats();
|
||||||
void getPrinterAttributesFinished(QNetworkReply* reply);
|
void getPrinterAttributesFinished(QNetworkReply* reply);
|
||||||
void printRequestFinished(QNetworkReply* reply);
|
void printRequestFinished(QNetworkReply* reply);
|
||||||
void getJobsRequestFinished(QNetworkReply* reply);
|
void getJobsRequestFinished(QNetworkReply* reply);
|
||||||
|
|
Loading…
Reference in a new issue