Deduplicate request creation

This commit is contained in:
Anton Thomasson 2020-12-09 19:59:58 +01:00
parent bb1d1fbf27
commit 01b2828838
2 changed files with 13 additions and 20 deletions

View file

@ -101,12 +101,7 @@ void IppPrinter::refresh() {
// emit additionalDocumentFormatsChanged();
QNetworkRequest request;
request.setUrl(httpUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
QNetworkRequest request = mkReq();
QJsonObject o = opAttrs();
IppMsg msg = IppMsg(o);
@ -392,11 +387,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert,
qDebug() << "Printing job" << o << attrs;
QNetworkRequest request;
request.setUrl(httpUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
QNetworkRequest request = mkReq();
QJsonValue PrinterResolutionRef = getAttrOrDefault(attrs, "printer-resolution");
quint32 HwResX = PrinterResolutionRef.toObject()["x"].toInt();
@ -530,14 +521,10 @@ bool IppPrinter::getJobs() {
IppMsg job = IppMsg(o, QJsonObject());
QNetworkRequest request;
QNetworkRequest request = mkReq();
QByteArray contents = job.encode(IppMsg::GetJobs);
request.setUrl(httpUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
_jobs_nam->post(request, contents);
return true;
@ -552,13 +539,10 @@ bool IppPrinter::cancelJob(qint32 jobId) {
IppMsg job = IppMsg(o, QJsonObject());
QNetworkRequest request;
QNetworkRequest request = mkReq();
QByteArray contents = job.encode(IppMsg::CancelJob);
request.setUrl(httpUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
_job_cancel_nam->post(request, contents);
@ -574,6 +558,14 @@ QUrl IppPrinter::httpUrl() {
return url;
}
QNetworkRequest IppPrinter::mkReq() {
QNetworkRequest request;
request.setUrl(httpUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
return request;
}
void IppPrinter::setBusyMessage(QString msg)
{
_busyMessage = msg;

View file

@ -71,6 +71,7 @@ public slots:
private:
QUrl _url;
QUrl httpUrl();
QNetworkRequest mkReq();
QJsonObject opAttrs();