~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/painting/qprinterinfo_mac.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-08-01 11:30:30 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20080801113030-c33y1z0l21t6cj5r
Tags: upstream-4.4.1
ImportĀ upstreamĀ versionĀ 4.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2007-2008 Trolltech ASA. All rights reserved.
 
4
**
 
5
** This file is part of the QtGui module of the Qt Toolkit.
 
6
**
 
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.
 
19
**
 
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.
 
27
**
 
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
 
32
** libraries.
 
33
**
 
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
 
37
** granted herein.
 
38
**
 
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.
 
41
**
 
42
****************************************************************************/
 
43
 
 
44
#include "qprinterinfo.h"
 
45
 
 
46
#include "private/qt_mac_p.h"
 
47
 
 
48
QT_BEGIN_NAMESPACE
 
49
 
 
50
#ifndef QT_NO_PRINTER
 
51
 
 
52
class QPrinterInfoPrivate
 
53
{
 
54
Q_DECLARE_PUBLIC(QPrinterInfo)
 
55
public:
 
56
    ~QPrinterInfoPrivate();
 
57
    QPrinterInfoPrivate();
 
58
    QPrinterInfoPrivate(const QString& name);
 
59
 
 
60
private:
 
61
    QPrinterInfo*                 q_ptr;
 
62
 
 
63
    QString                     m_name;
 
64
    bool                        m_default;
 
65
    bool                        m_isNull;
 
66
};
 
67
 
 
68
static QPrinterInfoPrivate nullQPrinterInfoPrivate;
 
69
 
 
70
extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size);
 
71
 
 
72
/////////////////////////////////////////////////////////////////////////////
 
73
/////////////////////////////////////////////////////////////////////////////
 
74
 
 
75
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
 
76
{
 
77
    QList<QPrinterInfo> printers;
 
78
 
 
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;
 
90
            }
 
91
        }
 
92
    }
 
93
 
 
94
    return printers;
 
95
}
 
96
 
 
97
QPrinterInfo QPrinterInfo::defaultPrinter(){
 
98
    QList<QPrinterInfo> printers = availablePrinters();
 
99
    for (int c = 0; c < printers.size(); ++c) {
 
100
        if (printers[c].isDefault()) {
 
101
            return printers[c];
 
102
        }
 
103
    }
 
104
    return QPrinterInfo();
 
105
}
 
106
 
 
107
/////////////////////////////////////////////////////////////////////////////
 
108
/////////////////////////////////////////////////////////////////////////////
 
109
 
 
110
QPrinterInfo::QPrinterInfo(const QPrinter& prn)
 
111
{
 
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()) {
 
116
            *this = list[c];
 
117
            return;
 
118
        }
 
119
    }
 
120
 
 
121
    *this = QPrinterInfo();
 
122
}
 
123
 
 
124
QPrinterInfo::~QPrinterInfo()
 
125
{
 
126
    if (d_ptr != &nullQPrinterInfoPrivate)
 
127
        delete d_ptr;
 
128
}
 
129
 
 
130
QPrinterInfo::QPrinterInfo()
 
131
{
 
132
    d_ptr = &nullQPrinterInfoPrivate;
 
133
}
 
134
 
 
135
QPrinterInfo::QPrinterInfo(const QString& name)
 
136
{
 
137
    d_ptr = new QPrinterInfoPrivate(name);
 
138
    d_ptr->q_ptr = this;
 
139
}
 
140
 
 
141
QPrinterInfo::QPrinterInfo(const QPrinterInfo& src)
 
142
{
 
143
    d_ptr = &nullQPrinterInfoPrivate;
 
144
    *this = src;
 
145
}
 
146
 
 
147
QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src)
 
148
{
 
149
    Q_ASSERT(d_ptr);
 
150
    if (d_ptr != &nullQPrinterInfoPrivate)
 
151
        delete d_ptr;
 
152
    d_ptr = new QPrinterInfoPrivate(*src.d_ptr);
 
153
    d_ptr->q_ptr = this;
 
154
    return *this;
 
155
}
 
156
 
 
157
QString QPrinterInfo::printerName() const
 
158
{
 
159
    const Q_D(QPrinterInfo);
 
160
    return d->m_name;
 
161
}
 
162
 
 
163
bool QPrinterInfo::isNull() const
 
164
{
 
165
    const Q_D(QPrinterInfo);
 
166
    return d->m_isNull;
 
167
}
 
168
 
 
169
bool QPrinterInfo::isDefault() const
 
170
{
 
171
    const Q_D(QPrinterInfo);
 
172
    return d->m_default;
 
173
}
 
174
 
 
175
QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
 
176
{
 
177
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4)
 
178
                return QList<QPrinter::PaperSize>();
 
179
#else
 
180
        if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4)
 
181
                return QList<QPrinter::PaperSize>();
 
182
 
 
183
    const Q_D(QPrinterInfo);
 
184
 
 
185
    PMPrinter cfPrn = PMPrinterCreateFromPrinterID(
 
186
            QCFString::toCFStringRef(d->m_name));
 
187
 
 
188
    if (!cfPrn) return QList<QPrinter::PaperSize>();
 
189
 
 
190
    CFArrayRef array;
 
191
    OSStatus status = PMPrinterGetPaperList(cfPrn, &array);
 
192
 
 
193
    if (status != 0) {
 
194
        PMRelease(cfPrn);
 
195
        return QList<QPrinter::PaperSize>();
 
196
    }
 
197
 
 
198
    QList<QPrinter::PaperSize> paperList;
 
199
    int count = CFArrayGetCount(array);
 
200
    for (int c = 0; c < count; c++) {
 
201
        PMPaper paper = static_cast<PMPaper>(
 
202
                const_cast<void*>(
 
203
                CFArrayGetValueAtIndex(array, c)));
 
204
        double width, height;
 
205
        status = PMPaperGetWidth(paper, &width);
 
206
        status |= PMPaperGetHeight(paper, &height);
 
207
        if (status != 0) continue;
 
208
 
 
209
        QSizeF size(width * 0.3527, height * 0.3527);
 
210
        paperList.append(qSizeFTopaperSize(size));
 
211
    }
 
212
 
 
213
    PMRelease(cfPrn);
 
214
 
 
215
    return paperList;
 
216
#endif // MAC_OS_X_VERSION_MAX_ALLOWED
 
217
}
 
218
 
 
219
/////////////////////////////////////////////////////////////////////////////
 
220
/////////////////////////////////////////////////////////////////////////////
 
221
 
 
222
QPrinterInfoPrivate::QPrinterInfoPrivate() :
 
223
    q_ptr(NULL),
 
224
    m_default(false),
 
225
    m_isNull(true)
 
226
{
 
227
}
 
228
 
 
229
QPrinterInfoPrivate::QPrinterInfoPrivate(const QString& name) :
 
230
    q_ptr(NULL),
 
231
    m_name(name),
 
232
    m_default(false),
 
233
    m_isNull(false)
 
234
{
 
235
}
 
236
 
 
237
QPrinterInfoPrivate::~QPrinterInfoPrivate()
 
238
{
 
239
}
 
240
 
 
241
#endif // QT_NO_PRINTER
 
242
 
 
243
QT_END_NAMESPACE