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) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
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 https://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
24 | ** | - | ||||||
25 | ** GNU General Public License Usage | - | ||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
35 | ** | - | ||||||
36 | ** $QT_END_LICENSE$ | - | ||||||
37 | ** | - | ||||||
38 | ****************************************************************************/ | - | ||||||
39 | - | |||||||
40 | #include "qcups_p.h" | - | ||||||
41 | - | |||||||
42 | #include "qprintengine.h" | - | ||||||
43 | - | |||||||
44 | #ifndef QT_NO_CUPS | - | ||||||
45 | - | |||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||
47 | - | |||||||
48 | QStringList QCUPSSupport::cupsOptionsList(QPrinter *printer) | - | ||||||
49 | { | - | ||||||
50 | return printer->printEngine()->property(PPK_CupsOptions).toStringList(); never executed: return printer->printEngine()->property(QPrintEngine::PrintEnginePropertyKey(0xfe00)).toStringList(); | 0 | ||||||
51 | } | - | ||||||
52 | - | |||||||
53 | void QCUPSSupport::setCupsOptions(QPrinter *printer, const QStringList &cupsOptions) | - | ||||||
54 | { | - | ||||||
55 | printer->printEngine()->setProperty(PPK_CupsOptions, QVariant(cupsOptions)); | - | ||||||
56 | } never executed: end of block | 0 | ||||||
57 | - | |||||||
58 | void QCUPSSupport::setCupsOption(QStringList &cupsOptions, const QString &option, const QString &value) | - | ||||||
59 | { | - | ||||||
60 | if (cupsOptions.contains(option)) {
| 0 | ||||||
61 | cupsOptions.replace(cupsOptions.indexOf(option) + 1, value); | - | ||||||
62 | } else { never executed: end of block | 0 | ||||||
63 | cupsOptions.append(option); | - | ||||||
64 | cupsOptions.append(value); | - | ||||||
65 | } never executed: end of block | 0 | ||||||
66 | } | - | ||||||
67 | - | |||||||
68 | void QCUPSSupport::clearCupsOption(QStringList &cupsOptions, const QString &option) | - | ||||||
69 | { | - | ||||||
70 | // ### use const_iterator once QList::erase takes them | - | ||||||
71 | const QStringList::iterator it = std::find(cupsOptions.begin(), cupsOptions.end(), option); | - | ||||||
72 | if (it != cupsOptions.end()) {
| 0 | ||||||
73 | Q_ASSERT(it + 1 < cupsOptions.end()); | - | ||||||
74 | cupsOptions.erase(it, it+1); | - | ||||||
75 | } never executed: end of block | 0 | ||||||
76 | } never executed: end of block | 0 | ||||||
77 | - | |||||||
78 | static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime) | - | ||||||
79 | { | - | ||||||
80 | switch (jobHold) { | - | ||||||
81 | case QCUPSSupport::Indefinite: never executed: case QCUPSSupport::Indefinite: | 0 | ||||||
82 | 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 | ||||||
83 | case QCUPSSupport::DayTime: never executed: case QCUPSSupport::DayTime: | 0 | ||||||
84 | 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 | ||||||
85 | case QCUPSSupport::Night: never executed: case QCUPSSupport::Night: | 0 | ||||||
86 | 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 | ||||||
87 | case QCUPSSupport::SecondShift: never executed: case QCUPSSupport::SecondShift: | 0 | ||||||
88 | 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 | ||||||
89 | case QCUPSSupport::ThirdShift: never executed: case QCUPSSupport::ThirdShift: | 0 | ||||||
90 | 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 | ||||||
91 | case QCUPSSupport::Weekend: never executed: case QCUPSSupport::Weekend: | 0 | ||||||
92 | 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 | ||||||
93 | case QCUPSSupport::SpecificTime: never executed: case QCUPSSupport::SpecificTime: | 0 | ||||||
94 | if (!holdUntilTime.isNull()) {
| 0 | ||||||
95 | // CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent | - | ||||||
96 | QDateTime localDateTime = QDateTime::currentDateTime(); | - | ||||||
97 | // Check if time is for tomorrow in case of DST change overnight | - | ||||||
98 | if (holdUntilTime < localDateTime.time())
| 0 | ||||||
99 | localDateTime = localDateTime.addDays(1); never executed: localDateTime = localDateTime.addDays(1); | 0 | ||||||
100 | localDateTime.setTime(holdUntilTime); | - | ||||||
101 | 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 | ||||||
102 | } | - | ||||||
103 | // else fall through: | - | ||||||
104 | case QCUPSSupport::NoHold: code before this statement never executed: case QCUPSSupport::NoHold: never executed: case QCUPSSupport::NoHold: | 0 | ||||||
105 | return QString(); never executed: return QString(); | 0 | ||||||
106 | } | - | ||||||
107 | Q_UNREACHABLE(); | - | ||||||
108 | return QString(); never executed: return QString(); | 0 | ||||||
109 | } | - | ||||||
110 | - | |||||||
111 | void QCUPSSupport::setJobHold(QPrinter *printer, const JobHoldUntil jobHold, const QTime &holdUntilTime) | - | ||||||
112 | { | - | ||||||
113 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
114 | const QString jobHoldUntilArgument = jobHoldToString(jobHold, holdUntilTime); | - | ||||||
115 | if (!jobHoldUntilArgument.isEmpty()) {
| 0 | ||||||
116 | setCupsOption(cupsOptions, | - | ||||||
117 | QStringLiteral("job-hold-until"), never executed: return qstring_literal_temp; | 0 | ||||||
118 | jobHoldUntilArgument); | - | ||||||
119 | } else { never executed: end of block | 0 | ||||||
120 | clearCupsOption(cupsOptions, QStringLiteral("job-hold-until")); never executed: return qstring_literal_temp; | 0 | ||||||
121 | } never executed: end of block | 0 | ||||||
122 | setCupsOptions(printer, cupsOptions); | - | ||||||
123 | } never executed: end of block | 0 | ||||||
124 | - | |||||||
125 | void QCUPSSupport::setJobBilling(QPrinter *printer, const QString &jobBilling) | - | ||||||
126 | { | - | ||||||
127 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
128 | setCupsOption(cupsOptions, QStringLiteral("job-billing"), jobBilling); never executed: return qstring_literal_temp; | 0 | ||||||
129 | setCupsOptions(printer, cupsOptions); | - | ||||||
130 | } never executed: end of block | 0 | ||||||
131 | - | |||||||
132 | void QCUPSSupport::setJobPriority(QPrinter *printer, int priority) | - | ||||||
133 | { | - | ||||||
134 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
135 | setCupsOption(cupsOptions, QStringLiteral("job-priority"), QString::number(priority)); never executed: return qstring_literal_temp; | 0 | ||||||
136 | setCupsOptions(printer, cupsOptions); | - | ||||||
137 | } never executed: end of block | 0 | ||||||
138 | - | |||||||
139 | static inline QString bannerPageToString(const QCUPSSupport::BannerPage bannerPage) | - | ||||||
140 | { | - | ||||||
141 | switch (bannerPage) { | - | ||||||
142 | 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 | ||||||
143 | 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 | ||||||
144 | 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 | ||||||
145 | 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 | ||||||
146 | 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 | ||||||
147 | 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 | ||||||
148 | 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 | ||||||
149 | } | - | ||||||
150 | Q_UNREACHABLE(); | - | ||||||
151 | return QString(); never executed: return QString(); | 0 | ||||||
152 | }; | - | ||||||
153 | - | |||||||
154 | void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage) | - | ||||||
155 | { | - | ||||||
156 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
157 | const QString startBanner = bannerPageToString(startBannerPage); | - | ||||||
158 | const QString endBanner = bannerPageToString(endBannerPage); | - | ||||||
159 | - | |||||||
160 | setCupsOption(cupsOptions, QStringLiteral("job-sheets"), startBanner + QLatin1Char(',') + endBanner); never executed: return qstring_literal_temp; | 0 | ||||||
161 | setCupsOptions(printer, cupsOptions); | - | ||||||
162 | } never executed: end of block | 0 | ||||||
163 | - | |||||||
164 | void QCUPSSupport::setPageSet(QPrinter *printer, const PageSet pageSet) | - | ||||||
165 | { | - | ||||||
166 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
167 | QString pageSetString; | - | ||||||
168 | - | |||||||
169 | switch (pageSet) { | - | ||||||
170 | case OddPages: never executed: case OddPages: | 0 | ||||||
171 | pageSetString = QStringLiteral("odd"); never executed: return qstring_literal_temp; | 0 | ||||||
172 | break; never executed: break; | 0 | ||||||
173 | case EvenPages: never executed: case EvenPages: | 0 | ||||||
174 | pageSetString = QStringLiteral("even"); never executed: return qstring_literal_temp; | 0 | ||||||
175 | break; never executed: break; | 0 | ||||||
176 | case AllPages: never executed: case AllPages: | 0 | ||||||
177 | pageSetString = QStringLiteral("all"); never executed: return qstring_literal_temp; | 0 | ||||||
178 | break; never executed: break; | 0 | ||||||
179 | } | - | ||||||
180 | - | |||||||
181 | setCupsOption(cupsOptions, QStringLiteral("page-set"), pageSetString); never executed: return qstring_literal_temp; | 0 | ||||||
182 | setCupsOptions(printer, cupsOptions); | - | ||||||
183 | } never executed: end of block | 0 | ||||||
184 | - | |||||||
185 | void QCUPSSupport::setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet, | - | ||||||
186 | const PagesPerSheetLayout pagesPerSheetLayout) | - | ||||||
187 | { | - | ||||||
188 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
189 | // WARNING: the following trick (with a [2]-extent) only works as | - | ||||||
190 | // WARNING: long as there's only one two-digit number in the list | - | ||||||
191 | // WARNING: and it is the last one (before the "\0")! | - | ||||||
192 | static const char pagesPerSheetData[][2] = { "1", "2", "4", "6", "9", {'1', '6'}, "\0" }; | - | ||||||
193 | static const char pageLayoutData[][5] = {"lrtb", "lrbt", "rlbt", "rltb", "btlr", "btrl", "tblr", "tbrl"}; | - | ||||||
194 | setCupsOption(cupsOptions, QStringLiteral("number-up"), QLatin1String(pagesPerSheetData[pagesPerSheet])); never executed: return qstring_literal_temp; | 0 | ||||||
195 | setCupsOption(cupsOptions, QStringLiteral("number-up-layout"), QLatin1String(pageLayoutData[pagesPerSheetLayout])); never executed: return qstring_literal_temp; | 0 | ||||||
196 | setCupsOptions(printer, cupsOptions); | - | ||||||
197 | } never executed: end of block | 0 | ||||||
198 | - | |||||||
199 | void QCUPSSupport::setPageRange(QPrinter *printer, int pageFrom, int pageTo) | - | ||||||
200 | { | - | ||||||
201 | QStringList cupsOptions = cupsOptionsList(printer); | - | ||||||
202 | 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 | ||||||
203 | setCupsOptions(printer, cupsOptions); | - | ||||||
204 | } never executed: end of block | 0 | ||||||
205 | - | |||||||
206 | QT_END_NAMESPACE | - | ||||||
207 | - | |||||||
208 | #endif // QT_NO_CUPS | - | ||||||
Source code | Switch to Preprocessed file |