diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-03-24 01:00:33 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-31 22:54:14 +0200 |
commit | c36746a829473f063b346e64cc08bfb3d7562e26 (patch) | |
tree | 3fc32d4d841a5b7195b177cdfcd2da0b3508b231 /src/printsupport | |
parent | 3270b4490bc420359483cb00ae48e91e261b30e8 (diff) |
QCUPSSupport: Extract Method jobHoldToString() from setJobHold()
The new function just calculates the job-hold-until cups option argument,
reducing the number of setCupsOption() calls down to one.
Effects on a stripped Linux AMD64 GCC 4.7 c++11 release build:
text: -552B
data: +-0B
relocs: +-0
Change-Id: I4aa4118c3493cd302dd8fd7f4985c7e0f70ef071
Reviewed-by: Martin Klapetek <mklapetek@kde.org>
Reviewed-by: John Layt <jlayt@kde.org>
Diffstat (limited to 'src/printsupport')
-rw-r--r-- | src/printsupport/kernel/qcups.cpp | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp index a1c657eda4..5f4043141c 100644 --- a/src/printsupport/kernel/qcups.cpp +++ b/src/printsupport/kernel/qcups.cpp @@ -67,61 +67,49 @@ void QCUPSSupport::setCupsOption(QStringList &cupsOptions, const QString &option } } -void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) +static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime) { - QStringList cupsOptions = cupsOptionsList(printer); - switch (jobHold) { - case NoHold: //default - break; - case Indefinite: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("indefinite")); - break; - case DayTime: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("day-time")); - break; - case Night: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("night")); - break; - case SecondShift: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("second-shift")); - break; - case ThirdShift: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("third-shift")); - break; - case Weekend: - setCupsOption(cupsOptions, - QStringLiteral("job-hold-until"), - QStringLiteral("weekend")); - break; - case SpecificTime: - if (holdUntilTime.isNull()) { - setJobHold(printer, NoHold); - return; + case QCUPSSupport::Indefinite: + return QStringLiteral("indefinite"); + case QCUPSSupport::DayTime: + return QStringLiteral("day-time"); + case QCUPSSupport::Night: + return QStringLiteral("night"); + case QCUPSSupport::SecondShift: + return QStringLiteral("second-shift"); + case QCUPSSupport::ThirdShift: + return QStringLiteral("third-shift"); + case QCUPSSupport::Weekend: + return QStringLiteral("weekend"); + case QCUPSSupport::SpecificTime: + if (!holdUntilTime.isNull()) { + // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent + QDateTime localDateTime = QDateTime::currentDateTime(); + // Check if time is for tomorrow in case of DST change overnight + if (holdUntilTime < localDateTime.time()) + localDateTime.addDays(1); + localDateTime.setTime(holdUntilTime); + return localDateTime.toUTC().time().toString(QStringLiteral("HH:mm")); } - // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent - QDateTime localDateTime = QDateTime::currentDateTime(); - // Check if time is for tomorrow in case of DST change overnight - if (holdUntilTime < localDateTime.time()) - localDateTime.addDays(1); - localDateTime.setTime(holdUntilTime); + // else fall through: + case QCUPSSupport::NoHold: + return QString(); + } + Q_UNREACHABLE(); + return QString(); +} + +void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) +{ + const QString jobHoldUntilArgument = jobHoldToString(jobHold, holdUntilTime); + if (!jobHoldUntilArgument.isEmpty()) { + QStringList cupsOptions = cupsOptionsList(printer); setCupsOption(cupsOptions, QStringLiteral("job-hold-until"), - localDateTime.toUTC().time().toString(QStringLiteral("HH:mm"))); - break; + jobHoldUntilArgument); + setCupsOptions(printer, cupsOptions); } - - setCupsOptions(printer, cupsOptions); } void QCUPSSupport::setJobBilling(QPrinter *printer, const QString &jobBilling) |