Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcocoaprintersupport.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include <AppKit/AppKit.h>
6
8
9#ifndef QT_NO_PRINTER
10
11#include <AppKit/AppKit.h>
12
13#include <QtCore/private/qcore_mac_p.h>
14
17
18#include <private/qprinterinfo_p.h>
19
20#define QT_STATICPLUGIN
21#include <qpa/qplatformprintplugin.h>
22
24
25using namespace Qt::StringLiterals;
26
27QCocoaPrinterSupport::QCocoaPrinterSupport()
28{ }
29
30QCocoaPrinterSupport::~QCocoaPrinterSupport()
31{ }
32
33QPrintEngine *QCocoaPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode printerMode, const QString &deviceId)
34{
35 return new QMacPrintEngine(printerMode, deviceId);
36}
37
38QPaintEngine *QCocoaPrinterSupport::createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode printerMode)
39{
40 Q_UNUSED(printerMode);
41 /*
42 QMacPrintEngine multiply inherits from QPrintEngine and QPaintEngine,
43 the cast here allows conversion of QMacPrintEngine* to QPaintEngine*
44 */
45 return static_cast<QMacPrintEngine *>(printEngine);
46}
47
48QPrintDevice QCocoaPrinterSupport::createPrintDevice(const QString &id)
49{
50 return QPlatformPrinterSupport::createPrintDevice(new QCocoaPrintDevice(id));
51}
52
53QStringList QCocoaPrinterSupport::availablePrintDeviceIds() const
54{
55 QStringList list;
56 QCFType<CFArrayRef> printerList;
57 if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
58 CFIndex count = CFArrayGetCount(printerList);
59 for (CFIndex i = 0; i < count; ++i) {
60 PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
61 list.append(QString::fromCFString(PMPrinterGetID(printer)));
62 }
63 }
64 return list;
65}
66
67QString QCocoaPrinterSupport::defaultPrintDeviceId() const
68{
69 QCFType<CFArrayRef> printerList;
70 if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
71 CFIndex count = CFArrayGetCount(printerList);
72 for (CFIndex i = 0; i < count; ++i) {
73 PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
74 if (PMPrinterIsDefault(printer))
75 return QString::fromCFString(PMPrinterGetID(printer));
76 }
77 }
78 return QString();
79}
80
82{
83 Q_OBJECT
84 Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "cocoa.json")
85
86public:
88};
89
90QPlatformPrinterSupport *QCocoaPrinterSupportPlugin::create(const QString &key)
91{
92 if (key.compare(key, "cocoaprintersupport"_L1, Qt::CaseInsensitive) != 0)
93 return 0;
94
95 return new QCocoaPrinterSupport();
96}
97
98QT_END_NAMESPACE
99
100#include "qcocoaprintersupport.moc"
101
102#endif //QT_NO_PRINTER