| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/kernel/qcups.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qcups_p.h" | - | ||||||
| 35 | - | |||||||
| 36 | #include "qprintengine.h" | - | ||||||
| 37 | - | |||||||
| 38 | #ifndef QT_NO_CUPS | - | ||||||
| 39 | - | |||||||
| 40 | QT_BEGIN_NAMESPACE | - | ||||||
| 41 | - | |||||||
| 42 | QStringList QCUPSSupport::cupsOptionsList(QPrinter *printer) | - | ||||||
| 43 | { | - | ||||||
| 44 | return printer->printEngine()->property(PPK_CupsOptions).toStringList(); never executed: return printer->printEngine()->property(QPrintEngine::PrintEnginePropertyKey(0xfe00)).toStringList(); | 0 | ||||||
| 45 | } | - | ||||||
| 46 | - | |||||||
| 47 | void QCUPSSupport::setCupsOptions(QPrinter *printer, const QStringList &cupsOptions) | - | ||||||
| 48 | { | - | ||||||
| 49 | printer->printEngine()->setProperty(PPK_CupsOptions, QVariant(cupsOptions)); | - | ||||||
| 50 | } never executed: end of block | 0 | ||||||
| 51 | - | |||||||
| 52 | void QCUPSSupport::setCupsOption(QStringList &cupsOptions, const QString &option, const QString &value) | - | ||||||
| 53 | { | - | ||||||
| 54 | if (cupsOptions.contains(option)) {
| 0 | ||||||
| 55 | cupsOptions.replace(cupsOptions.indexOf(option) + 1, value); | - | ||||||
| 56 | } else { never executed: end of block | 0 | ||||||
| 57 | cupsOptions.append(option); | - | ||||||
| 58 | cupsOptions.append(value); | - | ||||||
| 59 | } never executed: end of block | 0 | ||||||
| 60 | } | - | ||||||
| 61 | - | |||||||
| 62 | void QCUPSSupport::clearCupsOption(QStringList &cupsOptions, const QString &option) | - | ||||||
| 63 | { | - | ||||||
| 64 | // ### use const_iterator once QList::erase takes them | - | ||||||
| 65 | const QStringList::iterator it = std::find(cupsOptions.begin(), cupsOptions.end(), option); | - | ||||||
| 66 | if (it != cupsOptions.end()) {
| 0 | ||||||
| 67 | Q_ASSERT(it + 1 < cupsOptions.end()); | - | ||||||
| 68 | cupsOptions.erase(it, it+1); | - | ||||||
| 69 | } never executed: end of block | 0 | ||||||
| 70 | } never executed: end of block | 0 | ||||||
| 71 | - | |||||||
| 72 | static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime) | - | ||||||
| 73 | { | - | ||||||
| 74 | switch (jobHold) { | - | ||||||
| 75 | case QCUPSSupport::Indefinite: never executed: case QCUPSSupport::Indefinite: | 0 | ||||||
| 76 | return QStringLiteral("indefinite"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "indefinite")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "indefinite" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 77 | case QCUPSSupport::DayTime: never executed: case QCUPSSupport::DayTime: | 0 | ||||||
| 78 | return QStringLiteral("day-time"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "day-time")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "day-time" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 79 | case QCUPSSupport::Night: never executed: case QCUPSSupport::Night: | 0 | ||||||
| 80 | return QStringLiteral("night"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "night")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "night" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 81 | case QCUPSSupport::SecondShift: never executed: case QCUPSSupport::SecondShift: | 0 | ||||||
| 82 | return QStringLiteral("second-shift"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "second-shift")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "second-shift" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 83 | case QCUPSSupport::ThirdShift: never executed: case QCUPSSupport::ThirdShift: | 0 | ||||||
| 84 | return QStringLiteral("third-shift"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "third-shift")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "third-shift" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 85 | case QCUPSSupport::Weekend: never executed: case QCUPSSupport::Weekend: | 0 | ||||||
| 86 | return QStringLiteral("weekend"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "weekend")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "weekend" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||
| 87 | case QCUPSSupport::SpecificTime: never executed: case QCUPSSupport::SpecificTime: | 0 | ||||||
| 88 | if (!holdUntilTime.isNull()) {
| 0 | ||||||
| 89 | // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent | - | ||||||
| 90 | QDateTime localDateTime = QDateTime::currentDateTime(); | - | ||||||
| 91 | // Check if time is for tomorrow in case of DST change overnight | - | ||||||
| 92 | if (holdUntilTime < localDateTime.time())
| 0 | ||||||
| 93 | localDateTime = localDateTime.addDays(1); never executed: localDateTime = localDateTime.addDays(1); | 0 | ||||||
| 94 | localDateTime.setTime(holdUntilTime); | - | ||||||
| 95 | return localDateTime.toUTC().time().toString(QStringLiteral("HH:mm")); never executed: return localDateTime.toUTC().time().toString(([]() -> QString { enum { Size = sizeof(u"" "HH:mm")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "HH:mm" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));never executed: return qstring_literal_temp; | 0 | ||||||
| 96 | } | - | ||||||
| 97 | // else fall through: | - | ||||||
| 98 | case QCUPSSupport::NoHold: code before this statement never executed: case QCUPSSupport::NoHold:never executed: case QCUPSSupport::NoHold: | 0 | ||||||
| 99 | return QString(); never executed: return QString(); | 0 | ||||||
| 100 | } | - | ||||||
| 101 | Q_UNREACHABLE(); | - | ||||||
| 102 | return QString(); never executed: return QString(); | 0 | ||||||
| 103 | } | - | ||||||
| 104 | - | |||||||
| 105 | void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) | - | ||||||
| 106 | { | - | ||||||
| 107 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 108 | const QString jobHoldUntilArgument = jobHoldToString(jobHold, holdUntilTime); | - | ||||||
| 109 | if (!jobHoldUntilArgument.isEmpty()) {
| 0 | ||||||
| 110 | setCupsOption(cupsOptions, | - | ||||||
| 111 | QStringLiteral("job-hold-until"), never executed: return qstring_literal_temp; | 0 | ||||||
| 112 | jobHoldUntilArgument); | - | ||||||
| 113 | } else { never executed: end of block | 0 | ||||||
| 114 | clearCupsOption(cupsOptions, QStringLiteral("job-hold-until")); never executed: return qstring_literal_temp; | 0 | ||||||
| 115 | } never executed: end of block | 0 | ||||||
| 116 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 117 | } never executed: end of block | 0 | ||||||
| 118 | - | |||||||
| 119 | void QCUPSSupport::setJobBilling(QPrinter *printer, const QString &jobBilling) | - | ||||||
| 120 | { | - | ||||||
| 121 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 122 | setCupsOption(cupsOptions, QStringLiteral("job-billing"), jobBilling); never executed: return qstring_literal_temp; | 0 | ||||||
| 123 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 124 | } never executed: end of block | 0 | ||||||
| 125 | - | |||||||
| 126 | void QCUPSSupport::setJobPriority(QPrinter *printer, int priority) | - | ||||||
| 127 | { | - | ||||||
| 128 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 129 | setCupsOption(cupsOptions, QStringLiteral("job-priority"), QString::number(priority)); never executed: return qstring_literal_temp; | 0 | ||||||
| 130 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 131 | } never executed: end of block | 0 | ||||||
| 132 | - | |||||||
| 133 | static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPage) | - | ||||||
| 134 | { | - | ||||||
| 135 | switch (bannerPage) { | - | ||||||
| 136 | case QCUPSSupport::NoBanner: return QStringLiteral("none"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "none")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "none" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::NoBanner: | 0 | ||||||
| 137 | case QCUPSSupport::Standard: return QStringLiteral("standard"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "standard")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "standard" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::Standard: | 0 | ||||||
| 138 | case QCUPSSupport::Unclassified: return QStringLiteral("unclassified"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "unclassified")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "unclassified" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::Unclassified: | 0 | ||||||
| 139 | case QCUPSSupport::Confidential: return QStringLiteral("confidential"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "confidential")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "confidential" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::Confidential: | 0 | ||||||
| 140 | case QCUPSSupport::Classified: return QStringLiteral("classified"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "classified")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "classified" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::Classified: | 0 | ||||||
| 141 | case QCUPSSupport::Secret: return QStringLiteral("secret"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "secret")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "secret" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::Secret: | 0 | ||||||
| 142 | case QCUPSSupport::TopSecret: return QStringLiteral("topsecret"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "topsecret")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "topsecret" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp;never executed: case QCUPSSupport::TopSecret: | 0 | ||||||
| 143 | } | - | ||||||
| 144 | Q_UNREACHABLE(); | - | ||||||
| 145 | return QString(); never executed: return QString(); | 0 | ||||||
| 146 | }; | - | ||||||
| 147 | - | |||||||
| 148 | void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage) | - | ||||||
| 149 | { | - | ||||||
| 150 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 151 | const QString startBanner = bannerPageToString(startBannerPage); | - | ||||||
| 152 | const QString endBanner = bannerPageToString(endBannerPage); | - | ||||||
| 153 | - | |||||||
| 154 | setCupsOption(cupsOptions, QStringLiteral("job-sheets"), startBanner + QLatin1Char(',') + endBanner); never executed: return qstring_literal_temp; | 0 | ||||||
| 155 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 156 | } never executed: end of block | 0 | ||||||
| 157 | - | |||||||
| 158 | void QCUPSSupport::setPageSet(QPrinter *printer, const PageSet pageSet) | - | ||||||
| 159 | { | - | ||||||
| 160 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 161 | QString pageSetString; | - | ||||||
| 162 | - | |||||||
| 163 | switch (pageSet) { | - | ||||||
| 164 | case OddPages: never executed: case OddPages: | 0 | ||||||
| 165 | pageSetString = QStringLiteral("odd"); never executed: return qstring_literal_temp; | 0 | ||||||
| 166 | break; never executed: break; | 0 | ||||||
| 167 | case EvenPages: never executed: case EvenPages: | 0 | ||||||
| 168 | pageSetString = QStringLiteral("even"); never executed: return qstring_literal_temp; | 0 | ||||||
| 169 | break; never executed: break; | 0 | ||||||
| 170 | case AllPages: never executed: case AllPages: | 0 | ||||||
| 171 | pageSetString = QStringLiteral("all"); never executed: return qstring_literal_temp; | 0 | ||||||
| 172 | break; never executed: break; | 0 | ||||||
| 173 | } | - | ||||||
| 174 | - | |||||||
| 175 | setCupsOption(cupsOptions, QStringLiteral("page-set"), pageSetString); never executed: return qstring_literal_temp; | 0 | ||||||
| 176 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 177 | } never executed: end of block | 0 | ||||||
| 178 | - | |||||||
| 179 | void QCUPSSupport::setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet, | - | ||||||
| 180 | const PagesPerSheetLayout pagesPerSheetLayout) | - | ||||||
| 181 | { | - | ||||||
| 182 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 183 | // WARNING: the following trick (with a [2]-extent) only works as | - | ||||||
| 184 | // WARNING: long as there's only one two-digit number in the list | - | ||||||
| 185 | // WARNING: and it is the last one (before the "\0")! | - | ||||||
| 186 | static const char pagesPerSheetData[][2] = { "1", "2", "4", "6", "9", {'1', '6'}, "\0" }; | - | ||||||
| 187 | static const char pageLayoutData[][5] = {"lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl"}; | - | ||||||
| 188 | setCupsOption(cupsOptions, QStringLiteral("number-up"), QLatin1String(pagesPerSheetData[pagesPerSheet])); never executed: return qstring_literal_temp; | 0 | ||||||
| 189 | setCupsOption(cupsOptions, QStringLiteral("number-up-layout"), QLatin1String(pageLayoutData[pagesPerSheetLayout])); never executed: return qstring_literal_temp; | 0 | ||||||
| 190 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 191 | } never executed: end of block | 0 | ||||||
| 192 | - | |||||||
| 193 | void QCUPSSupport::setPageRange(QPrinter *printer, int pageFrom, int pageTo) | - | ||||||
| 194 | { | - | ||||||
| 195 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
| 196 | setCupsOption(cupsOptions, QStringLiteral("page-ranges"), QStringLiteral("%1-%2").arg(pageFrom).arg(pageTo)); never executed: return qstring_literal_temp;never executed: return qstring_literal_temp; | 0 | ||||||
| 197 | setCupsOptions(printer, cupsOptions); | - | ||||||
| 198 | } never executed: end of block | 0 | ||||||
| 199 | - | |||||||
| 200 | QT_END_NAMESPACE | - | ||||||
| 201 | - | |||||||
| 202 | #endif // QT_NO_CUPS | - | ||||||
| Source code | Switch to Preprocessed file |