kernel/qcups.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qcups_p.h" -
43 -
44#include <qdebug.h> -
45 -
46#ifndef QT_NO_CUPS -
47 -
48#ifndef QT_LINUXBASE // LSB merges everything into cups.h -
49# include <cups/language.h> -
50#endif -
51#include <qtextcodec.h> -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55typedef int (*CupsGetDests)(cups_dest_t **dests); -
56typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests); -
57typedef const char* (*CupsGetPPD)(const char *printer); -
58typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options); -
59typedef ppd_file_t* (*PPDOpenFile)(const char *filename); -
60typedef void (*PPDMarkDefaults)(ppd_file_t *ppd); -
61typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option); -
62typedef void (*PPDClose)(ppd_file_t *ppd); -
63typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option); -
64typedef void (*CupsFreeOptions)(int num_options, cups_option_t *options); -
65typedef void (*CupsSetDests)(int num_dests, cups_dest_t *dests); -
66typedef cups_lang_t* (*CupsLangGet)(const char *language); -
67typedef const char* (*CupsLangEncoding)(cups_lang_t *language); -
68typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options); -
69typedef int (*CupsTempFd)(char *name, int len); -
70typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options); -
71 -
72static bool cupsLoaded = false; -
73static int qt_cups_num_printers = 0; -
74static CupsGetDests _cupsGetDests = 0; -
75static CupsFreeDests _cupsFreeDests = 0; -
76static CupsGetPPD _cupsGetPPD = 0; -
77static PPDOpenFile _ppdOpenFile = 0; -
78static PPDMarkDefaults _ppdMarkDefaults = 0; -
79static PPDClose _ppdClose = 0; -
80static CupsMarkOptions _cupsMarkOptions = 0; -
81static PPDMarkOption _ppdMarkOption = 0; -
82static CupsFreeOptions _cupsFreeOptions = 0; -
83static CupsSetDests _cupsSetDests = 0; -
84static CupsLangGet _cupsLangGet = 0; -
85static CupsLangEncoding _cupsLangEncoding = 0; -
86static CupsAddOption _cupsAddOption = 0; -
87static CupsTempFd _cupsTempFd = 0; -
88static CupsPrintFile _cupsPrintFile = 0; -
89 -
90static void resolveCups() -
91{ -
92 QLibrary cupsLib(QLatin1String("cups"), 2);
executed (the execution status of this line is deduced): QLibrary cupsLib(QLatin1String("cups"), 2);
-
93 if(cupsLib.load()) {
partially evaluated: cupsLib.load()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
94 _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
executed (the execution status of this line is deduced): _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
-
95 _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
executed (the execution status of this line is deduced): _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
-
96 _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
executed (the execution status of this line is deduced): _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
-
97 _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
executed (the execution status of this line is deduced): _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
-
98 _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
executed (the execution status of this line is deduced): _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
-
99 _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
executed (the execution status of this line is deduced): _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
-
100 _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults");
executed (the execution status of this line is deduced): _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults");
-
101 _ppdClose = (PPDClose) cupsLib.resolve("ppdClose");
executed (the execution status of this line is deduced): _ppdClose = (PPDClose) cupsLib.resolve("ppdClose");
-
102 _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions");
executed (the execution status of this line is deduced): _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions");
-
103 _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption");
executed (the execution status of this line is deduced): _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption");
-
104 _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions");
executed (the execution status of this line is deduced): _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions");
-
105 _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests");
executed (the execution status of this line is deduced): _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests");
-
106 _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
executed (the execution status of this line is deduced): _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
-
107 _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
executed (the execution status of this line is deduced): _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
-
108 _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
executed (the execution status of this line is deduced): _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
-
109 -
110 if (_cupsGetDests && _cupsFreeDests) {
partially evaluated: _cupsGetDests
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
partially evaluated: _cupsFreeDests
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
111 cups_dest_t *printers;
executed (the execution status of this line is deduced): cups_dest_t *printers;
-
112 int num_printers = _cupsGetDests(&printers);
executed (the execution status of this line is deduced): int num_printers = _cupsGetDests(&printers);
-
113 if (num_printers)
partially evaluated: num_printers
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
114 _cupsFreeDests(num_printers, printers);
never executed: _cupsFreeDests(num_printers, printers);
0
115 qt_cups_num_printers = num_printers;
executed (the execution status of this line is deduced): qt_cups_num_printers = num_printers;
-
116 }
executed: }
Execution Count:2
2
117 }
executed: }
Execution Count:2
2
118 cupsLoaded = true;
executed (the execution status of this line is deduced): cupsLoaded = true;
-
119}
executed: }
Execution Count:2
2
120 -
121// ================ CUPS Support class ======================== -
122 -
123QCUPSSupport::QCUPSSupport() -
124 : -
125 prnCount(0), -
126 printers(0), -
127 page_sizes(0), -
128 currPrinterIndex(0), -
129 currPPD(0) -
130{ -
131 if (!cupsLoaded)
never evaluated: !cupsLoaded
0
132 resolveCups();
never executed: resolveCups();
0
133 -
134 // getting all available printers -
135 if (!isAvailable())
never evaluated: !isAvailable()
0
136 return;
never executed: return;
0
137 -
138 qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
never executed (the execution status of this line is deduced): qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
-
139 -
140 for (int i = 0; i < prnCount; ++i) {
never evaluated: i < prnCount
0
141 if (printers[i].is_default) {
never evaluated: printers[i].is_default
0
142 currPrinterIndex = i;
never executed (the execution status of this line is deduced): currPrinterIndex = i;
-
143 setCurrentPrinter(i);
never executed (the execution status of this line is deduced): setCurrentPrinter(i);
-
144 break;
never executed: break;
0
145 } -
146 }
never executed: }
0
147 -
148#ifndef QT_NO_TEXTCODEC -
149 cups_lang_t *cupsLang = _cupsLangGet(0);
never executed (the execution status of this line is deduced): cups_lang_t *cupsLang = _cupsLangGet(0);
-
150 codec = QTextCodec::codecForName(_cupsLangEncoding(cupsLang));
never executed (the execution status of this line is deduced): codec = QTextCodec::codecForName(_cupsLangEncoding(cupsLang));
-
151 if (!codec)
never evaluated: !codec
0
152 codec = QTextCodec::codecForLocale();
never executed: codec = QTextCodec::codecForLocale();
0
153#endif -
154}
never executed: }
0
155 -
156QCUPSSupport::~QCUPSSupport() -
157{ -
158 if (currPPD)
never evaluated: currPPD
0
159 _ppdClose(currPPD);
never executed: _ppdClose(currPPD);
0
160 if (prnCount)
never evaluated: prnCount
0
161 _cupsFreeDests(prnCount, printers);
never executed: _cupsFreeDests(prnCount, printers);
0
162}
never executed: }
0
163 -
164int QCUPSSupport::availablePrintersCount() const -
165{ -
166 return prnCount;
never executed: return prnCount;
0
167} -
168 -
169const cups_dest_t* QCUPSSupport::availablePrinters() const -
170{ -
171 return printers;
never executed: return printers;
0
172} -
173 -
174const ppd_file_t* QCUPSSupport::currentPPD() const -
175{ -
176 return currPPD;
never executed: return currPPD;
0
177} -
178 -
179const ppd_file_t* QCUPSSupport::setCurrentPrinter(int index) -
180{ -
181 Q_ASSERT(index >= 0 && index <= prnCount);
never executed (the execution status of this line is deduced): qt_noop();
-
182 if (index == prnCount)
never evaluated: index == prnCount
0
183 return 0;
never executed: return 0;
0
184 -
185 currPrinterIndex = index;
never executed (the execution status of this line is deduced): currPrinterIndex = index;
-
186 -
187 if (currPPD)
never evaluated: currPPD
0
188 _ppdClose(currPPD);
never executed: _ppdClose(currPPD);
0
189 currPPD = 0;
never executed (the execution status of this line is deduced): currPPD = 0;
-
190 page_sizes = 0;
never executed (the execution status of this line is deduced): page_sizes = 0;
-
191 -
192 const char *ppdFile = _cupsGetPPD(printers[index].name);
never executed (the execution status of this line is deduced): const char *ppdFile = _cupsGetPPD(printers[index].name);
-
193 -
194 if (!ppdFile)
never evaluated: !ppdFile
0
195 return 0;
never executed: return 0;
0
196 -
197 currPPD = _ppdOpenFile(ppdFile);
never executed (the execution status of this line is deduced): currPPD = _ppdOpenFile(ppdFile);
-
198 unlink(ppdFile);
never executed (the execution status of this line is deduced): unlink(ppdFile);
-
199 -
200 // marking default options -
201 _ppdMarkDefaults(currPPD);
never executed (the execution status of this line is deduced): _ppdMarkDefaults(currPPD);
-
202 -
203 // marking options explicitly set -
204 _cupsMarkOptions(currPPD, printers[currPrinterIndex].num_options, printers[currPrinterIndex].options);
never executed (the execution status of this line is deduced): _cupsMarkOptions(currPPD, printers[currPrinterIndex].num_options, printers[currPrinterIndex].options);
-
205 -
206 // getting pointer to page sizes -
207 page_sizes = ppdOption("PageSize");
never executed (the execution status of this line is deduced): page_sizes = ppdOption("PageSize");
-
208 -
209 return currPPD;
never executed: return currPPD;
0
210} -
211 -
212int QCUPSSupport::currentPrinterIndex() const -
213{ -
214 return currPrinterIndex;
never executed: return currPrinterIndex;
0
215} -
216 -
217bool QCUPSSupport::isAvailable() -
218{ -
219 if(!cupsLoaded)
evaluated: !cupsLoaded
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:117
2-117
220 resolveCups();
executed: resolveCups();
Execution Count:2
2
221 -
222 return _cupsGetDests &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
223 _cupsFreeDests &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
224 _cupsGetPPD &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
225 _ppdOpenFile &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
226 _ppdMarkDefaults &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
227 _ppdClose &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
228 _cupsMarkOptions &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
229 _ppdMarkOption &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
230 _cupsFreeOptions &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
231 _cupsSetDests &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
232 _cupsLangGet &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
233 _cupsLangEncoding &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
234 _cupsAddOption &&
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
235 (qt_cups_num_printers > 0);
executed: return _cupsGetDests && _cupsFreeDests && _cupsGetPPD && _ppdOpenFile && _ppdMarkDefaults && _ppdClose && _cupsMarkOptions && _ppdMarkOption && _cupsFreeOptions && _cupsSetDests && _cupsLangGet && _cupsLangEncoding && _cupsAddOption && (qt_cups_num_printers > 0);
Execution Count:119
119
236} -
237 -
238const ppd_option_t* QCUPSSupport::ppdOption(const char *key) const -
239{ -
240 if (currPPD) {
never evaluated: currPPD
0
241 for (int gr = 0; gr < currPPD->num_groups; ++gr) {
never evaluated: gr < currPPD->num_groups
0
242 for (int opt = 0; opt < currPPD->groups[gr].num_options; ++opt) {
never evaluated: opt < currPPD->groups[gr].num_options
0
243 if (qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0)
never evaluated: qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0
0
244 return &currPPD->groups[gr].options[opt];
never executed: return &currPPD->groups[gr].options[opt];
0
245 }
never executed: }
0
246 }
never executed: }
0
247 }
never executed: }
0
248 return 0;
never executed: return 0;
0
249} -
250 -
251const cups_option_t* QCUPSSupport::printerOption(const QString &key) const -
252{ -
253 for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) {
never evaluated: i < printers[currPrinterIndex].num_options
0
254 if (QLatin1String(printers[currPrinterIndex].options[i].name) == key)
never evaluated: QLatin1String(printers[currPrinterIndex].options[i].name) == key
0
255 return &printers[currPrinterIndex].options[i];
never executed: return &printers[currPrinterIndex].options[i];
0
256 }
never executed: }
0
257 return 0;
never executed: return 0;
0
258} -
259 -
260const ppd_option_t* QCUPSSupport::pageSizes() const -
261{ -
262 return page_sizes;
never executed: return page_sizes;
0
263} -
264 -
265int QCUPSSupport::markOption(const char* name, const char* value) -
266{ -
267 return _ppdMarkOption(currPPD, name, value);
never executed: return _ppdMarkOption(currPPD, name, value);
0
268} -
269 -
270void QCUPSSupport::saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions) -
271{ -
272 int oldOptionCount = printers[currPrinterIndex].num_options;
never executed (the execution status of this line is deduced): int oldOptionCount = printers[currPrinterIndex].num_options;
-
273 cups_option_t* oldOptions = printers[currPrinterIndex].options;
never executed (the execution status of this line is deduced): cups_option_t* oldOptions = printers[currPrinterIndex].options;
-
274 -
275 int newOptionCount = 0;
never executed (the execution status of this line is deduced): int newOptionCount = 0;
-
276 cups_option_t* newOptions = 0;
never executed (the execution status of this line is deduced): cups_option_t* newOptions = 0;
-
277 -
278 // copying old options that are not on the new list -
279 for (int i = 0; i < oldOptionCount; ++i) {
never evaluated: i < oldOptionCount
0
280 bool contains = false;
never executed (the execution status of this line is deduced): bool contains = false;
-
281 for (int j = 0; j < options.count(); ++j) {
never evaluated: j < options.count()
0
282 if (qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0) {
never evaluated: qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0
0
283 contains = true;
never executed (the execution status of this line is deduced): contains = true;
-
284 break;
never executed: break;
0
285 } -
286 }
never executed: }
0
287 -
288 if (!contains) {
never evaluated: !contains
0
289 newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions);
never executed (the execution status of this line is deduced): newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions);
-
290 }
never executed: }
0
291 }
never executed: }
0
292 -
293 // we can release old option list -
294 _cupsFreeOptions(oldOptionCount, oldOptions);
never executed (the execution status of this line is deduced): _cupsFreeOptions(oldOptionCount, oldOptions);
-
295 -
296 // adding marked options -
297 for (int i = 0; i < markedOptions.count(); ++i) {
never evaluated: i < markedOptions.count()
0
298 const char* name = markedOptions.at(i);
never executed (the execution status of this line is deduced): const char* name = markedOptions.at(i);
-
299 ++i;
never executed (the execution status of this line is deduced): ++i;
-
300 newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions);
never executed (the execution status of this line is deduced): newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions);
-
301 }
never executed: }
0
302 -
303 // placing the new option list -
304 printers[currPrinterIndex].num_options = newOptionCount;
never executed (the execution status of this line is deduced): printers[currPrinterIndex].num_options = newOptionCount;
-
305 printers[currPrinterIndex].options = newOptions;
never executed (the execution status of this line is deduced): printers[currPrinterIndex].options = newOptions;
-
306 -
307 // saving new default values -
308 _cupsSetDests(prnCount, printers);
never executed (the execution status of this line is deduced): _cupsSetDests(prnCount, printers);
-
309}
never executed: }
0
310 -
311QRect QCUPSSupport::paperRect(const char *choice) const -
312{ -
313 if (!currPPD)
never evaluated: !currPPD
0
314 return QRect();
never executed: return QRect();
0
315 for (int i = 0; i < currPPD->num_sizes; ++i) {
never evaluated: i < currPPD->num_sizes
0
316 if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
never evaluated: qstrcmp(currPPD->sizes[i].name, choice) == 0
0
317 return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length));
never executed: return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length));
0
318 }
never executed: }
0
319 return QRect();
never executed: return QRect();
0
320} -
321 -
322QRect QCUPSSupport::pageRect(const char *choice) const -
323{ -
324 if (!currPPD)
never evaluated: !currPPD
0
325 return QRect();
never executed: return QRect();
0
326 for (int i = 0; i < currPPD->num_sizes; ++i) {
never evaluated: i < currPPD->num_sizes
0
327 if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
never evaluated: qstrcmp(currPPD->sizes[i].name, choice) == 0
0
328 return QRect(qRound(currPPD->sizes[i].left),
never executed: return QRect(qRound(currPPD->sizes[i].left), qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
0
329 qRound(currPPD->sizes[i].length - currPPD->sizes[i].top),
never executed: return QRect(qRound(currPPD->sizes[i].left), qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
0
330 qRound(currPPD->sizes[i].right - currPPD->sizes[i].left),
never executed: return QRect(qRound(currPPD->sizes[i].left), qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
0
331 qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
never executed: return QRect(qRound(currPPD->sizes[i].left), qRound(currPPD->sizes[i].length - currPPD->sizes[i].top), qRound(currPPD->sizes[i].right - currPPD->sizes[i].left), qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
0
332 }
never executed: }
0
333 return QRect();
never executed: return QRect();
0
334} -
335 -
336QStringList QCUPSSupport::options() const -
337{ -
338 QStringList list;
never executed (the execution status of this line is deduced): QStringList list;
-
339 collectMarkedOptions(list);
never executed (the execution status of this line is deduced): collectMarkedOptions(list);
-
340 return list;
never executed: return list;
0
341} -
342 -
343bool QCUPSSupport::printerHasPPD(const char *printerName) -
344{ -
345 if (!isAvailable())
never evaluated: !isAvailable()
0
346 return false;
never executed: return false;
0
347 const char *ppdFile = _cupsGetPPD(printerName);
never executed (the execution status of this line is deduced): const char *ppdFile = _cupsGetPPD(printerName);
-
348 if (ppdFile)
never evaluated: ppdFile
0
349 unlink(ppdFile);
never executed: unlink(ppdFile);
0
350 return (ppdFile != 0);
never executed: return (ppdFile != 0);
0
351} -
352 -
353QString QCUPSSupport::unicodeString(const char *s) -
354{ -
355#ifndef QT_NO_TEXTCODEC -
356 return codec->toUnicode(s);
never executed: return codec->toUnicode(s);
0
357#else -
358 return QLatin1String(s); -
359#endif -
360} -
361 -
362void QCUPSSupport::collectMarkedOptions(QStringList& list, const ppd_group_t* group) const -
363{ -
364 if (group == 0) {
never evaluated: group == 0
0
365 if (!currPPD)
never evaluated: !currPPD
0
366 return;
never executed: return;
0
367 for (int i = 0; i < currPPD->num_groups; ++i) {
never evaluated: i < currPPD->num_groups
0
368 collectMarkedOptions(list, &currPPD->groups[i]);
never executed (the execution status of this line is deduced): collectMarkedOptions(list, &currPPD->groups[i]);
-
369 collectMarkedOptionsHelper(list, &currPPD->groups[i]);
never executed (the execution status of this line is deduced): collectMarkedOptionsHelper(list, &currPPD->groups[i]);
-
370 }
never executed: }
0
371 } else {
never executed: }
0
372 for (int i = 0; i < group->num_subgroups; ++i)
never evaluated: i < group->num_subgroups
0
373 collectMarkedOptionsHelper(list, &group->subgroups[i]);
never executed: collectMarkedOptionsHelper(list, &group->subgroups[i]);
0
374 }
never executed: }
0
375} -
376 -
377void QCUPSSupport::collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const -
378{ -
379 for (int i = 0; i < group->num_options; ++i) {
never evaluated: i < group->num_options
0
380 for (int j = 0; j < group->options[i].num_choices; ++j) {
never evaluated: j < group->options[i].num_choices
0
381 if (group->options[i].choices[j].marked == 1 && qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0)
never evaluated: group->options[i].choices[j].marked == 1
never evaluated: qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0
0
382 list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice);
never executed: list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice);
0
383 }
never executed: }
0
384 }
never executed: }
0
385}
never executed: }
0
386 -
387QPair<int, QString> QCUPSSupport::tempFd() -
388{ -
389 char filename[512];
never executed (the execution status of this line is deduced): char filename[512];
-
390 int fd = _cupsTempFd(filename, 512);
never executed (the execution status of this line is deduced): int fd = _cupsTempFd(filename, 512);
-
391 return QPair<int, QString>(fd, QString::fromLocal8Bit(filename));
never executed: return QPair<int, QString>(fd, QString::fromLocal8Bit(filename));
0
392} -
393 -
394// Prints the given file and returns a job id. -
395int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title, -
396 int num_options, cups_option_t * options) -
397{ -
398 return _cupsPrintFile(printerName, filename, title, num_options, options);
never executed: return _cupsPrintFile(printerName, filename, title, num_options, options);
0
399} -
400 -
401QCUPSSupport::Printer::Printer(const QString &n) : name(n), isDefault(false), cupsPrinterIndex(-1) -
402{ -
403}
never executed: }
0
404 -
405QList<QCUPSSupport::Printer> QCUPSSupport::availableUnixPrinters() -
406{ -
407 QList<Printer> printers;
never executed (the execution status of this line is deduced): QList<Printer> printers;
-
408 -
409 if (QCUPSSupport::isAvailable()) {
never evaluated: QCUPSSupport::isAvailable()
0
410 QCUPSSupport cups;
never executed (the execution status of this line is deduced): QCUPSSupport cups;
-
411 int cupsPrinterCount = cups.availablePrintersCount();
never executed (the execution status of this line is deduced): int cupsPrinterCount = cups.availablePrintersCount();
-
412 const cups_dest_t* cupsPrinters = cups.availablePrinters();
never executed (the execution status of this line is deduced): const cups_dest_t* cupsPrinters = cups.availablePrinters();
-
413 for (int i = 0; i < cupsPrinterCount; ++i) {
never evaluated: i < cupsPrinterCount
0
414 QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
never executed (the execution status of this line is deduced): QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
-
415 if (cupsPrinters[i].instance)
never evaluated: cupsPrinters[i].instance
0
416 printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
never executed: printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
0
417 -
418 Printer p(printerName);
never executed (the execution status of this line is deduced): Printer p(printerName);
-
419 if (cupsPrinters[i].is_default)
never evaluated: cupsPrinters[i].is_default
0
420 p.isDefault = true;
never executed: p.isDefault = true;
0
421 p.cupsPrinterIndex = i;
never executed (the execution status of this line is deduced): p.cupsPrinterIndex = i;
-
422 printers.append(p);
never executed (the execution status of this line is deduced): printers.append(p);
-
423 }
never executed: }
0
424 }
never executed: }
0
425 -
426 return printers;
never executed: return printers;
0
427} -
428 -
429// preserve names in ascending order for the binary search -
430static const struct NamedPaperSize { -
431 const char *const name; -
432 QPrinter::PaperSize size; -
433} named_sizes_map[QPrinter::NPageSize] = { -
434 { "A0", QPrinter::A0 }, -
435 { "A1", QPrinter::A1 }, -
436 { "A2", QPrinter::A2 }, -
437 { "A3", QPrinter::A3 }, -
438 { "A4", QPrinter::A4 }, -
439 { "A5", QPrinter::A5 }, -
440 { "A6", QPrinter::A6 }, -
441 { "A7", QPrinter::A7 }, -
442 { "A8", QPrinter::A8 }, -
443 { "A9", QPrinter::A9 }, -
444 { "B0", QPrinter::B0 }, -
445 { "B1", QPrinter::B1 }, -
446 { "B10", QPrinter::B10 }, -
447 { "B2", QPrinter::B2 }, -
448 { "B4", QPrinter::B4 }, -
449 { "B5", QPrinter::B5 }, -
450 { "B6", QPrinter::B6 }, -
451 { "B7", QPrinter::B7 }, -
452 { "B8", QPrinter::B8 }, -
453 { "B9", QPrinter::B9 }, -
454 { "C5E", QPrinter::C5E }, -
455 { "Comm10E", QPrinter::Comm10E }, -
456 { "Custom", QPrinter::Custom }, -
457 { "DLE", QPrinter::DLE }, -
458 { "Executive", QPrinter::Executive }, -
459 { "Folio", QPrinter::Folio }, -
460 { "Ledger", QPrinter::Ledger }, -
461 { "Legal", QPrinter::Legal }, -
462 { "Letter", QPrinter::Letter }, -
463 { "Tabloid", QPrinter::Tabloid } -
464}; -
465 -
466inline bool operator<(const char *name, const NamedPaperSize &data) -
467{ return qstrcmp(name, data.name) < 0; }
never executed: return qstrcmp(name, data.name) < 0;
0
468inline bool operator<(const NamedPaperSize &data, const char *name) -
469{ return qstrcmp(data.name, name) < 0; }
never executed: return qstrcmp(data.name, name) < 0;
0
470 -
471static inline QPrinter::PaperSize string2PaperSize(const char *name) -
472{ -
473 const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name);
never executed (the execution status of this line is deduced): const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name);
-
474 if (r - named_sizes_map != QPrinter::NPageSize)
never evaluated: r - named_sizes_map != QPrinter::NPageSize
0
475 return r->size;
never executed: return r->size;
0
476 return QPrinter::Custom;
never executed: return QPrinter::Custom;
0
477} -
478 -
479static inline const char *paperSize2String(QPrinter::PaperSize size) -
480{ -
481 for (int i = 0; i < QPrinter::NPageSize; ++i) {
never evaluated: i < QPrinter::NPageSize
0
482 if (size == named_sizes_map[i].size)
never evaluated: size == named_sizes_map[i].size
0
483 return named_sizes_map[i].name;
never executed: return named_sizes_map[i].name;
0
484 }
never executed: }
0
485 return 0;
never executed: return 0;
0
486} -
487 -
488QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinterIndex) -
489{ -
490 QList<QPrinter::PaperSize> result;
never executed (the execution status of this line is deduced): QList<QPrinter::PaperSize> result;
-
491 if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
never evaluated: !QCUPSSupport::isAvailable()
never evaluated: cupsPrinterIndex < 0
0
492 return result;
never executed: return result;
0
493 // Find paper sizes from CUPS. -
494 QCUPSSupport cups;
never executed (the execution status of this line is deduced): QCUPSSupport cups;
-
495 cups.setCurrentPrinter(cupsPrinterIndex);
never executed (the execution status of this line is deduced): cups.setCurrentPrinter(cupsPrinterIndex);
-
496 if (const ppd_option_t* size = cups.pageSizes()) {
never evaluated: const ppd_option_t* size = cups.pageSizes()
0
497 for (int j = 0; j < size->num_choices; ++j)
never evaluated: j < size->num_choices
0
498 result.append(string2PaperSize(size->choices[j].choice));
never executed: result.append(string2PaperSize(size->choices[j].choice));
0
499 }
never executed: }
0
500 return result;
never executed: return result;
0
501} -
502 -
503QT_END_NAMESPACE -
504 -
505#endif // QT_NO_CUPS -
506 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial