QCUPSSupport: Extract Method bannerPageToString() from setBannerPages()

The new function just converts the job-sheets cups option argument,
reducing the number of almost-identical switch statements to one.

Effects on a stripped Linux AMD64 GCC 4.7 -std=c++11 -O2 build:
  text: -1008B
  data:   +-0B
  relocs: +-0

Change-Id: I56843fa963e098e5c8ae203584f34bf5798667e6
Reviewed-by: Martin Klapetek <mklapetek@kde.org>
Reviewed-by: John Layt <jlayt@kde.org>
bb10
Marc Mutz 2014-03-24 01:08:09 +01:00 committed by The Qt Project
parent c36746a829
commit c3a2fe6436
1 changed files with 17 additions and 49 deletions

View File

@ -126,58 +126,26 @@ void QCUPSSupport::setJobPriority(QPrinter *printer, int priority)
setCupsOptions(printer, cupsOptions);
}
static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPage)
{
switch (bannerPage) {
case QCUPSSupport::NoBanner: return QStringLiteral("none");
case QCUPSSupport::Standard: return QStringLiteral("standard");
case QCUPSSupport::Unclassified: return QStringLiteral("unclassified");
case QCUPSSupport::Confidential: return QStringLiteral("confidential");
case QCUPSSupport::Classified: return QStringLiteral("classified");
case QCUPSSupport::Secret: return QStringLiteral("secret");
case QCUPSSupport::TopSecret: return QStringLiteral("topsecret");
}
Q_UNREACHABLE();
return QString();
};
void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage)
{
QStringList cupsOptions = cupsOptionsList(printer);
QString startBanner, endBanner;
switch (startBannerPage) {
case NoBanner:
startBanner = QStringLiteral("none");
break;
case Standard:
startBanner = QStringLiteral("standard");
break;
case Unclassified:
startBanner = QStringLiteral("unclassified");
break;
case Confidential:
startBanner = QStringLiteral("confidential");
break;
case Classified:
startBanner = QStringLiteral("classified");
break;
case Secret:
startBanner = QStringLiteral("secret");
break;
case TopSecret:
startBanner = QStringLiteral("topsecret");
break;
}
switch (endBannerPage) {
case NoBanner:
endBanner = QStringLiteral("none");
break;
case Standard:
endBanner = QStringLiteral("standard");
break;
case Unclassified:
endBanner = QStringLiteral("unclassified");
break;
case Confidential:
endBanner = QStringLiteral("confidential");
break;
case Classified:
endBanner = QStringLiteral("classified");
break;
case Secret:
endBanner = QStringLiteral("secret");
break;
case TopSecret:
endBanner = QStringLiteral("topsecret");
break;
}
const QString startBanner = bannerPageToString(startBannerPage);
const QString endBanner = bannerPageToString(endBannerPage);
setCupsOption(cupsOptions, QStringLiteral("job-sheets"), startBanner + QLatin1Char(',') + endBanner);
setCupsOptions(printer, cupsOptions);