Move operation to IppMsg constructor

This commit is contained in:
Anton Thomasson 2022-07-10 11:36:21 +02:00
parent 04830863ab
commit 071c39b6f3
5 changed files with 22 additions and 19 deletions

View file

@ -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++;

View file

@ -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;

View file

@ -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)

View file

@ -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;

View file

@ -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"));