1
/****************************************************************************
3
** Copyright (C) 2007-2008 Trolltech ASA. All rights reserved.
5
** This file is part of the QtGui module of the Qt Toolkit.
7
** This file may be used under the terms of the GNU General Public
8
** License versions 2.0 or 3.0 as published by the Free Software
9
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
10
** included in the packaging of this file. Alternatively you may (at
11
** your option) use any later version of the GNU General Public
12
** License if such license has been publicly approved by Trolltech ASA
13
** (or its successors, if any) and the KDE Free Qt Foundation. In
14
** addition, as a special exception, Trolltech gives you certain
15
** additional rights. These rights are described in the Trolltech GPL
16
** Exception version 1.2, which can be found at
17
** http://www.trolltech.com/products/qt/gplexception/ and in the file
18
** GPL_EXCEPTION.txt in this package.
20
** Please review the following information to ensure GNU General
21
** Public Licensing requirements will be met:
22
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
23
** you are unsure which license is appropriate for your use, please
24
** review the following information:
25
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
26
** or contact the sales department at sales@trolltech.com.
28
** In addition, as a special exception, Trolltech, as the sole
29
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
30
** Integration plug-in the right for the Qt/Eclipse Integration to
31
** link to functionality provided by Qt Designer and its related
34
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
35
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
36
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
39
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
40
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42
****************************************************************************/
44
#include "qprinterinfo.h"
46
#include "private/qt_mac_p.h"
52
class QPrinterInfoPrivate
54
Q_DECLARE_PUBLIC(QPrinterInfo)
56
~QPrinterInfoPrivate();
57
QPrinterInfoPrivate();
58
QPrinterInfoPrivate(const QString& name);
68
static QPrinterInfoPrivate nullQPrinterInfoPrivate;
70
extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size);
72
/////////////////////////////////////////////////////////////////////////////
73
/////////////////////////////////////////////////////////////////////////////
75
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
77
QList<QPrinterInfo> printers;
79
OSStatus status = noErr;
80
QCFType<CFArrayRef> printerList;
81
status = PMServerCreatePrinterList(kPMServerLocal, &printerList);
82
if (status == noErr) {
83
CFIndex count = CFArrayGetCount(printerList);
84
for (CFIndex i=0; i<count; ++i) {
85
PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
86
QString name = QCFString::toQString(PMPrinterGetName(printer));
87
printers.append(QPrinterInfo(name));
88
if (PMPrinterIsDefault(printer)) {
89
printers[i].d_ptr->m_default = true;
97
QPrinterInfo QPrinterInfo::defaultPrinter(){
98
QList<QPrinterInfo> printers = availablePrinters();
99
for (int c = 0; c < printers.size(); ++c) {
100
if (printers[c].isDefault()) {
104
return QPrinterInfo();
107
/////////////////////////////////////////////////////////////////////////////
108
/////////////////////////////////////////////////////////////////////////////
110
QPrinterInfo::QPrinterInfo(const QPrinter& prn)
112
d_ptr = &nullQPrinterInfoPrivate;
113
QList<QPrinterInfo> list = availablePrinters();
114
for (int c = 0; c < list.size(); ++c) {
115
if (prn.printerName() == list[c].printerName()) {
121
*this = QPrinterInfo();
124
QPrinterInfo::~QPrinterInfo()
126
if (d_ptr != &nullQPrinterInfoPrivate)
130
QPrinterInfo::QPrinterInfo()
132
d_ptr = &nullQPrinterInfoPrivate;
135
QPrinterInfo::QPrinterInfo(const QString& name)
137
d_ptr = new QPrinterInfoPrivate(name);
141
QPrinterInfo::QPrinterInfo(const QPrinterInfo& src)
143
d_ptr = &nullQPrinterInfoPrivate;
147
QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src)
150
if (d_ptr != &nullQPrinterInfoPrivate)
152
d_ptr = new QPrinterInfoPrivate(*src.d_ptr);
157
QString QPrinterInfo::printerName() const
159
const Q_D(QPrinterInfo);
163
bool QPrinterInfo::isNull() const
165
const Q_D(QPrinterInfo);
169
bool QPrinterInfo::isDefault() const
171
const Q_D(QPrinterInfo);
175
QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
177
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4)
178
return QList<QPrinter::PaperSize>();
180
if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4)
181
return QList<QPrinter::PaperSize>();
183
const Q_D(QPrinterInfo);
185
PMPrinter cfPrn = PMPrinterCreateFromPrinterID(
186
QCFString::toCFStringRef(d->m_name));
188
if (!cfPrn) return QList<QPrinter::PaperSize>();
191
OSStatus status = PMPrinterGetPaperList(cfPrn, &array);
195
return QList<QPrinter::PaperSize>();
198
QList<QPrinter::PaperSize> paperList;
199
int count = CFArrayGetCount(array);
200
for (int c = 0; c < count; c++) {
201
PMPaper paper = static_cast<PMPaper>(
203
CFArrayGetValueAtIndex(array, c)));
204
double width, height;
205
status = PMPaperGetWidth(paper, &width);
206
status |= PMPaperGetHeight(paper, &height);
207
if (status != 0) continue;
209
QSizeF size(width * 0.3527, height * 0.3527);
210
paperList.append(qSizeFTopaperSize(size));
216
#endif // MAC_OS_X_VERSION_MAX_ALLOWED
219
/////////////////////////////////////////////////////////////////////////////
220
/////////////////////////////////////////////////////////////////////////////
222
QPrinterInfoPrivate::QPrinterInfoPrivate() :
229
QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name) :
237
QPrinterInfoPrivate::~QPrinterInfoPrivate()
241
#endif // QT_NO_PRINTER