0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qprinterinfo.h"
|
|
43 |
|
|
44 |
#include <qfile.h>
|
|
45 |
#include <qfileinfo.h>
|
|
46 |
#include <qdir.h>
|
|
47 |
#include <qprintdialog.h>
|
|
48 |
#include <qlibrary.h>
|
|
49 |
#include <qtextstream.h>
|
|
50 |
|
|
51 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
|
52 |
# include <private/qcups_p.h>
|
|
53 |
# include <cups/cups.h>
|
|
54 |
# include <private/qpdf_p.h>
|
|
55 |
#endif
|
|
56 |
|
|
57 |
#include <private/qprinterinfo_unix_p.h>
|
|
58 |
|
|
59 |
QT_BEGIN_NAMESPACE
|
|
60 |
|
|
61 |
#ifndef QT_NO_PRINTER
|
|
62 |
|
|
63 |
class QPrinterInfoPrivate
|
|
64 |
{
|
|
65 |
Q_DECLARE_PUBLIC(QPrinterInfo)
|
|
66 |
public:
|
|
67 |
QPrinterInfoPrivate();
|
|
68 |
QPrinterInfoPrivate(const QString& name);
|
|
69 |
~QPrinterInfoPrivate();
|
|
70 |
|
|
71 |
static QPrinter::PaperSize string2PaperSize(const QString& str);
|
|
72 |
static QString pageSize2String(QPrinter::PaperSize size);
|
|
73 |
|
|
74 |
private:
|
|
75 |
QString m_name;
|
|
76 |
bool m_isNull;
|
|
77 |
bool m_default;
|
|
78 |
QList<QPrinter::PaperSize> m_paperSizes;
|
|
79 |
|
|
80 |
QPrinterInfo* q_ptr;
|
|
81 |
};
|
|
82 |
|
|
83 |
static QPrinterInfoPrivate nullQPrinterInfoPrivate;
|
|
84 |
|
|
85 |
class QPrinterInfoPrivateDeleter
|
|
86 |
{
|
|
87 |
public:
|
|
88 |
static inline void cleanup(QPrinterInfoPrivate *d)
|
|
89 |
{
|
|
90 |
if (d != &nullQPrinterInfoPrivate)
|
|
91 |
delete d;
|
|
92 |
}
|
|
93 |
};
|
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////
|
|
96 |
/////////////////////////////////////////////////////////////////////////////
|
|
97 |
|
|
98 |
void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name,
|
|
99 |
QString host, QString comment,
|
|
100 |
QStringList aliases)
|
|
101 |
{
|
|
102 |
for (int i = 0; i < printers->size(); ++i)
|
|
103 |
if (printers->at(i).samePrinter(name))
|
|
104 |
return;
|
|
105 |
|
|
106 |
#ifndef QT_NO_PRINTDIALOG
|
|
107 |
if (host.isEmpty())
|
|
108 |
host = QPrintDialog::tr("locally connected");
|
|
109 |
#endif
|
|
110 |
printers->append(QPrinterDescription(name.simplified(), host.simplified(), comment.simplified(), aliases));
|
|
111 |
}
|
|
112 |
|
|
113 |
void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printers)
|
|
114 |
{
|
|
115 |
if (printerDesc.length() < 1)
|
|
116 |
return;
|
|
117 |
|
|
118 |
printerDesc = printerDesc.simplified();
|
|
119 |
int i = printerDesc.indexOf(QLatin1Char(':'));
|
|
120 |
QString printerName, printerComment, printerHost;
|
|
121 |
QStringList aliases;
|
|
122 |
|
|
123 |
if (i >= 0) {
|
|
124 |
// have ':' want '|'
|
|
125 |
int j = printerDesc.indexOf(QLatin1Char('|'));
|
|
126 |
if (j > 0 && j < i) {
|
|
127 |
printerName = printerDesc.left(j);
|
|
128 |
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
|
|
129 |
#ifndef QT_NO_PRINTDIALOG
|
|
130 |
// try extracting a comment from the aliases
|
|
131 |
printerComment = QPrintDialog::tr("Aliases: %1")
|
|
132 |
.arg(aliases.join(QLatin1String(", ")));
|
|
133 |
#endif
|
|
134 |
} else {
|
|
135 |
printerName = printerDesc.left(i);
|
|
136 |
}
|
|
137 |
// look for lprng pseudo all printers entry
|
|
138 |
i = printerDesc.indexOf(QRegExp(QLatin1String(": *all *=")));
|
|
139 |
if (i >= 0)
|
|
140 |
printerName = QString();
|
|
141 |
// look for signs of this being a remote printer
|
|
142 |
i = printerDesc.indexOf(QRegExp(QLatin1String(": *rm *=")));
|
|
143 |
if (i >= 0) {
|
|
144 |
// point k at the end of remote host name
|
|
145 |
while (printerDesc[i] != QLatin1Char('='))
|
|
146 |
i++;
|
|
147 |
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
|
|
148 |
i++;
|
|
149 |
j = i;
|
|
150 |
while (j < (int)printerDesc.length() && printerDesc[j] != QLatin1Char(':'))
|
|
151 |
j++;
|
|
152 |
|
|
153 |
// and stuff that into the string
|
|
154 |
printerHost = printerDesc.mid(i, j - i);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
if (printerName.length())
|
|
158 |
qt_perhapsAddPrinter(printers, printerName, printerHost, printerComment,
|
|
159 |
aliases);
|
|
160 |
}
|
|
161 |
|
|
162 |
int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName)
|
|
163 |
{
|
|
164 |
QFile printcap(fileName);
|
|
165 |
if (!printcap.open(QIODevice::ReadOnly))
|
|
166 |
return NotFound;
|
|
167 |
|
|
168 |
char *line_ascii = new char[1025];
|
|
169 |
line_ascii[1024] = '\0';
|
|
170 |
|
|
171 |
QString printerDesc;
|
|
172 |
bool atEnd = false;
|
|
173 |
|
|
174 |
while (!atEnd) {
|
|
175 |
if (printcap.atEnd() || printcap.readLine(line_ascii, 1024) <= 0)
|
|
176 |
atEnd = true;
|
|
177 |
QString line = QString::fromLocal8Bit(line_ascii);
|
|
178 |
line = line.trimmed();
|
|
179 |
if (line.length() >= 1 && line[int(line.length()) - 1] == QLatin1Char('\\'))
|
|
180 |
line.chop(1);
|
|
181 |
if (line[0] == QLatin1Char('#')) {
|
|
182 |
if (!atEnd)
|
|
183 |
continue;
|
|
184 |
} else if (line[0] == QLatin1Char('|') || line[0] == QLatin1Char(':')
|
|
185 |
|| line.isEmpty()) {
|
|
186 |
printerDesc += line;
|
|
187 |
if (!atEnd)
|
|
188 |
continue;
|
|
189 |
}
|
|
190 |
|
|
191 |
qt_parsePrinterDesc(printerDesc, printers);
|
|
192 |
|
|
193 |
// add the first line of the new printer definition
|
|
194 |
printerDesc = line;
|
|
195 |
}
|
|
196 |
delete[] line_ascii;
|
|
197 |
return Success;
|
|
198 |
}
|
|
199 |
|
|
200 |
/*!
|
|
201 |
\internal
|
|
202 |
|
|
203 |
Checks $HOME/.printers for a line matching '_default <name>' (where
|
|
204 |
<name> does not contain any white space). The first such match
|
|
205 |
results in <name> being returned.
|
|
206 |
If no lines match then an empty string is returned.
|
|
207 |
*/
|
|
208 |
QString qt_getDefaultFromHomePrinters()
|
|
209 |
{
|
|
210 |
QFile file(QDir::homePath() + QLatin1String("/.printers"));
|
|
211 |
if (!file.open(QIODevice::ReadOnly))
|
|
212 |
return QString();
|
|
213 |
QString all(QLatin1String(file.readAll()));
|
|
214 |
QStringList words = all.split(QRegExp(QLatin1String("\\W+")), QString::SkipEmptyParts);
|
|
215 |
const int i = words.indexOf(QLatin1String("_default"));
|
|
216 |
if (i != -1 && i < words.size() - 1)
|
|
217 |
return words.at(i + 1);
|
|
218 |
return QString();
|
|
219 |
}
|
|
220 |
|
|
221 |
// solaris, not 2.6
|
|
222 |
void qt_parseEtcLpPrinters(QList<QPrinterDescription> *printers)
|
|
223 |
{
|
|
224 |
QDir lp(QLatin1String("/etc/lp/printers"));
|
|
225 |
QFileInfoList dirs = lp.entryInfoList();
|
|
226 |
if (dirs.isEmpty())
|
|
227 |
return;
|
|
228 |
|
|
229 |
QString tmp;
|
|
230 |
for (int i = 0; i < dirs.size(); ++i) {
|
|
231 |
QFileInfo printer = dirs.at(i);
|
|
232 |
if (printer.isDir()) {
|
|
233 |
tmp.sprintf("/etc/lp/printers/%s/configuration",
|
|
234 |
printer.fileName().toAscii().data());
|
|
235 |
QFile configuration(tmp);
|
|
236 |
char *line = new char[1025];
|
|
237 |
QString remote(QLatin1String("Remote:"));
|
|
238 |
QString contentType(QLatin1String("Content types:"));
|
|
239 |
QString printerHost;
|
|
240 |
bool canPrintPostscript = false;
|
|
241 |
if (configuration.open(QIODevice::ReadOnly)) {
|
|
242 |
while (!configuration.atEnd() &&
|
|
243 |
configuration.readLine(line, 1024) > 0) {
|
|
244 |
if (QString::fromLatin1(line).startsWith(remote)) {
|
|
245 |
const char *p = line;
|
|
246 |
while (*p != ':')
|
|
247 |
p++;
|
|
248 |
p++;
|
|
249 |
while (isspace((uchar) *p))
|
|
250 |
p++;
|
|
251 |
printerHost = QString::fromLocal8Bit(p);
|
|
252 |
printerHost = printerHost.simplified();
|
|
253 |
} else if (QString::fromLatin1(line).startsWith(contentType)) {
|
|
254 |
char *p = line;
|
|
255 |
while (*p != ':')
|
|
256 |
p++;
|
|
257 |
p++;
|
|
258 |
char *e;
|
|
259 |
while (*p) {
|
|
260 |
while (isspace((uchar) *p))
|
|
261 |
p++;
|
|
262 |
if (*p) {
|
|
263 |
char s;
|
|
264 |
e = p;
|
|
265 |
while (isalnum((uchar) *e))
|
|
266 |
e++;
|
|
267 |
s = *e;
|
|
268 |
*e = '\0';
|
|
269 |
if (!qstrcmp(p, "postscript") ||
|
|
270 |
!qstrcmp(p, "any"))
|
|
271 |
canPrintPostscript = true;
|
|
272 |
*e = s;
|
|
273 |
if (s == ',')
|
|
274 |
e++;
|
|
275 |
p = e;
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
}
|
|
280 |
if (canPrintPostscript)
|
|
281 |
qt_perhapsAddPrinter(printers, printer.fileName(),
|
|
282 |
printerHost, QLatin1String(""));
|
|
283 |
}
|
|
284 |
delete[] line;
|
|
285 |
}
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
// solaris 2.6
|
|
290 |
char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found)
|
|
291 |
{
|
|
292 |
QFile pc(QLatin1String("/etc/printers.conf"));
|
|
293 |
if (!pc.open(QIODevice::ReadOnly)) {
|
|
294 |
if (found)
|
|
295 |
*found = false;
|
|
296 |
return 0;
|
|
297 |
}
|
|
298 |
if (found)
|
|
299 |
*found = true;
|
|
300 |
|
|
301 |
char *line = new char[1025];
|
|
302 |
line[1024] = '\0';
|
|
303 |
|
|
304 |
QString printerDesc;
|
|
305 |
int lineLength = 0;
|
|
306 |
|
|
307 |
char *defaultPrinter = 0;
|
|
308 |
|
|
309 |
while (!pc.atEnd() &&
|
|
310 |
(lineLength=pc.readLine(line, 1024)) > 0) {
|
|
311 |
if (*line == '#') {
|
|
312 |
*line = '\0';
|
|
313 |
lineLength = 0;
|
|
314 |
}
|
|
315 |
if (lineLength >= 2 && line[lineLength-2] == '\\') {
|
|
316 |
line[lineLength-2] = '\0';
|
|
317 |
printerDesc += QString::fromLocal8Bit(line);
|
|
318 |
} else {
|
|
319 |
printerDesc += QString::fromLocal8Bit(line);
|
|
320 |
printerDesc = printerDesc.simplified();
|
|
321 |
int i = printerDesc.indexOf(QLatin1Char(':'));
|
|
322 |
QString printerName, printerHost, printerComment;
|
|
323 |
QStringList aliases;
|
|
324 |
if (i >= 0) {
|
|
325 |
// have : want |
|
|
326 |
int j = printerDesc.indexOf(QLatin1Char('|'));
|
|
327 |
if (j >= i)
|
|
328 |
j = -1;
|
|
329 |
printerName = printerDesc.mid(0, j < 0 ? i : j);
|
|
330 |
if (printerName == QLatin1String("_default")) {
|
|
331 |
i = printerDesc.indexOf(
|
|
332 |
QRegExp(QLatin1String(": *use *=")));
|
|
333 |
while (printerDesc[i] != QLatin1Char('='))
|
|
334 |
i++;
|
|
335 |
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
|
|
336 |
i++;
|
|
337 |
j = i;
|
|
338 |
while (j < (int)printerDesc.length() &&
|
|
339 |
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
|
|
340 |
j++;
|
|
341 |
// that's our default printer
|
|
342 |
defaultPrinter =
|
|
343 |
qstrdup(printerDesc.mid(i, j-i).toAscii().data());
|
|
344 |
printerName = QString();
|
|
345 |
printerDesc = QString();
|
|
346 |
} else if (printerName == QLatin1String("_all")) {
|
|
347 |
// skip it.. any other cases we want to skip?
|
|
348 |
printerName = QString();
|
|
349 |
printerDesc = QString();
|
|
350 |
}
|
|
351 |
|
|
352 |
if (j > 0) {
|
|
353 |
// try extracting a comment from the aliases
|
|
354 |
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
|
|
355 |
#ifndef QT_NO_PRINTDIALOG
|
|
356 |
printerComment = QPrintDialog::tr("Aliases: %1")
|
|
357 |
.arg(aliases.join(QLatin1String(", ")));
|
|
358 |
#endif
|
|
359 |
}
|
|
360 |
// look for signs of this being a remote printer
|
|
361 |
i = printerDesc.indexOf(
|
|
362 |
QRegExp(QLatin1String(": *bsdaddr *=")));
|
|
363 |
if (i >= 0) {
|
|
364 |
// point k at the end of remote host name
|
|
365 |
while (printerDesc[i] != QLatin1Char('='))
|
|
366 |
i++;
|
|
367 |
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
|
|
368 |
i++;
|
|
369 |
j = i;
|
|
370 |
while (j < (int)printerDesc.length() &&
|
|
371 |
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
|
|
372 |
j++;
|
|
373 |
// and stuff that into the string
|
|
374 |
printerHost = printerDesc.mid(i, j-i);
|
|
375 |
// maybe stick the remote printer name into the comment
|
|
376 |
if (printerDesc[j] == QLatin1Char(',')) {
|
|
377 |
i = ++j;
|
|
378 |
while (printerDesc[i].isSpace())
|
|
379 |
i++;
|
|
380 |
j = i;
|
|
381 |
while (j < (int)printerDesc.length() &&
|
|
382 |
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
|
|
383 |
j++;
|
|
384 |
if (printerName != printerDesc.mid(i, j-i)) {
|
|
385 |
printerComment =
|
|
386 |
QLatin1String("Remote name: ");
|
|
387 |
printerComment += printerDesc.mid(i, j-i);
|
|
388 |
}
|
|
389 |
}
|
|
390 |
}
|
|
391 |
}
|
|
392 |
if (printerComment == QLatin1String(":"))
|
|
393 |
printerComment = QString(); // for cups
|
|
394 |
if (printerName.length())
|
|
395 |
qt_perhapsAddPrinter(printers, printerName, printerHost,
|
|
396 |
printerComment, aliases);
|
|
397 |
// chop away the line, for processing the next one
|
|
398 |
printerDesc = QString();
|
|
399 |
}
|
|
400 |
}
|
|
401 |
delete[] line;
|
|
402 |
return defaultPrinter;
|
|
403 |
}
|
|
404 |
|
|
405 |
#ifndef QT_NO_NIS
|
|
406 |
|
|
407 |
#if defined(Q_C_CALLBACKS)
|
|
408 |
extern "C" {
|
|
409 |
#endif
|
|
410 |
|
|
411 |
int qt_pd_foreach(int /*status */, char * /*key */, int /*keyLen */,
|
|
412 |
char *val, int valLen, char *data)
|
|
413 |
{
|
|
414 |
qt_parsePrinterDesc(QString::fromLatin1(val, valLen), (QList<QPrinterDescription> *)data);
|
|
415 |
return 0;
|
|
416 |
}
|
|
417 |
|
|
418 |
#if defined(Q_C_CALLBACKS)
|
|
419 |
}
|
|
420 |
#endif
|
|
421 |
|
|
422 |
int qt_retrieveNisPrinters(QList<QPrinterDescription> *printers)
|
|
423 |
{
|
|
424 |
typedef int (*WildCast)(int, char *, int, char *, int, char *);
|
|
425 |
char printersConfByname[] = "printers.conf.byname";
|
|
426 |
char *domain;
|
|
427 |
int err;
|
|
428 |
|
|
429 |
QLibrary lib(QLatin1String("nsl"));
|
|
430 |
typedef int (*ypGetDefaultDomain)(char **);
|
|
431 |
ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.resolve("yp_get_default_domain");
|
|
432 |
typedef int (*ypAll)(const char *, const char *, const struct ypall_callback *);
|
|
433 |
ypAll _ypAll = (ypAll)lib.resolve("yp_all");
|
|
434 |
|
|
435 |
if (_ypGetDefaultDomain && _ypAll) {
|
|
436 |
err = _ypGetDefaultDomain(&domain);
|
|
437 |
if (err == 0) {
|
|
438 |
ypall_callback cb;
|
|
439 |
// wild cast to support K&R-style system headers
|
|
440 |
(WildCast &) cb.foreach = (WildCast) qt_pd_foreach;
|
|
441 |
cb.data = (char *) printers;
|
|
442 |
err = _ypAll(domain, printersConfByname, &cb);
|
|
443 |
}
|
|
444 |
if (!err)
|
|
445 |
return Success;
|
|
446 |
}
|
|
447 |
return Unavail;
|
|
448 |
}
|
|
449 |
|
|
450 |
#endif // QT_NO_NIS
|
|
451 |
|
|
452 |
char *qt_parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line)
|
|
453 |
{
|
|
454 |
#define skipSpaces() \
|
|
455 |
while (line[k] != '\0' && isspace((uchar) line[k])) \
|
|
456 |
k++
|
|
457 |
|
|
458 |
char *defaultPrinter = 0;
|
|
459 |
bool stop = false;
|
|
460 |
int lastStatus = NotFound;
|
|
461 |
|
|
462 |
int k = 8;
|
|
463 |
skipSpaces();
|
|
464 |
if (line[k] != ':')
|
|
465 |
return 0;
|
|
466 |
k++;
|
|
467 |
|
|
468 |
char *cp = strchr(line, '#');
|
|
469 |
if (cp != 0)
|
|
470 |
*cp = '\0';
|
|
471 |
|
|
472 |
while (line[k] != '\0') {
|
|
473 |
if (isspace((uchar) line[k])) {
|
|
474 |
k++;
|
|
475 |
} else if (line[k] == '[') {
|
|
476 |
k++;
|
|
477 |
skipSpaces();
|
|
478 |
while (line[k] != '\0') {
|
|
479 |
char status = tolower(line[k]);
|
|
480 |
char action = '?';
|
|
481 |
|
|
482 |
while (line[k] != '=' && line[k] != ']' && line[k] != '\0')
|
|
483 |
k++;
|
|
484 |
if (line[k] == '=') {
|
|
485 |
k++;
|
|
486 |
skipSpaces();
|
|
487 |
action = tolower(line[k]);
|
|
488 |
while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != ']')
|
|
489 |
k++;
|
|
490 |
} else if (line[k] == ']') {
|
|
491 |
k++;
|
|
492 |
break;
|
|
493 |
}
|
|
494 |
skipSpaces();
|
|
495 |
|
|
496 |
if (lastStatus == status)
|
|
497 |
stop = (action == (char) Return);
|
|
498 |
}
|
|
499 |
} else {
|
|
500 |
if (stop)
|
|
501 |
break;
|
|
502 |
|
|
503 |
QByteArray source;
|
|
504 |
while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != '[') {
|
|
505 |
source += line[k];
|
|
506 |
k++;
|
|
507 |
}
|
|
508 |
|
|
509 |
if (source == "user") {
|
|
510 |
lastStatus = qt_parsePrintcap(printers,
|
|
511 |
QDir::homePath() + QLatin1String("/.printers"));
|
|
512 |
} else if (source == "files") {
|
|
513 |
bool found;
|
|
514 |
defaultPrinter = qt_parsePrintersConf(printers, &found);
|
|
515 |
if (found)
|
|
516 |
lastStatus = Success;
|
|
517 |
#ifndef QT_NO_NIS
|
|
518 |
} else if (source == "nis") {
|
|
519 |
lastStatus = qt_retrieveNisPrinters(printers);
|
|
520 |
#endif
|
|
521 |
} else {
|
|
522 |
// nisplus, dns, etc., are not implemented yet
|
|
523 |
lastStatus = NotFound;
|
|
524 |
}
|
|
525 |
stop = (lastStatus == Success);
|
|
526 |
}
|
|
527 |
}
|
|
528 |
return defaultPrinter;
|
|
529 |
}
|
|
530 |
|
|
531 |
char *qt_parseNsswitchConf(QList<QPrinterDescription> *printers)
|
|
532 |
{
|
|
533 |
QFile nc(QLatin1String("/etc/nsswitch.conf"));
|
|
534 |
if (!nc.open(QIODevice::ReadOnly))
|
|
535 |
return 0;
|
|
536 |
|
|
537 |
char *defaultPrinter = 0;
|
|
538 |
|
|
539 |
char *line = new char[1025];
|
|
540 |
line[1024] = '\0';
|
|
541 |
|
|
542 |
while (!nc.atEnd() &&
|
|
543 |
nc.readLine(line, 1024) > 0) {
|
|
544 |
if (qstrncmp(line, "printers", 8) == 0) {
|
|
545 |
defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
|
|
546 |
delete[] line;
|
|
547 |
return defaultPrinter;
|
|
548 |
}
|
|
549 |
}
|
|
550 |
|
|
551 |
strcpy(line, "printers: user files nis nisplus xfn");
|
|
552 |
defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
|
|
553 |
delete[] line;
|
|
554 |
return defaultPrinter;
|
|
555 |
}
|
|
556 |
|
|
557 |
// HP-UX
|
|
558 |
void qt_parseEtcLpMember(QList<QPrinterDescription> *printers)
|
|
559 |
{
|
|
560 |
QDir lp(QLatin1String("/etc/lp/member"));
|
|
561 |
if (!lp.exists())
|
|
562 |
return;
|
|
563 |
QFileInfoList dirs = lp.entryInfoList();
|
|
564 |
if (dirs.isEmpty())
|
|
565 |
return;
|
|
566 |
|
|
567 |
#ifdef QT_NO_PRINTDIALOG
|
|
568 |
Q_UNUSED(printers);
|
|
569 |
#else
|
|
570 |
QString tmp;
|
|
571 |
for (int i = 0; i < dirs.size(); ++i) {
|
|
572 |
QFileInfo printer = dirs.at(i);
|
|
573 |
// I haven't found any real documentation, so I'm guessing that
|
|
574 |
// since lpstat uses /etc/lp/member rather than one of the
|
|
575 |
// other directories, it's the one to use. I did not find a
|
|
576 |
// decent way to locate aliases and remote printers.
|
|
577 |
if (printer.isFile())
|
|
578 |
qt_perhapsAddPrinter(printers, printer.fileName(),
|
|
579 |
QPrintDialog::tr("unknown"),
|
|
580 |
QLatin1String(""));
|
|
581 |
}
|
|
582 |
#endif
|
|
583 |
}
|
|
584 |
|
|
585 |
// IRIX 6.x
|
|
586 |
void qt_parseSpoolInterface(QList<QPrinterDescription> *printers)
|
|
587 |
{
|
|
588 |
QDir lp(QLatin1String("/usr/spool/lp/interface"));
|
|
589 |
if (!lp.exists())
|
|
590 |
return;
|
|
591 |
QFileInfoList files = lp.entryInfoList();
|
|
592 |
if(files.isEmpty())
|
|
593 |
return;
|
|
594 |
|
|
595 |
for (int i = 0; i < files.size(); ++i) {
|
|
596 |
QFileInfo printer = files.at(i);
|
|
597 |
|
|
598 |
if (!printer.isFile())
|
|
599 |
continue;
|
|
600 |
|
|
601 |
// parse out some information
|
|
602 |
QFile configFile(printer.filePath());
|
|
603 |
if (!configFile.open(QIODevice::ReadOnly))
|
|
604 |
continue;
|
|
605 |
|
|
606 |
QByteArray line;
|
|
607 |
line.resize(1025);
|
|
608 |
QString namePrinter;
|
|
609 |
QString hostName;
|
|
610 |
QString hostPrinter;
|
|
611 |
QString printerType;
|
|
612 |
|
|
613 |
QString nameKey(QLatin1String("NAME="));
|
|
614 |
QString typeKey(QLatin1String("TYPE="));
|
|
615 |
QString hostKey(QLatin1String("HOSTNAME="));
|
|
616 |
QString hostPrinterKey(QLatin1String("HOSTPRINTER="));
|
|
617 |
|
|
618 |
while (!configFile.atEnd() &&
|
|
619 |
(configFile.readLine(line.data(), 1024)) > 0) {
|
|
620 |
QString uline = QString::fromLocal8Bit(line);
|
|
621 |
if (uline.startsWith(typeKey) ) {
|
|
622 |
printerType = uline.mid(nameKey.length());
|
|
623 |
printerType = printerType.simplified();
|
|
624 |
} else if (uline.startsWith(hostKey)) {
|
|
625 |
hostName = uline.mid(hostKey.length());
|
|
626 |
hostName = hostName.simplified();
|
|
627 |
} else if (uline.startsWith(hostPrinterKey)) {
|
|
628 |
hostPrinter = uline.mid(hostPrinterKey.length());
|
|
629 |
hostPrinter = hostPrinter.simplified();
|
|
630 |
} else if (uline.startsWith(nameKey)) {
|
|
631 |
namePrinter = uline.mid(nameKey.length());
|
|
632 |
namePrinter = namePrinter.simplified();
|
|
633 |
}
|
|
634 |
}
|
|
635 |
configFile.close();
|
|
636 |
|
|
637 |
printerType = printerType.trimmed();
|
|
638 |
if (printerType.indexOf(QLatin1String("postscript"), 0, Qt::CaseInsensitive) < 0)
|
|
639 |
continue;
|
|
640 |
|
|
641 |
int ii = 0;
|
|
642 |
while ((ii = namePrinter.indexOf(QLatin1Char('"'), ii)) >= 0)
|
|
643 |
namePrinter.remove(ii, 1);
|
|
644 |
|
|
645 |
if (hostName.isEmpty() || hostPrinter.isEmpty()) {
|
|
646 |
qt_perhapsAddPrinter(printers, printer.fileName(),
|
|
647 |
QLatin1String(""), namePrinter);
|
|
648 |
} else {
|
|
649 |
QString comment;
|
|
650 |
comment = namePrinter;
|
|
651 |
comment += QLatin1String(" (");
|
|
652 |
comment += hostPrinter;
|
|
653 |
comment += QLatin1Char(')');
|
|
654 |
qt_perhapsAddPrinter(printers, printer.fileName(),
|
|
655 |
hostName, comment);
|
|
656 |
}
|
|
657 |
}
|
|
658 |
}
|
|
659 |
|
|
660 |
|
|
661 |
// Every unix must have its own. It's a standard. Here is AIX.
|
|
662 |
void qt_parseQconfig(QList<QPrinterDescription> *printers)
|
|
663 |
{
|
|
664 |
QFile qconfig(QLatin1String("/etc/qconfig"));
|
|
665 |
if (!qconfig.open(QIODevice::ReadOnly))
|
|
666 |
return;
|
|
667 |
|
|
668 |
QTextStream ts(&qconfig);
|
|
669 |
QString line;
|
|
670 |
|
|
671 |
QString stanzaName; // either a queue or a device name
|
|
672 |
bool up = true; // queue up? default true, can be false
|
|
673 |
QString remoteHost; // null if local
|
|
674 |
QString deviceName; // null if remote
|
|
675 |
|
|
676 |
QRegExp newStanza(QLatin1String("^[0-z\\-]*:$"));
|
|
677 |
|
|
678 |
// our basic strategy here is to process each line, detecting new
|
|
679 |
// stanzas. each time we see a new stanza, we check if the
|
|
680 |
// previous stanza was a valid queue for a) a remote printer or b)
|
|
681 |
// a local printer. if it wasn't, we assume that what we see is
|
|
682 |
// the start of the first stanza, or that the previous stanza was
|
|
683 |
// a device stanza, or that there is some syntax error (we don't
|
|
684 |
// report those).
|
|
685 |
|
|
686 |
do {
|
|
687 |
line = ts.readLine();
|
|
688 |
bool indented = line[0].isSpace();
|
|
689 |
line = line.simplified();
|
|
690 |
|
|
691 |
int i = line.indexOf(QLatin1Char('='));
|
|
692 |
if (indented && i != -1) { // line in stanza
|
|
693 |
QString variable = line.left(i).simplified();
|
|
694 |
QString value=line.mid(i+1, line.length()).simplified();
|
|
695 |
if (variable == QLatin1String("device"))
|
|
696 |
deviceName = value;
|
|
697 |
else if (variable == QLatin1String("host"))
|
|
698 |
remoteHost = value;
|
|
699 |
else if (variable == QLatin1String("up"))
|
|
700 |
up = !(value.toLower() == QLatin1String("false"));
|
|
701 |
} else if (line[0] == QLatin1Char('*')) { // comment
|
|
702 |
// nothing to do
|
|
703 |
} else if (ts.atEnd() || // end of file, or beginning of new stanza
|
|
704 |
(!indented && line.contains(newStanza))) {
|
|
705 |
if (up && stanzaName.length() > 0 && stanzaName.length() < 21) {
|
|
706 |
if (remoteHost.length()) // remote printer
|
|
707 |
qt_perhapsAddPrinter(printers, stanzaName, remoteHost,
|
|
708 |
QString());
|
|
709 |
else if (deviceName.length()) // local printer
|
|
710 |
qt_perhapsAddPrinter(printers, stanzaName, QString(),
|
|
711 |
QString());
|
|
712 |
}
|
|
713 |
line.chop(1);
|
|
714 |
if (line.length() >= 1 && line.length() <= 20)
|
|
715 |
stanzaName = line;
|
|
716 |
up = true;
|
|
717 |
remoteHost.clear();
|
|
718 |
deviceName.clear();
|
|
719 |
} else {
|
|
720 |
// syntax error? ignore.
|
|
721 |
}
|
|
722 |
} while (!ts.atEnd());
|
|
723 |
}
|
|
724 |
|
|
725 |
int qt_getLprPrinters(QList<QPrinterDescription>& printers)
|
|
726 |
{
|
|
727 |
QByteArray etcLpDefault;
|
|
728 |
qt_parsePrintcap(&printers, QLatin1String("/etc/printcap"));
|
|
729 |
qt_parseEtcLpMember(&printers);
|
|
730 |
qt_parseSpoolInterface(&printers);
|
|
731 |
qt_parseQconfig(&printers);
|
|
732 |
|
|
733 |
QFileInfo f;
|
|
734 |
f.setFile(QLatin1String("/etc/lp/printers"));
|
|
735 |
if (f.isDir()) {
|
|
736 |
qt_parseEtcLpPrinters(&printers);
|
|
737 |
QFile def(QLatin1String("/etc/lp/default"));
|
|
738 |
if (def.open(QIODevice::ReadOnly)) {
|
|
739 |
etcLpDefault.resize(1025);
|
|
740 |
if (def.readLine(etcLpDefault.data(), 1024) > 0) {
|
|
741 |
QRegExp rx(QLatin1String("^(\\S+)"));
|
|
742 |
if (rx.indexIn(QString::fromLatin1(etcLpDefault)) != -1)
|
|
743 |
etcLpDefault = rx.cap(1).toAscii();
|
|
744 |
}
|
|
745 |
}
|
|
746 |
}
|
|
747 |
|
|
748 |
char *def = 0;
|
|
749 |
f.setFile(QLatin1String("/etc/nsswitch.conf"));
|
|
750 |
if (f.isFile()) {
|
|
751 |
def = qt_parseNsswitchConf(&printers);
|
|
752 |
} else {
|
|
753 |
f.setFile(QLatin1String("/etc/printers.conf"));
|
|
754 |
if (f.isFile())
|
|
755 |
def = qt_parsePrintersConf(&printers);
|
|
756 |
}
|
|
757 |
|
|
758 |
if (def) {
|
|
759 |
etcLpDefault = def;
|
|
760 |
delete [] def;
|
|
761 |
}
|
|
762 |
|
|
763 |
QString homePrintersDefault = qt_getDefaultFromHomePrinters();
|
|
764 |
|
|
765 |
// all printers hopefully known. try to find a good default
|
|
766 |
QString dollarPrinter;
|
|
767 |
{
|
|
768 |
dollarPrinter = QString::fromLocal8Bit(qgetenv("PRINTER"));
|
|
769 |
if (dollarPrinter.isEmpty())
|
|
770 |
dollarPrinter = QString::fromLocal8Bit(qgetenv("LPDEST"));
|
|
771 |
if (dollarPrinter.isEmpty())
|
|
772 |
dollarPrinter = QString::fromLocal8Bit(qgetenv("NPRINTER"));
|
|
773 |
if (dollarPrinter.isEmpty())
|
|
774 |
dollarPrinter = QString::fromLocal8Bit(qgetenv("NGPRINTER"));
|
|
775 |
#ifndef QT_NO_PRINTDIALOG
|
|
776 |
if (!dollarPrinter.isEmpty())
|
|
777 |
qt_perhapsAddPrinter(&printers, dollarPrinter,
|
|
778 |
QPrintDialog::tr("unknown"),
|
|
779 |
QLatin1String(""));
|
|
780 |
#endif
|
|
781 |
}
|
|
782 |
|
|
783 |
int quality = 0;
|
|
784 |
int best = 0;
|
|
785 |
for (int i = 0; i < printers.size(); ++i) {
|
|
786 |
QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)"));
|
|
787 |
QRegExp lp(QLatin1String("[^a-z]lp(?:[^a-z]|$)"));
|
|
788 |
|
|
789 |
QString name = printers.at(i).name;
|
|
790 |
QString comment = printers.at(i).comment;
|
|
791 |
if (quality < 5 && name == dollarPrinter) {
|
|
792 |
best = i;
|
|
793 |
quality = 5;
|
|
794 |
} else if (quality < 4 && !homePrintersDefault.isEmpty() &&
|
|
795 |
name == homePrintersDefault) {
|
|
796 |
best = i;
|
|
797 |
quality = 4;
|
|
798 |
} else if (quality < 3 && !etcLpDefault.isEmpty() &&
|
|
799 |
name == QLatin1String(etcLpDefault)) {
|
|
800 |
best = i;
|
|
801 |
quality = 3;
|
|
802 |
} else if (quality < 2 &&
|
|
803 |
(name == QLatin1String("ps") ||
|
|
804 |
ps.indexIn(comment) != -1)) {
|
|
805 |
best = i;
|
|
806 |
quality = 2;
|
|
807 |
} else if (quality < 1 &&
|
|
808 |
(name == QLatin1String("lp") ||
|
|
809 |
lp.indexIn(comment) > -1)) {
|
|
810 |
best = i;
|
|
811 |
quality = 1;
|
|
812 |
}
|
|
813 |
}
|
|
814 |
|
|
815 |
return best;
|
|
816 |
}
|
|
817 |
|
|
818 |
/////////////////////////////////////////////////////////////////////////////
|
|
819 |
/////////////////////////////////////////////////////////////////////////////
|
|
820 |
|
|
821 |
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
|
|
822 |
{
|
|
823 |
QList<QPrinterInfo> list;
|
|
824 |
|
|
825 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
|
826 |
QCUPSSupport cups;
|
|
827 |
if (QCUPSSupport::isAvailable()) {
|
|
828 |
//const ppd_file_t* cupsPPD = cups.currentPPD();
|
|
829 |
int cupsPrinterCount = cups.availablePrintersCount();
|
|
830 |
const cups_dest_t* cupsPrinters = cups.availablePrinters();
|
|
831 |
|
|
832 |
for (int i = 0; i < cupsPrinterCount; ++i) {
|
|
833 |
QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
|
|
834 |
if (cupsPrinters[i].instance)
|
|
835 |
printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
|
|
836 |
list.append(QPrinterInfo(printerName));
|
|
837 |
if (cupsPrinters[i].is_default)
|
|
838 |
list[i].d_ptr->m_default = true;
|
|
839 |
// Find paper sizes.
|
|
840 |
cups.setCurrentPrinter(i);
|
|
841 |
const ppd_option_t* sizes = cups.pageSizes();
|
|
842 |
if (sizes) {
|
|
843 |
for (int j = 0; j < sizes->num_choices; ++j) {
|
|
844 |
list[i].d_ptr->m_paperSizes.append(
|
|
845 |
QPrinterInfoPrivate::string2PaperSize(
|
|
846 |
QLatin1String(sizes->choices[j].choice)));
|
|
847 |
}
|
|
848 |
}
|
|
849 |
}
|
|
850 |
} else {
|
|
851 |
#endif
|
|
852 |
QList<QPrinterDescription> lprPrinters;
|
|
853 |
int defprn = qt_getLprPrinters(lprPrinters);
|
|
854 |
// populating printer combo
|
|
855 |
QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin();
|
|
856 |
for(; i != lprPrinters.constEnd(); ++i) {
|
|
857 |
list.append(QPrinterInfo((*i).name));
|
|
858 |
}
|
|
859 |
if (defprn >= 0 && defprn < lprPrinters.size()) {
|
|
860 |
list[defprn].d_ptr->m_default = true;
|
|
861 |
}
|
|
862 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
|
863 |
}
|
|
864 |
#endif
|
|
865 |
|
|
866 |
return list;
|
|
867 |
}
|
|
868 |
|
|
869 |
QPrinterInfo QPrinterInfo::defaultPrinter()
|
|
870 |
{
|
|
871 |
QList<QPrinterInfo> prnList = availablePrinters();
|
|
872 |
for (int i = 0; i < prnList.size(); ++i) {
|
|
873 |
if (prnList[i].isDefault())
|
|
874 |
return prnList[i];
|
|
875 |
}
|
|
876 |
return (prnList.size() > 0) ? prnList[0] : QPrinterInfo();
|
|
877 |
}
|
|
878 |
|
|
879 |
QPrinterInfo::QPrinterInfo()
|
|
880 |
: d_ptr(&nullQPrinterInfoPrivate)
|
|
881 |
{
|
|
882 |
}
|
|
883 |
|
|
884 |
QPrinterInfo::QPrinterInfo(const QPrinterInfo& src)
|
|
885 |
: d_ptr(&nullQPrinterInfoPrivate)
|
|
886 |
{
|
|
887 |
*this = src;
|
|
888 |
}
|
|
889 |
|
|
890 |
QPrinterInfo::QPrinterInfo(const QPrinter& printer)
|
|
891 |
: d_ptr(new QPrinterInfoPrivate(printer.printerName()))
|
|
892 |
{
|
|
893 |
|
|
894 |
Q_D(QPrinterInfo);
|
|
895 |
d->q_ptr = this;
|
|
896 |
|
|
897 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
|
898 |
QCUPSSupport cups;
|
|
899 |
if (QCUPSSupport::isAvailable()) {
|
|
900 |
int cupsPrinterCount = cups.availablePrintersCount();
|
|
901 |
const cups_dest_t* cupsPrinters = cups.availablePrinters();
|
|
902 |
|
|
903 |
for (int i = 0; i < cupsPrinterCount; ++i) {
|
|
904 |
QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
|
|
905 |
if (cupsPrinters[i].instance)
|
|
906 |
printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
|
|
907 |
if (printerName == printer.printerName()) {
|
|
908 |
if (cupsPrinters[i].is_default)
|
|
909 |
d->m_default = true;
|
|
910 |
// Find paper sizes.
|
|
911 |
cups.setCurrentPrinter(i);
|
|
912 |
const ppd_option_t* sizes = cups.pageSizes();
|
|
913 |
if (sizes) {
|
|
914 |
for (int j = 0; j < sizes->num_choices; ++j) {
|
|
915 |
d->m_paperSizes.append(
|
|
916 |
QPrinterInfoPrivate::string2PaperSize(
|
|
917 |
QLatin1String(sizes->choices[j].choice)));
|
|
918 |
}
|
|
919 |
}
|
|
920 |
return;
|
|
921 |
}
|
|
922 |
}
|
|
923 |
} else {
|
|
924 |
#endif
|
|
925 |
QList<QPrinterDescription> lprPrinters;
|
|
926 |
int defprn = qt_getLprPrinters(lprPrinters);
|
|
927 |
// populating printer combo
|
|
928 |
QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin();
|
|
929 |
int c;
|
|
930 |
for(c = 0; i != lprPrinters.constEnd(); ++i, ++c) {
|
|
931 |
if (i->name == printer.printerName()) {
|
|
932 |
if (defprn == c)
|
|
933 |
d->m_default = true;
|
|
934 |
return;
|
|
935 |
}
|
|
936 |
}
|
|
937 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
|
938 |
}
|
|
939 |
#endif
|
|
940 |
|
|
941 |
// Printer not found.
|
|
942 |
d_ptr.reset(&nullQPrinterInfoPrivate);
|
|
943 |
}
|
|
944 |
|
|
945 |
QPrinterInfo::QPrinterInfo(const QString& name)
|
|
946 |
: d_ptr(new QPrinterInfoPrivate(name))
|
|
947 |
{
|
|
948 |
d_ptr->q_ptr = this;
|
|
949 |
}
|
|
950 |
|
|
951 |
QPrinterInfo::~QPrinterInfo()
|
|
952 |
{
|
|
953 |
}
|
|
954 |
|
|
955 |
QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src)
|
|
956 |
{
|
|
957 |
Q_ASSERT(d_ptr);
|
|
958 |
d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr));
|
|
959 |
d_ptr->q_ptr = this;
|
|
960 |
return *this;
|
|
961 |
}
|
|
962 |
|
|
963 |
QString QPrinterInfo::printerName() const
|
|
964 |
{
|
|
965 |
const Q_D(QPrinterInfo);
|
|
966 |
return d->m_name;
|
|
967 |
}
|
|
968 |
|
|
969 |
bool QPrinterInfo::isNull() const
|
|
970 |
{
|
|
971 |
const Q_D(QPrinterInfo);
|
|
972 |
return d->m_isNull;
|
|
973 |
}
|
|
974 |
|
|
975 |
bool QPrinterInfo::isDefault() const
|
|
976 |
{
|
|
977 |
const Q_D(QPrinterInfo);
|
|
978 |
return d->m_default;
|
|
979 |
}
|
|
980 |
|
|
981 |
QList< QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
|
|
982 |
{
|
|
983 |
const Q_D(QPrinterInfo);
|
|
984 |
return d->m_paperSizes;
|
|
985 |
}
|
|
986 |
|
|
987 |
/////////////////////////////////////////////////////////////////////////////
|
|
988 |
/////////////////////////////////////////////////////////////////////////////
|
|
989 |
|
|
990 |
QPrinterInfoPrivate::QPrinterInfoPrivate()
|
|
991 |
{
|
|
992 |
m_isNull = true;
|
|
993 |
m_default = false;
|
|
994 |
q_ptr = 0;
|
|
995 |
}
|
|
996 |
|
|
997 |
QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name)
|
|
998 |
{
|
|
999 |
m_name = name;
|
|
1000 |
m_isNull = false;
|
|
1001 |
m_default = false;
|
|
1002 |
q_ptr = 0;
|
|
1003 |
}
|
|
1004 |
|
|
1005 |
QPrinterInfoPrivate::~QPrinterInfoPrivate()
|
|
1006 |
{
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
QPrinter::PaperSize QPrinterInfoPrivate::string2PaperSize(const QString& str)
|
|
1010 |
{
|
|
1011 |
if (str == QLatin1String("A4")) {
|
|
1012 |
return QPrinter::A4;
|
|
1013 |
} else if (str == QLatin1String("B5")) {
|
|
1014 |
return QPrinter::B5;
|
|
1015 |
} else if (str == QLatin1String("Letter")) {
|
|
1016 |
return QPrinter::Letter;
|
|
1017 |
} else if (str == QLatin1String("Legal")) {
|
|
1018 |
return QPrinter::Legal;
|
|
1019 |
} else if (str == QLatin1String("Executive")) {
|
|
1020 |
return QPrinter::Executive;
|
|
1021 |
} else if (str == QLatin1String("A0")) {
|
|
1022 |
return QPrinter::A0;
|
|
1023 |
} else if (str == QLatin1String("A1")) {
|
|
1024 |
return QPrinter::A1;
|
|
1025 |
} else if (str == QLatin1String("A2")) {
|
|
1026 |
return QPrinter::A2;
|
|
1027 |
} else if (str == QLatin1String("A3")) {
|
|
1028 |
return QPrinter::A3;
|
|
1029 |
} else if (str == QLatin1String("A5")) {
|
|
1030 |
return QPrinter::A5;
|
|
1031 |
} else if (str == QLatin1String("A6")) {
|
|
1032 |
return QPrinter::A6;
|
|
1033 |
} else if (str == QLatin1String("A7")) {
|
|
1034 |
return QPrinter::A7;
|
|
1035 |
} else if (str == QLatin1String("A8")) {
|
|
1036 |
return QPrinter::A8;
|
|
1037 |
} else if (str == QLatin1String("A9")) {
|
|
1038 |
return QPrinter::A9;
|
|
1039 |
} else if (str == QLatin1String("B0")) {
|
|
1040 |
return QPrinter::B0;
|
|
1041 |
} else if (str == QLatin1String("B1")) {
|
|
1042 |
return QPrinter::B1;
|
|
1043 |
} else if (str == QLatin1String("B10")) {
|
|
1044 |
return QPrinter::B10;
|
|
1045 |
} else if (str == QLatin1String("B2")) {
|
|
1046 |
return QPrinter::B2;
|
|
1047 |
} else if (str == QLatin1String("B3")) {
|
|
1048 |
return QPrinter::B3;
|
|
1049 |
} else if (str == QLatin1String("B4")) {
|
|
1050 |
return QPrinter::B4;
|
|
1051 |
} else if (str == QLatin1String("B6")) {
|
|
1052 |
return QPrinter::B6;
|
|
1053 |
} else if (str == QLatin1String("B7")) {
|
|
1054 |
return QPrinter::B7;
|
|
1055 |
} else if (str == QLatin1String("B8")) {
|
|
1056 |
return QPrinter::B8;
|
|
1057 |
} else if (str == QLatin1String("B9")) {
|
|
1058 |
return QPrinter::B9;
|
|
1059 |
} else if (str == QLatin1String("C5E")) {
|
|
1060 |
return QPrinter::C5E;
|
|
1061 |
} else if (str == QLatin1String("Comm10E")) {
|
|
1062 |
return QPrinter::Comm10E;
|
|
1063 |
} else if (str == QLatin1String("DLE")) {
|
|
1064 |
return QPrinter::DLE;
|
|
1065 |
} else if (str == QLatin1String("Folio")) {
|
|
1066 |
return QPrinter::Folio;
|
|
1067 |
} else if (str == QLatin1String("Ledger")) {
|
|
1068 |
return QPrinter::Ledger;
|
|
1069 |
} else if (str == QLatin1String("Tabloid")) {
|
|
1070 |
return QPrinter::Tabloid;
|
|
1071 |
} else {
|
|
1072 |
return QPrinter::Custom;
|
|
1073 |
}
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
QString QPrinterInfoPrivate::pageSize2String(QPrinter::PaperSize size)
|
|
1077 |
{
|
|
1078 |
switch (size) {
|
|
1079 |
case QPrinter::A4:
|
|
1080 |
return QLatin1String("A4");
|
|
1081 |
case QPrinter::B5:
|
|
1082 |
return QLatin1String("B5");
|
|
1083 |
case QPrinter::Letter:
|
|
1084 |
return QLatin1String("Letter");
|
|
1085 |
case QPrinter::Legal:
|
|
1086 |
return QLatin1String("Legal");
|
|
1087 |
case QPrinter::Executive:
|
|
1088 |
return QLatin1String("Executive");
|
|
1089 |
case QPrinter::A0:
|
|
1090 |
return QLatin1String("A0");
|
|
1091 |
case QPrinter::A1:
|
|
1092 |
return QLatin1String("A1");
|
|
1093 |
case QPrinter::A2:
|
|
1094 |
return QLatin1String("A2");
|
|
1095 |
case QPrinter::A3:
|
|
1096 |
return QLatin1String("A3");
|
|
1097 |
case QPrinter::A5:
|
|
1098 |
return QLatin1String("A5");
|
|
1099 |
case QPrinter::A6:
|
|
1100 |
return QLatin1String("A6");
|
|
1101 |
case QPrinter::A7:
|
|
1102 |
return QLatin1String("A7");
|
|
1103 |
case QPrinter::A8:
|
|
1104 |
return QLatin1String("A8");
|
|
1105 |
case QPrinter::A9:
|
|
1106 |
return QLatin1String("A9");
|
|
1107 |
case QPrinter::B0:
|
|
1108 |
return QLatin1String("B0");
|
|
1109 |
case QPrinter::B1:
|
|
1110 |
return QLatin1String("B1");
|
|
1111 |
case QPrinter::B10:
|
|
1112 |
return QLatin1String("B10");
|
|
1113 |
case QPrinter::B2:
|
|
1114 |
return QLatin1String("B2");
|
|
1115 |
case QPrinter::B3:
|
|
1116 |
return QLatin1String("B3");
|
|
1117 |
case QPrinter::B4:
|
|
1118 |
return QLatin1String("B4");
|
|
1119 |
case QPrinter::B6:
|
|
1120 |
return QLatin1String("B6");
|
|
1121 |
case QPrinter::B7:
|
|
1122 |
return QLatin1String("B7");
|
|
1123 |
case QPrinter::B8:
|
|
1124 |
return QLatin1String("B8");
|
|
1125 |
case QPrinter::B9:
|
|
1126 |
return QLatin1String("B9");
|
|
1127 |
case QPrinter::C5E:
|
|
1128 |
return QLatin1String("C5E");
|
|
1129 |
case QPrinter::Comm10E:
|
|
1130 |
return QLatin1String("Comm10E");
|
|
1131 |
case QPrinter::DLE:
|
|
1132 |
return QLatin1String("DLE");
|
|
1133 |
case QPrinter::Folio:
|
|
1134 |
return QLatin1String("Folio");
|
|
1135 |
case QPrinter::Ledger:
|
|
1136 |
return QLatin1String("Ledger");
|
|
1137 |
case QPrinter::Tabloid:
|
|
1138 |
return QLatin1String("Tabloid");
|
|
1139 |
default:
|
|
1140 |
return QLatin1String("Custom");
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
#endif // QT_NO_PRINTER
|
|
1145 |
|
|
1146 |
QT_END_NAMESPACE
|