From ad77a2447e8cc828dadd268c72428556e3cc8a84 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 6 Dec 2017 10:19:13 +0100 Subject: [PATCH 1/1] CUPS: Use default cups job-priority instead of 50 This also reads the job-priority from lpoptions if set there for the particular printer Change-Id: I75d983c377d2135a0b0d3e028829a7384a5e1897 Reviewed-by: Laurent Montel Reviewed-by: Frederik Gladhorn --- src/plugins/printsupport/cups/qppdprintdevice.cpp | 2 ++ src/printsupport/dialogs/qprintdialog_unix.cpp | 2 +- src/printsupport/kernel/qcups_p.h | 5 +++-- src/printsupport/widgets/qcupsjobwidget.cpp | 20 +++++++++++++++++--- src/printsupport/widgets/qcupsjobwidget_p.h | 4 +++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/plugins/printsupport/cups/qppdprintdevice.cpp b/src/plugins/printsupport/cups/qppdprintdevice.cpp index 021d040..56976a6 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.cpp +++ b/src/plugins/printsupport/cups/qppdprintdevice.cpp @@ -427,6 +427,8 @@ QVariant QPpdPrintDevice::property(QPrintDevice::PrintDevicePropertyKey key) con { if (key == PDPK_PpdFile) return QVariant::fromValue(m_ppd); + else if (key == PDPK_CupsJobPriority) + return printerOption(QStringLiteral("job-priority")); return QVariant(); } diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp index 9ad9fa3..020894c 100644 --- a/src/printsupport/dialogs/qprintdialog_unix.cpp +++ b/src/printsupport/dialogs/qprintdialog_unix.cpp @@ -333,7 +333,7 @@ QPrintPropertiesDialog::QPrintPropertiesDialog(QPrinter *printer, QPrintDevice * widget.pageSetup->setPrinter(printer, outputFormat, printerName); #if QT_CONFIG(cupsjobwidget) - m_jobOptions = new QCupsJobWidget(printer); + m_jobOptions = new QCupsJobWidget(printer, currentPrintDevice); widget.tabs->insertTab(1, m_jobOptions, tr("Job Options")); #endif diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h index b67390c..3abccf2 100644 --- a/src/printsupport/kernel/qcups_p.h +++ b/src/printsupport/kernel/qcups_p.h @@ -67,8 +67,9 @@ QT_BEGIN_NAMESPACE // removed from the dialogs. #define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00) -#define PDPK_PpdFile QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase) -#define PDPK_PpdOption QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 1) +#define PDPK_PpdFile QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase) +#define PDPK_PpdOption QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 1) +#define PDPK_CupsJobPriority QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 2) class Q_PRINTSUPPORT_EXPORT QCUPSSupport { diff --git a/src/printsupport/widgets/qcupsjobwidget.cpp b/src/printsupport/widgets/qcupsjobwidget.cpp index 8fb07c8..f21e229 100644 --- a/src/printsupport/widgets/qcupsjobwidget.cpp +++ b/src/printsupport/widgets/qcupsjobwidget.cpp @@ -52,6 +52,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE /*! @@ -64,9 +66,10 @@ QT_BEGIN_NAMESPACE \inmodule QtPrintSupport */ -QCupsJobWidget::QCupsJobWidget(QPrinter *printer, QWidget *parent) +QCupsJobWidget::QCupsJobWidget(QPrinter *printer, QPrintDevice *printDevice, QWidget *parent) : QWidget(parent), - m_printer(printer) + m_printer(printer), + m_printDevice(printDevice) { m_ui.setupUi(this); //set all the default values @@ -151,7 +154,18 @@ QString QCupsJobWidget::jobBilling() const void QCupsJobWidget::initJobPriority() { - setJobPriority(50); + int priority = -1; + if (m_printDevice) { + bool ok; + priority = m_printDevice->property(PDPK_CupsJobPriority).toInt(&ok); + if (!ok) + priority = -1; + } + + if (priority < 0 || priority > 100) + priority = 50; + + setJobPriority(priority); } void QCupsJobWidget::setJobPriority(int jobPriority) diff --git a/src/printsupport/widgets/qcupsjobwidget_p.h b/src/printsupport/widgets/qcupsjobwidget_p.h index 2aca6bc..dcec27a 100644 --- a/src/printsupport/widgets/qcupsjobwidget_p.h +++ b/src/printsupport/widgets/qcupsjobwidget_p.h @@ -65,13 +65,14 @@ QT_BEGIN_NAMESPACE class QString; class QTime; class QPrinter; +class QPrintDevice; class QCupsJobWidget : public QWidget { Q_OBJECT public: - explicit QCupsJobWidget(QPrinter *printer, QWidget *parent = nullptr); + explicit QCupsJobWidget(QPrinter *printer, QPrintDevice *printDevice, QWidget *parent = nullptr); ~QCupsJobWidget(); void setupPrinter(); @@ -102,6 +103,7 @@ private: void initBannerPages(); QPrinter *m_printer; + QPrintDevice *m_printDevice; Ui::QCupsJobWidget m_ui; Q_DISABLE_COPY(QCupsJobWidget) -- 2.7.4