CUPS: Use printer job-sheets as default instead of none,none

This also reads the job-sheets from lpoptions if set there for the particular printer

Change-Id: I35aff103261ef58492779071d866e8a15ac78607
Reviewed-by: Laurent Montel <laurent.montel@kdab.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Albert Astals Cid 2017-12-06 11:28:55 +01:00
parent 33f08a68c1
commit 83538a360e
4 changed files with 45 additions and 2 deletions

View File

@ -429,6 +429,8 @@ QVariant QPpdPrintDevice::property(QPrintDevice::PrintDevicePropertyKey key) con
return QVariant::fromValue<ppd_file_t *>(m_ppd);
else if (key == PDPK_CupsJobPriority)
return printerOption(QStringLiteral("job-priority"));
else if (key == PDPK_CupsJobSheets)
return printerOption(QStringLiteral("job-sheets"));
return QVariant();
}

View File

@ -150,6 +150,32 @@ static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPa
return QString();
}
static inline QCUPSSupport::BannerPage stringToBannerPage(const QString &bannerPage)
{
if (bannerPage == QLatin1String("none")) return QCUPSSupport::NoBanner;
else if (bannerPage == QLatin1String("standard")) return QCUPSSupport::Standard;
else if (bannerPage == QLatin1String("unclassified")) return QCUPSSupport::Unclassified;
else if (bannerPage == QLatin1String("confidential")) return QCUPSSupport::Confidential;
else if (bannerPage == QLatin1String("classified")) return QCUPSSupport::Classified;
else if (bannerPage == QLatin1String("secret")) return QCUPSSupport::Secret;
else if (bannerPage == QLatin1String("topsecret")) return QCUPSSupport::TopSecret;
return QCUPSSupport::NoBanner;
}
QCUPSSupport::JobSheets QCUPSSupport::parseJobSheets(const QString &jobSheets)
{
JobSheets result;
const QStringList parts = jobSheets.split(QLatin1Char(','));
if (parts.count() == 2) {
result.startBannerPage = stringToBannerPage(parts[0]);
result.endBannerPage = stringToBannerPage(parts[1]);
}
return result;
}
void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage)
{
QStringList cupsOptions = cupsOptionsList(printer);

View File

@ -70,6 +70,7 @@ QT_BEGIN_NAMESPACE
#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)
#define PDPK_CupsJobSheets QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 3)
class Q_PRINTSUPPORT_EXPORT QCUPSSupport
{
@ -139,6 +140,13 @@ public:
static void setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet,
const PagesPerSheetLayout pagesPerSheetLayout);
static void setPageRange(QPrinter *printer, int pageFrom, int pageTo);
struct JobSheets
{
BannerPage startBannerPage = QCUPSSupport::NoBanner;
BannerPage endBannerPage = QCUPSSupport::NoBanner;
};
static JobSheets parseJobSheets(const QString &jobSheets);
};
Q_DECLARE_TYPEINFO(QCUPSSupport::JobHoldUntil, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QCUPSSupport::BannerPage, Q_PRIMITIVE_TYPE);

View File

@ -196,8 +196,15 @@ void QCupsJobWidget::initBannerPages()
m_ui.endBannerPageCombo->addItem(tr("Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Secret));
m_ui.endBannerPageCombo->addItem(tr("Top Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::TopSecret));
setStartBannerPage(QCUPSSupport::NoBanner);
setEndBannerPage(QCUPSSupport::NoBanner);
QCUPSSupport::JobSheets jobSheets;
if (m_printDevice) {
const QString jobSheetsString = m_printDevice->property(PDPK_CupsJobSheets).toString();
jobSheets = QCUPSSupport::parseJobSheets(jobSheetsString);
}
setStartBannerPage(jobSheets.startBannerPage);
setEndBannerPage(jobSheets.endBannerPage);
}
void QCupsJobWidget::setStartBannerPage(const QCUPSSupport::BannerPage bannerPage)