summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaprintersupport.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaprintersupport.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaprintersupport.mm104
1 files changed, 17 insertions, 87 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm
index cb2aa7132b..5853135dfb 100644
--- a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm
+++ b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm
@@ -42,10 +42,10 @@
#include "qcocoaprintersupport.h"
#ifndef QT_NO_PRINTER
+
+#include "qcocoaprintdevice.h"
#include "qprintengine_mac_p.h"
-#include <QtPrintSupport/QPrinter>
-#include <QtPrintSupport/QPrinterInfo>
#include <private/qprinterinfo_p.h>
QCocoaPrinterSupport::QCocoaPrinterSupport()
@@ -69,107 +69,37 @@ QPaintEngine *QCocoaPrinterSupport::createPaintEngine(QPrintEngine *printEngine,
return static_cast<QMacPrintEngine *>(printEngine);
}
-QList<QPrinter::PaperSize> QCocoaPrinterSupport::supportedPaperSizes(const QPrinterInfo &printerInfo) const
+QPrintDevice QCocoaPrinterSupport::createPrintDevice(const QString &id)
{
- QList<QPrinter::PaperSize> returnValue;
- if (printerInfo.isNull())
- return returnValue;
-
- PMPrinter printer = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(printerInfo.printerName()));
- if (!printer)
- return returnValue;
-
- CFArrayRef array;
- if (PMPrinterGetPaperList(printer, &array) != noErr) {
- PMRelease(printer);
- return returnValue;
- }
-
- CFIndex count = CFArrayGetCount(array);
- for (CFIndex i = 0; i < count; ++i) {
- PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
- double width, height;
- if (PMPaperGetWidth(paper, &width) == noErr
- && PMPaperGetHeight(paper, &height) == noErr) {
- // width and height are in points, convertQSizeFToPaperSize() expects millimeters
- static const double OnePointInMillimeters = 1.0 / 72.0 * 25.4;
- QSizeF size(width * OnePointInMillimeters, height * OnePointInMillimeters);
- returnValue += QPlatformPrinterSupport::convertQSizeFToPaperSize(size);
- }
- }
-
- PMRelease(printer);
-
- return returnValue;
+ return QPlatformPrinterSupport::createPrintDevice(new QCocoaPrintDevice(id));
}
-QList<QPrinterInfo> QCocoaPrinterSupport::availablePrinters()
+QStringList QCocoaPrinterSupport::availablePrintDeviceIds() const
{
- QList<QPrinterInfo> returnValue;
+ QStringList list;
QCFType<CFArrayRef> printerList;
if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
CFIndex count = CFArrayGetCount(printerList);
for (CFIndex i = 0; i < count; ++i) {
PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
- returnValue += printerInfoFromPMPrinter(printer);
+ list.append(QCFString::toQString(PMPrinterGetID(printer)));
}
}
- return returnValue;
-}
-
-QPrinterInfo QCocoaPrinterSupport::printerInfo(const QString &printerName)
-{
- PMPrinter printer = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(printerName));
- QPrinterInfo pi = printerInfoFromPMPrinter(printer);
- PMRelease(printer);
- return pi;
-}
-
-QPrinterInfo QCocoaPrinterSupport::printerInfoFromPMPrinter(const PMPrinter &printer)
-{
- if (!printer)
- return QPrinterInfo();
-
- QString name = QCFString::toQString(PMPrinterGetID(printer));
- QString description = QCFString::toQString(PMPrinterGetName(printer));
- QString location = QCFString::toQString(PMPrinterGetLocation(printer));
- CFStringRef cfMakeAndModel;
- PMPrinterGetMakeAndModelName(printer, &cfMakeAndModel);
- QString makeAndModel = QCFString::toQString(cfMakeAndModel);
- bool isDefault = PMPrinterIsDefault(printer);
-
- return createPrinterInfo(name, description, location, makeAndModel, isDefault, 0);
+ return list;
}
-QList<QPair<QString, QSizeF> > QCocoaPrinterSupport::supportedSizesWithNames(const QPrinterInfo &printerInfo) const
+QString QCocoaPrinterSupport::defaultPrintDeviceId() const
{
- QList<QPair<QString, QSizeF> > returnValue;
- if (printerInfo.isNull())
- return returnValue;
-
- PMPrinter printer = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(printerInfo.printerName()));
- if (!printer)
- return returnValue;
-
- CFArrayRef array;
- if (PMPrinterGetPaperList(printer, &array) != noErr) {
- PMRelease(printer);
- return returnValue;
- }
-
- int count = CFArrayGetCount(array);
- for (int i = 0; i < count; ++i) {
- PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
- double width, height;
- if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) {
- static const double OnePointInMillimeters = 1.0 / 72.0 * 25.4;
- QCFString paperName;
- if (PMPaperCreateLocalizedName(paper, printer, &paperName) == noErr)
- returnValue.append(qMakePair(QString(paperName), QSizeF(width * OnePointInMillimeters, height * OnePointInMillimeters)));
+ QCFType<CFArrayRef> printerList;
+ if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr) {
+ CFIndex count = CFArrayGetCount(printerList);
+ for (CFIndex i = 0; i < count; ++i) {
+ PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
+ if (PMPrinterIsDefault(printer))
+ return QCFString::toQString(PMPrinterGetID(printer));
}
}
- PMRelease(printer);
- return returnValue;
+ return QString();
}
#endif //QT_NO_PRINTER