| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** Copyright (C) 2010 netlabs.org. OS/2 parts.
|
|---|
| 8 | **
|
|---|
| 9 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 10 | **
|
|---|
| 11 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 12 | ** Commercial Usage
|
|---|
| 13 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 14 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 15 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 16 | ** a written agreement between you and Nokia.
|
|---|
| 17 | **
|
|---|
| 18 | ** GNU Lesser General Public License Usage
|
|---|
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 20 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 21 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 22 | ** packaging of this file. Please review the following information to
|
|---|
| 23 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 25 | **
|
|---|
| 26 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 27 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 29 | **
|
|---|
| 30 | ** GNU General Public License Usage
|
|---|
| 31 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 32 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 34 | ** packaging of this file. Please review the following information to
|
|---|
| 35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 37 | **
|
|---|
| 38 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 39 | ** Nokia at [email protected].
|
|---|
| 40 | ** $QT_END_LICENSE$
|
|---|
| 41 | **
|
|---|
| 42 | ****************************************************************************/
|
|---|
| 43 |
|
|---|
| 44 | #include "qprinterinfo.h"
|
|---|
| 45 |
|
|---|
| 46 | #if !defined(QT_NO_CUPS)
|
|---|
| 47 | # include <private/qcups_p.h>
|
|---|
| 48 | # include <cups/cups.h>
|
|---|
| 49 | # include <private/qpdf_p.h>
|
|---|
| 50 | #endif
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_NAMESPACE
|
|---|
| 53 |
|
|---|
| 54 | #ifndef QT_NO_PRINTER
|
|---|
| 55 |
|
|---|
| 56 | class QPrinterInfoPrivate
|
|---|
| 57 | {
|
|---|
| 58 | Q_DECLARE_PUBLIC(QPrinterInfo)
|
|---|
| 59 | public:
|
|---|
| 60 | QPrinterInfoPrivate();
|
|---|
| 61 | QPrinterInfoPrivate(const QString& name);
|
|---|
| 62 | ~QPrinterInfoPrivate();
|
|---|
| 63 |
|
|---|
| 64 | static QPrinter::PaperSize string2PaperSize(const QString& str);
|
|---|
| 65 | static QString pageSize2String(QPrinter::PaperSize size);
|
|---|
| 66 |
|
|---|
| 67 | private:
|
|---|
| 68 | QString m_name;
|
|---|
| 69 | bool m_isNull;
|
|---|
| 70 | bool m_default;
|
|---|
| 71 | mutable bool m_mustGetPaperSizes;
|
|---|
| 72 | mutable QList<QPrinter::PaperSize> m_paperSizes;
|
|---|
| 73 | int m_cupsPrinterIndex;
|
|---|
| 74 |
|
|---|
| 75 | QPrinterInfo* q_ptr;
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | static QPrinterInfoPrivate nullQPrinterInfoPrivate;
|
|---|
| 79 |
|
|---|
| 80 | class QPrinterInfoPrivateDeleter
|
|---|
| 81 | {
|
|---|
| 82 | public:
|
|---|
| 83 | static inline void cleanup(QPrinterInfoPrivate *d)
|
|---|
| 84 | {
|
|---|
| 85 | if (d != &nullQPrinterInfoPrivate)
|
|---|
| 86 | delete d;
|
|---|
| 87 | }
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 91 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 92 |
|
|---|
| 93 | QList<QPrinterInfo> QPrinterInfo::availablePrinters()
|
|---|
| 94 | {
|
|---|
| 95 | QList<QPrinterInfo> list;
|
|---|
| 96 |
|
|---|
| 97 | #if !defined(QT_NO_CUPS)
|
|---|
| 98 | QCUPSSupport cups;
|
|---|
| 99 | if (QCUPSSupport::isAvailable()) {
|
|---|
| 100 | //const ppd_file_t* cupsPPD = cups.currentPPD();
|
|---|
| 101 | int cupsPrinterCount = cups.availablePrintersCount();
|
|---|
| 102 | const cups_dest_t* cupsPrinters = cups.availablePrinters();
|
|---|
| 103 |
|
|---|
| 104 | for (int i = 0; i < cupsPrinterCount; ++i) {
|
|---|
| 105 | QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
|
|---|
| 106 | if (cupsPrinters[i].instance)
|
|---|
| 107 | printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
|
|---|
| 108 | list.append(QPrinterInfo(printerName));
|
|---|
| 109 | if (cupsPrinters[i].is_default)
|
|---|
| 110 | list[i].d_ptr->m_default = true;
|
|---|
| 111 | list[i].d_ptr->m_cupsPrinterIndex = i;
|
|---|
| 112 | }
|
|---|
| 113 | }
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|
| 116 | return list;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | QPrinterInfo QPrinterInfo::defaultPrinter()
|
|---|
| 120 | {
|
|---|
| 121 | QList<QPrinterInfo> prnList = availablePrinters();
|
|---|
| 122 | for (int i = 0; i < prnList.size(); ++i) {
|
|---|
| 123 | if (prnList[i].isDefault())
|
|---|
| 124 | return prnList[i];
|
|---|
| 125 | }
|
|---|
| 126 | return (prnList.size() > 0) ? prnList[0] : QPrinterInfo();
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | QPrinterInfo::QPrinterInfo()
|
|---|
| 130 | : d_ptr(&nullQPrinterInfoPrivate)
|
|---|
| 131 | {
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | QPrinterInfo::QPrinterInfo(const QPrinterInfo& src)
|
|---|
| 135 | : d_ptr(&nullQPrinterInfoPrivate)
|
|---|
| 136 | {
|
|---|
| 137 | *this = src;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | QPrinterInfo::QPrinterInfo(const QPrinter& printer)
|
|---|
| 141 | : d_ptr(new QPrinterInfoPrivate(printer.printerName()))
|
|---|
| 142 | {
|
|---|
| 143 |
|
|---|
| 144 | Q_D(QPrinterInfo);
|
|---|
| 145 | d->q_ptr = this;
|
|---|
| 146 |
|
|---|
| 147 | #if !defined(QT_NO_CUPS)
|
|---|
| 148 | QCUPSSupport cups;
|
|---|
| 149 | if (QCUPSSupport::isAvailable()) {
|
|---|
| 150 | int cupsPrinterCount = cups.availablePrintersCount();
|
|---|
| 151 | const cups_dest_t* cupsPrinters = cups.availablePrinters();
|
|---|
| 152 |
|
|---|
| 153 | for (int i = 0; i < cupsPrinterCount; ++i) {
|
|---|
| 154 | QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
|
|---|
| 155 | if (cupsPrinters[i].instance)
|
|---|
| 156 | printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
|
|---|
| 157 | if (printerName == printer.printerName()) {
|
|---|
| 158 | if (cupsPrinters[i].is_default)
|
|---|
| 159 | d->m_default = true;
|
|---|
|
|---|