diff --git a/src/ippmsg.cpp b/src/ippmsg.cpp index ffbbe0c..38869e9 100644 --- a/src/ippmsg.cpp +++ b/src/ippmsg.cpp @@ -6,8 +6,9 @@ IppMsg::IppMsg() { } -IppMsg::IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs, quint8 majVsn, quint8 minVsn) +IppMsg::IppMsg(Operation operation, QJsonObject opAttrs, QJsonObject jobAttrs, quint8 majVsn, quint8 minVsn) { + _operation = operation; _majVsn = majVsn; _minVsn = minVsn; _opAttrs = opAttrs; @@ -302,13 +303,13 @@ QString IppMsg::consume_attribute(QJsonObject& attrs, Bytestream& data) return name; } -Bytestream IppMsg::encode(Operation op) +Bytestream IppMsg::encode() { Bytestream ipp; ipp << _majVsn << _minVsn; - ipp << quint16(op); + ipp << quint16(_operation); ipp << _reqid++; diff --git a/src/ippmsg.h b/src/ippmsg.h index baee69a..1b33ae2 100644 --- a/src/ippmsg.h +++ b/src/ippmsg.h @@ -67,11 +67,11 @@ public: explicit IppMsg(); explicit IppMsg(Bytestream& resp); - IppMsg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject(), quint8 majVsn=1, quint8 minVsn=1); + IppMsg(Operation operation, QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject(), quint8 majVsn=1, quint8 minVsn=1); IppMsg(const IppMsg& other) = default; ~IppMsg(); - Bytestream encode(Operation op); + Bytestream encode(); QJsonObject getPrinterAttrs() {return _printerAttrs;} QJsonArray getJobAttrs() {return _jobAttrs;} QJsonObject getOpAttrs() {return _opAttrs;} @@ -87,6 +87,8 @@ private: QString consume_attribute(QJsonObject& attrs, Bytestream& data); void encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue value, bool subCollection=false); + Operation _operation; + quint8 _majVsn; quint8 _minVsn; diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index dc6647b..3a61913 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -132,8 +132,8 @@ void IppPrinter::refresh() { { QJsonObject o = opAttrs(); - IppMsg msg = IppMsg(o); - emit doDoGetPrinterAttributes(msg.encode(IppMsg::GetPrinterAttrs)); + IppMsg msg = IppMsg(IppMsg::GetPrinterAttrs, o); + emit doDoGetPrinterAttributes(msg.encode()); } } @@ -705,7 +705,6 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename) qDebug() << "Final op attributes:" << o; qDebug() << "Final job attributes:" << jobAttrs; - IppMsg job = mk_msg(o, jobAttrs); QString Sides = getAttrOrDefault(jobAttrs, "sides").toString(); @@ -719,6 +718,7 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename) Params.tumble = true; } + IppMsg job = mk_msg(IppMsg::PrintJob, o, jobAttrs); emit doPrint(filename, mimeType, targetFormat, job, Params, margins); } @@ -728,9 +728,9 @@ bool IppPrinter::getJobs() { QJsonObject o = opAttrs(); o.insert("requested-attributes", QJsonObject {{"tag", IppMsg::Keyword}, {"value", "all"}}); - IppMsg job = IppMsg(o, QJsonObject()); + IppMsg job = IppMsg(IppMsg::GetJobs, o, QJsonObject()); - emit doGetJobs(job.encode(IppMsg::GetJobs)); + emit doGetJobs(job.encode()); return true; } @@ -742,9 +742,9 @@ bool IppPrinter::cancelJob(qint32 jobId) { QJsonObject o = opAttrs(); o.insert("job-id", QJsonObject {{"tag", IppMsg::Integer}, {"value", jobId}}); - IppMsg job = IppMsg(o, QJsonObject()); + IppMsg job = IppMsg(IppMsg::CancelJob, o, QJsonObject()); - emit doCancelJob(job.encode(IppMsg::CancelJob)); + emit doCancelJob(job.encode()); return true; } @@ -755,9 +755,9 @@ bool IppPrinter::identify() { QJsonObject o = opAttrs(); - IppMsg job = IppMsg(o, QJsonObject()); + IppMsg job = IppMsg(IppMsg::IdentifyPrinter, o, QJsonObject()); - emit doCancelJob(job.encode(IppMsg::IdentifyPrinter)); + emit doCancelJob(job.encode()); return true; } @@ -860,15 +860,15 @@ QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name, QStr } } -IppMsg IppPrinter::mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs) +IppMsg IppPrinter::mk_msg(IppMsg::Operation operation, QJsonObject opAttrs, QJsonObject jobAttrs) { if(_attrs.contains("ipp-versions-supported") && _attrs["ipp-versions-supported"].toObject()["value"].toArray().contains("2.0")) { qDebug() << "TWO-POINT-ZERO"; - return IppMsg(opAttrs, jobAttrs, 2, 0); + return IppMsg(operation, opAttrs, jobAttrs, 2, 0); } - return IppMsg(opAttrs, jobAttrs); + return IppMsg(operation, opAttrs, jobAttrs); } void IppPrinter::resolveUrl(QUrl& url) diff --git a/src/ippprinter.h b/src/ippprinter.h index a2df94c..aa56741 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -116,7 +116,7 @@ private: QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name, QString subkey = ""); - IppMsg mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject()); + IppMsg mk_msg(IppMsg::Operation operation, QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject()); QJsonObject _attrs; QJsonObject _jobAttrs; diff --git a/src/printerworker.cpp b/src/printerworker.cpp index 94752b9..c4f8f5e 100644 --- a/src/printerworker.cpp +++ b/src/printerworker.cpp @@ -69,7 +69,7 @@ void PrinterWorker::print(QString filename, QString mimeType, QString targetForm try { Mimer* mimer = Mimer::instance(); - Bytestream contents = job.encode(IppMsg::PrintJob); + Bytestream contents = job.encode(); emit busyMessage(tr("Preparing"));