summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2011-05-30 11:18:46 +0200
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2011-05-30 14:21:09 +0200
commitaf13869fef8db737ec9e0ed4f1e95c7fd8fd4eab (patch)
tree896acfdb2f0c1f6ac993762d3fecb16ef69731c3
parent09796553a5c3253d8507600f31d24589b52aa080 (diff)
downloadqtbase-af13869fef8db737ec9e0ed4f1e95c7fd8fd4eab.tar.gz
qtbase-af13869fef8db737ec9e0ed4f1e95c7fd8fd4eab.tar.bz2
qtbase-af13869fef8db737ec9e0ed4f1e95c7fd8fd4eab.zip
Add QPlatformPrinterSupport.
Add QPlatformPrinterSupport which provides functionality for obtaining QPrinterInfo and creating native printer engines. Rubber-stamped-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp12
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h4
-rw-r--r--src/gui/painting/painting.pri7
-rw-r--r--src/gui/painting/qcups.cpp45
-rw-r--r--src/gui/painting/qcups_p.h12
-rw-r--r--src/gui/painting/qplatformprintersupport_qpa.cpp133
-rw-r--r--src/gui/painting/qplatformprintersupport_qpa.h84
-rw-r--r--src/gui/painting/qprinter.cpp8
-rw-r--r--src/gui/painting/qprinterinfo.cpp26
-rw-r--r--src/gui/painting/qprinterinfo.h1
-rw-r--r--src/gui/painting/qprinterinfo_p.h7
-rw-r--r--src/gui/painting/qprinterinfo_unix.cpp80
-rw-r--r--src/gui/painting/qprinterinfo_unix_p.h5
-rw-r--r--src/plugins/platforms/printersupport/genericunix/genericunix.pri4
-rw-r--r--src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.cpp65
-rw-r--r--src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.h59
-rw-r--r--src/plugins/platforms/printersupport/windows/qwindowsprintersupport.cpp118
-rw-r--r--src/plugins/platforms/printersupport/windows/qwindowsprintersupport.h62
-rw-r--r--src/plugins/platforms/printersupport/windows/windows.pri7
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp9
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.h3
-rw-r--r--src/plugins/platforms/xcb/xcb.pro1
22 files changed, 674 insertions, 78 deletions
diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp
index 7a95ffa2a5..b335dd5a97 100644
--- a/src/gui/kernel/qplatformintegration_qpa.cpp
+++ b/src/gui/kernel/qplatformintegration_qpa.cpp
@@ -43,6 +43,7 @@
#include <QtGui/QPlatformFontDatabase>
#include <QtGui/QPlatformClipboard>
+#include <QtGui/QPlatformPrinterSupport>
QT_BEGIN_NAMESPACE
@@ -218,8 +219,19 @@ bool QPlatformIntegration::hasCapability(Capability cap) const
return false;
}
+/*!
+ Returns the platform's printing support.
+ \since 5.0
+*/
+QPlatformPrinterSupport *QPlatformIntegration::printerSupport() const
+{
+ static QPlatformPrinterSupport *ps = 0;
+ if (!ps)
+ ps = new QPlatformPrinterSupport;
+ return ps;
+}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h
index b42a162019..c3d311eb1e 100644
--- a/src/gui/kernel/qplatformintegration_qpa.h
+++ b/src/gui/kernel/qplatformintegration_qpa.h
@@ -60,7 +60,7 @@ class QPlatformEventLoopIntegration;
class QPlatformFontDatabase;
class QPlatformClipboard;
class QPlatformNativeInterface;
-
+class QPlatformPrinterSupport;
class Q_GUI_EXPORT QPlatformIntegration
{
@@ -98,6 +98,8 @@ public:
// Access native handles. The window handle is already available from Wid;
virtual QPlatformNativeInterface *nativeInterface() const;
+
+ virtual QPlatformPrinterSupport *printerSupport() const;
};
QT_END_NAMESPACE
diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri
index 3e284c04c1..aaf3b04833 100644
--- a/src/gui/painting/painting.pri
+++ b/src/gui/painting/painting.pri
@@ -100,8 +100,7 @@ win32:!qpa {
SOURCES += \
painting/qcolormap_win.cpp \
painting/qpaintdevice_win.cpp \
- painting/qprintengine_win.cpp \
- painting/qprinterinfo_win.cpp
+ painting/qprintengine_win.cpp
!win32-borland:!wince*:LIBS += -lmsimg32
}
@@ -139,9 +138,11 @@ unix:!mac:!symbian {
}
qpa {
+ HEADERS += painting/qplatformprintersupport_qpa.h
SOURCES += \
painting/qcolormap_qpa.cpp \
- painting/qpaintdevice_qpa.cpp
+ painting/qpaintdevice_qpa.cpp \
+ painting/qplatformprintersupport_qpa.cpp
}
symbian {
diff --git a/src/gui/painting/qcups.cpp b/src/gui/painting/qcups.cpp
index 3ec5f72395..76050d9d71 100644
--- a/src/gui/painting/qcups.cpp
+++ b/src/gui/painting/qcups.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <qdebug.h>
#include "qcups_p.h"
+#include "qprinterinfo_unix_p.h"
#ifndef QT_NO_CUPS
@@ -396,6 +397,50 @@ int QCUPSSupport::printFile(const char * printerName, const char * filename, con
return _cupsPrintFile(printerName, filename, title, num_options, options);
}
+QCUPSSupport::Printer::Printer(const QString &n) : name(n), isDefault(false), cupsPrinterIndex(-1)
+{
+}
+
+QList<QCUPSSupport::Printer> QCUPSSupport::availableUnixPrinters()
+{
+ QList<Printer> printers;
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable()) {
+ QCUPSSupport cups;
+ int cupsPrinterCount = cups.availablePrintersCount();
+ const cups_dest_t* cupsPrinters = cups.availablePrinters();
+ for (int i = 0; i < cupsPrinterCount; ++i) {
+ QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
+ if (cupsPrinters[i].instance)
+ printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
+
+ Printer p(printerName);
+ if (cupsPrinters[i].is_default)
+ p.isDefault = true;
+ p.cupsPrinterIndex = i;
+ printers.append(p);
+ }
+ } else
+#endif
+ {
+ QList<QPrinterDescription> lprPrinters;
+ int defprn = qt_getLprPrinters(lprPrinters);
+ // populating printer combo
+ foreach (const QPrinterDescription &description, lprPrinters)
+ printers.append(Printer(description.name));
+ if (defprn >= 0 && defprn < printers.size())
+ printers[defprn].isDefault = true;
+ }
+
+ return printers;
+}
+
+QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinterIndex)
+{
+ return qt_getCupsPrinterPaperSizes(cupsPrinterIndex);
+}
+
QT_END_NAMESPACE
#endif // QT_NO_CUPS
diff --git a/src/gui/painting/qcups_p.h b/src/gui/painting/qcups_p.h
index e6c53111a5..6b6a55a440 100644
--- a/src/gui/painting/qcups_p.h
+++ b/src/gui/painting/qcups_p.h
@@ -54,6 +54,7 @@
//
#include "QtCore/qstring.h"
#include "QtCore/qstringlist.h"
+#include "QtCore/qpair.h"
#include "QtGui/qprinter.h"
#ifndef QT_NO_CUPS
@@ -68,6 +69,14 @@ Q_DECLARE_TYPEINFO(cups_option_t, Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE);
class Q_GUI_EXPORT QCUPSSupport
{
public:
+ struct Printer
+ {
+ Printer(const QString &name = QString());
+
+ QString name;
+ bool isDefault;
+ int cupsPrinterIndex;
+ };
QCUPSSupport();
~QCUPSSupport();
@@ -100,6 +109,9 @@ public:
int printFile(const char * printerName, const char * filename, const char * title,
int num_options, cups_option_t * options);
+ static QList<Printer> availableUnixPrinters();
+ static QList<QPrinter::PaperSize> getCupsPrinterPaperSizes(int cupsPrinterIndex);
+
private:
void collectMarkedOptions(QStringList& list, const ppd_group_t* group = 0) const;
void collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const;
diff --git a/src/gui/painting/qplatformprintersupport_qpa.cpp b/src/gui/painting/qplatformprintersupport_qpa.cpp
new file mode 100644
index 0000000000..9fb25c953f
--- /dev/null
+++ b/src/gui/painting/qplatformprintersupport_qpa.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformprintersupport_qpa.h"
+
+#include <QtGui/qprinterinfo.h>
+
+#include <private/qprinterinfo_p.h>
+
+#ifndef QT_NO_PRINTER
+
+QT_BEGIN_NAMESPACE
+
+QPlatformPrinterSupport::QPlatformPrinterSupport()
+{
+}
+
+QPlatformPrinterSupport::~QPlatformPrinterSupport()
+{
+}
+
+QPrintEngine *QPlatformPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode)
+{
+ return 0;
+}
+
+QPaintEngine *QPlatformPrinterSupport::createPaintEngine(QPrintEngine *, QPrinter::PrinterMode)
+{
+ return 0;
+}
+
+QList<QPrinter::PaperSize> QPlatformPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const
+{
+ return QList<QPrinter::PaperSize>();
+}
+
+QList<QPrinterInfo> QPlatformPrinterSupport::availablePrinters()
+{
+ return QList<QPrinterInfo>();
+}
+
+QPrinterInfo QPlatformPrinterSupport::defaultPrinter()
+{
+ const QList<QPrinterInfo> printers = availablePrinters();
+ foreach (const QPrinterInfo &printerInfo, printers) {
+ if (printerInfo.isDefault())
+ return printerInfo;
+ }
+ return printers.isEmpty() ? QPrinterInfo() : printers.front();
+}
+
+QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName, bool isDefault)
+{
+ QPrinterInfo pi = QPrinterInfo(printerName);
+ pi.d_func()->isDefault = isDefault;
+ return pi;
+}
+
+void QPlatformPrinterSupport::setPrinterInfoDefault(QPrinterInfo *p, bool isDefault)
+{
+ p->d_func()->isDefault = isDefault;
+}
+
+bool QPlatformPrinterSupport::printerInfoIsDefault(const QPrinterInfo &p)
+{
+ return p.d_func()->isDefault;
+}
+
+int QPlatformPrinterSupport::printerInfoCupsPrinterIndex(const QPrinterInfo &p)
+{
+ int i = -1;
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (!p.isNull())
+ return i = p.d_func()->cupsPrinterIndex;
+#endif
+#endif
+ Q_UNUSED(p)
+ return i;
+}
+
+void QPlatformPrinterSupport::setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index)
+{
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ p->d_func()->cupsPrinterIndex = index;
+#endif
+#endif
+ Q_UNUSED(p)
+ Q_UNUSED(index)
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/gui/painting/qplatformprintersupport_qpa.h b/src/gui/painting/qplatformprintersupport_qpa.h
new file mode 100644
index 0000000000..90dd260925
--- /dev/null
+++ b/src/gui/painting/qplatformprintersupport_qpa.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMPRINTINGSUPPORT_H
+#define QPLATFORMPRINTINGSUPPORT_H
+
+#include <QtGui/qprinter.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+
+class QPrintEngine;
+
+class Q_GUI_EXPORT QPlatformPrinterSupport
+{
+public:
+ QPlatformPrinterSupport();
+ virtual ~QPlatformPrinterSupport();
+
+ virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode);
+ virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode);
+ virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
+
+ virtual QList<QPrinterInfo> availablePrinters();
+ virtual QPrinterInfo defaultPrinter();
+
+protected:
+ static QPrinterInfo printerInfo(const QString &printerName, bool isDefault = false);
+ static void setPrinterInfoDefault(QPrinterInfo *p, bool isDefault);
+ static bool printerInfoIsDefault(const QPrinterInfo &p);
+ static int printerInfoCupsPrinterIndex(const QPrinterInfo &p);
+ static void setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index);
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPLATFORMPRINTINGSUPPORT_H
diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp
index bfd2c44b9f..059331f5f9 100644
--- a/src/gui/painting/qprinter.cpp
+++ b/src/gui/painting/qprinter.cpp
@@ -52,6 +52,9 @@
#ifndef QT_NO_PRINTER
+#include <private/qguiapplication_p.h>
+#include <QtGui/QPlatformPrinterSupport>
+
#if defined (Q_WS_WIN)
#include <private/qprintengine_win_p.h>
#elif defined (Q_WS_MAC)
@@ -165,7 +168,10 @@ void QPrinterPrivate::createDefaultEngines()
switch (realOutputFormat) {
case QPrinter::NativeFormat: {
-#if defined (Q_WS_WIN)
+#if defined (Q_WS_QPA)
+ printEngine = QGuiApplicationPrivate::platformIntegration()->printerSupport()->createNativePrintEngine(printerMode);
+ paintEngine = QGuiApplicationPrivate::platformIntegration()->printerSupport()->createPaintEngine(printEngine, printerMode);
+#elif defined (Q_WS_WIN)
QWin32PrintEngine *winEngine = new QWin32PrintEngine(printerMode);
paintEngine = winEngine;
printEngine = winEngine;
diff --git a/src/gui/painting/qprinterinfo.cpp b/src/gui/painting/qprinterinfo.cpp
index a7ddc85a54..0049bd248a 100644
--- a/src/gui/painting/qprinterinfo.cpp
+++ b/src/gui/painting/qprinterinfo.cpp
@@ -30,6 +30,9 @@
#ifndef QT_NO_PRINTER
+#include <private/qguiapplication_p.h>
+#include <QtGui/QPlatformPrinterSupport>
+
QT_BEGIN_NAMESPACE
QPrinterInfoPrivate QPrinterInfoPrivate::shared_null;
@@ -168,6 +171,29 @@ bool QPrinterInfo::isDefault() const
On Mac OS X 10.3, this function always returns an empty list.
*/
+#ifdef Q_WS_QPA
+QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
+{
+ const Q_D(QPrinterInfo);
+ if (!isNull() && !d->hasPaperSizes) {
+ d->paperSizes = QGuiApplicationPrivate::platformIntegration()->printerSupport()->supportedPaperSizes(*this);
+ d->hasPaperSizes = true;
+ }
+ return d->paperSizes;
+}
+
+QList<QPrinterInfo> QPrinterInfo::availablePrinters()
+{
+ return QGuiApplicationPrivate::platformIntegration()->printerSupport()->availablePrinters();
+}
+
+QPrinterInfo QPrinterInfo::defaultPrinter()
+{
+ return QGuiApplicationPrivate::platformIntegration()->printerSupport()->defaultPrinter();
+}
+
+#endif //Q_WS_QPA
+
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/gui/painting/qprinterinfo.h b/src/gui/painting/qprinterinfo.h
index 9ff1bd16bd..72082cf299 100644
--- a/src/gui/painting/qprinterinfo.h
+++ b/src/gui/painting/qprinterinfo.h
@@ -77,6 +77,7 @@ private:
QPrinterInfo(const QString &name);
private:
+ friend class QPlatformPrinterSupport;
Q_DECLARE_PRIVATE(QPrinterInfo)
QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr;
};
diff --git a/src/gui/painting/qprinterinfo_p.h b/src/gui/painting/qprinterinfo_p.h
index a3f7d5d252..a3c654e7b7 100644
--- a/src/gui/painting/qprinterinfo_p.h
+++ b/src/gui/painting/qprinterinfo_p.h
@@ -68,9 +68,10 @@ public:
name(name), isDefault(false)
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- , cupsPrinterIndex(0), hasPaperSizes(false)
+ , cupsPrinterIndex(0)
#endif
#endif
+ , hasPaperSizes(false)
{}
~QPrinterInfoPrivate()
{}
@@ -83,10 +84,10 @@ public:
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
int cupsPrinterIndex;
- mutable bool hasPaperSizes;
- mutable QList<QPrinter::PaperSize> paperSizes;
#endif
#endif
+ mutable bool hasPaperSizes;
+ mutable QList<QPrinter::PaperSize> paperSizes;
};
diff --git a/src/gui/painting/qprinterinfo_unix.cpp b/src/gui/painting/qprinterinfo_unix.cpp
index 7420bbfb90..3c66481b4d 100644
--- a/src/gui/painting/qprinterinfo_unix.cpp
+++ b/src/gui/painting/qprinterinfo_unix.cpp
@@ -835,78 +835,20 @@ Q_GUI_EXPORT int qt_getLprPrinters(QList<QPrinterDescription>& printers)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-QList<QPrinterInfo> QPrinterInfo::availablePrinters()
+QList<QPrinter::PaperSize> qt_getCupsPrinterPaperSizes(int cupsPrinterIndex)
{
- QList<QPrinterInfo> printers;
-
+ QList<QPrinter::PaperSize> result;
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- QCUPSSupport cups;
- int cupsPrinterCount = cups.availablePrintersCount();
- const cups_dest_t* cupsPrinters = cups.availablePrinters();
- for (int i = 0; i < cupsPrinterCount; ++i) {
- QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
- if (cupsPrinters[i].instance)
- printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
-
- QPrinterInfo printerInfo(printerName);
- if (cupsPrinters[i].is_default)
- printerInfo.d_ptr->isDefault = true;
- printerInfo.d_ptr->cupsPrinterIndex = i;
- printers.append(printerInfo);
- }
- } else
-#endif
- {
- QList<QPrinterDescription> lprPrinters;
- int defprn = qt_getLprPrinters(lprPrinters);
- // populating printer combo
- foreach (const QPrinterDescription &description, lprPrinters)
- printers.append(QPrinterInfo(description.name));
- if (defprn >= 0 && defprn < printers.size())
- printers[defprn].d_ptr->isDefault = true;
+ if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
+ return result;
+ // Find paper sizes from CUPS.
+ QCUPSSupport cups;
+ cups.setCurrentPrinter(cupsPrinterIndex);
+ if (const ppd_option_t* size = cups.pageSizes()) {
+ for (int j = 0; j < size->num_choices; ++j)
+ result.append(string2PaperSize(size->choices[j].choice));
}
-
- return printers;
-}
-
-QPrinterInfo QPrinterInfo::defaultPrinter()
-{
- QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.isDefault())
- return printerInfo;
- }
-
- return printers.value(0);
-}
-
-QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
-{
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- const Q_D(QPrinterInfo);
-
- if (isNull())
- return d->paperSizes;
-
- if (!d->hasPaperSizes) {
- d->hasPaperSizes = true;
-
- if (QCUPSSupport::isAvailable()) {
- // Find paper sizes from CUPS.
- QCUPSSupport cups;
- cups.setCurrentPrinter(d->cupsPrinterIndex);
- const ppd_option_t* sizes = cups.pageSizes();
- if (sizes) {
- for (int j = 0; j < sizes->num_choices; ++j)
- d->paperSizes.append(string2PaperSize(sizes->choices[j].choice));
- }
- }
- }
-
- return d->paperSizes;
-#else
- return QList<QPrinter::PaperSize>();
+ return result;
#endif
}
diff --git a/src/gui/painting/qprinterinfo_unix_p.h b/src/gui/painting/qprinterinfo_unix_p.h
index 1ededf5a36..f8721deaa9 100644
--- a/src/gui/painting/qprinterinfo_unix_p.h
+++ b/src/gui/painting/qprinterinfo_unix_p.h
@@ -42,6 +42,9 @@
#ifndef QPRINTERINFO_UNIX_P_H
#define QPRINTERINFO_UNIX_P_H
+#include <QtGui/qprinter.h>
+#include <QtCore/qstringlist.h>
+
#ifndef QT_NO_NIS
# ifndef BOOL_DEFINED
# define BOOL_DEFINED
@@ -118,6 +121,8 @@ void qt_parseSpoolInterface(QList<QPrinterDescription> *printers);
void qt_parseQconfig(QList<QPrinterDescription> *printers);
int qt_getLprPrinters(QList<QPrinterDescription>& printers);
+QList<QPrinter::PaperSize> qt_getCupsPrinterPaperSizes(int cupsPrinterIndex);
+
#endif // QT_NO_PRINTER
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/printersupport/genericunix/genericunix.pri b/src/plugins/platforms/printersupport/genericunix/genericunix.pri
new file mode 100644
index 0000000000..ea9c8f0b5d
--- /dev/null
+++ b/src/plugins/platforms/printersupport/genericunix/genericunix.pri
@@ -0,0 +1,4 @@
+INCLUDEPATH += $$PWD
+HEADERS += $$PWD/qgenericunixprintersupport.h
+SOURCES += $$PWD/qgenericunixprintersupport.cpp
+QT += gui-private
diff --git a/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.cpp b/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.cpp
new file mode 100644
index 0000000000..54d866c4ed
--- /dev/null
+++ b/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qgenericunixprintersupport.h>
+
+#include <QtGui/QPrinterInfo>
+#include <private/qcups_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QList<QPrinter::PaperSize> QGenericUnixPrinterSupport::supportedPaperSizes(const QPrinterInfo &printerInfo) const
+{
+ return QCUPSSupport::getCupsPrinterPaperSizes(QPlatformPrinterSupport::printerInfoCupsPrinterIndex(printerInfo));
+}
+
+QList<QPrinterInfo> QGenericUnixPrinterSupport::availablePrinters()
+{
+ QList<QPrinterInfo> printers;
+ foreach (const QCUPSSupport::Printer &p, QCUPSSupport::availableUnixPrinters()) {
+ QPrinterInfo printer(QPlatformPrinterSupport::printerInfo(p.name, p.isDefault));
+ QPlatformPrinterSupport::setPrinterInfoCupsPrinterIndex(&printer, p.cupsPrinterIndex);
+ printers.append(printer);
+ }
+ return printers;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.h b/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.h
new file mode 100644
index 0000000000..5d7b3b43fb
--- /dev/null
+++ b/src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGENERICUNIXPRINTINGSUPPORT_H
+#define QGENERICUNIXPRINTINGSUPPORT_H
+
+#include <QtGui/QPlatformPrinterSupport>
+
+QT_BEGIN_NAMESPACE
+
+class QGenericUnixPrinterSupport : public QPlatformPrinterSupport
+{
+public:
+ virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
+
+ virtual QList<QPrinterInfo> availablePrinters();
+};
+
+QT_END_NAMESPACE
+
+#endif // QGENERICUNIXPRINTINGSUPPORT_H
diff --git a/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.cpp b/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.cpp
new file mode 100644
index 0000000000..d5c185fee3
--- /dev/null
+++ b/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qwindowsprintersupport.h>
+#include <qprintengine_win_p.h>
+
+#include <QtGui/QPrinterInfo>
+
+#include <QtCore/QStringList>
+
+#include <QtCore/qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+
+QPrintEngine *QWindowsPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode mode)
+{
+ return new QWin32PrintEngine(mode);
+}
+
+QPaintEngine *QWindowsPrinterSupport::createPaintEngine(QPrintEngine *engine, QPrinter::PrinterMode)
+{
+ return static_cast<QWin32PrintEngine *>(engine);
+}
+
+QList<QPrinter::PaperSize> QWindowsPrinterSupport::supportedPaperSizes(const QPrinterInfo &printerInfo) const
+{
+ QList<QPrinter::PaperSize> paperSizes;
+ const QString printerName = printerInfo.printerName();
+ const wchar_t *nameUtf16 = reinterpret_cast<const wchar_t*>(printerName.utf16());
+ DWORD size = DeviceCapabilities(nameUtf16, NULL, DC_PAPERS, NULL, NULL);
+ if ((int)size != -1) {
+ wchar_t *papers = new wchar_t[size];
+ size = DeviceCapabilities(nameUtf16, NULL, DC_PAPERS, papers, NULL);
+ for (int c = 0; c < (int)size; ++c)
+ paperSizes.append(mapDevmodePaperSize(papers[c]));
+ delete [] papers;
+ }
+ return paperSizes;
+}
+
+QList<QPrinterInfo> QWindowsPrinterSupport::availablePrinters()
+{
+ QList<QPrinterInfo> printers;
+
+ DWORD needed = 0;
+ DWORD returned = 0;
+ if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) {
+ LPBYTE buffer = new BYTE[needed];
+ if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) {
+ PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
+ QPrinterInfo defPrn = defaultPrinter();
+ for (uint i = 0; i < returned; ++i) {
+ const QString printerName(QString::fromWCharArray(infoList[i].pPrinterName));
+ const bool isDefault = printerName == defPrn.printerName();
+ printers.append(QPlatformPrinterSupport::printerInfo(printerName,
+ isDefault));
+ }
+ }
+ delete [] buffer;
+ }
+
+ return printers;
+}
+
+QPrinterInfo QWindowsPrinterSupport::defaultPrinter()
+{
+ QString noPrinters(QLatin1String("qt_no_printers"));
+ wchar_t buffer[256];
+ GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256);
+ QString output = QString::fromWCharArray(buffer);
+ if (output != noPrinters) {
+ // Filter out the name of the printer, which should be everything before a comma.
+ const QString printerName = output.split(QLatin1Char(',')).value(0);
+ return QPlatformPrinterSupport::printerInfo(printerName, true);
+ }
+
+ return QPrinterInfo();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.h b/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.h
new file mode 100644
index 0000000000..d648846ef2
--- /dev/null
+++ b/src/plugins/platforms/printersupport/windows/qwindowsprintersupport.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWINDOWSPRINTERSUPPORT_H
+#define QWINDOWSPRINTERSUPPORT_H
+
+#include <QtGui/QPlatformPrinterSupport>
+
+QT_BEGIN_NAMESPACE
+
+class QWindowsPrinterSupport : public QPlatformPrinterSupport
+{
+public:
+ virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode);
+ virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode);
+
+ virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
+ virtual QPrinterInfo defaultPrinter();
+ virtual QList<QPrinterInfo> availablePrinters();
+};
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSPRINTERSUPPORT_H
diff --git a/src/plugins/platforms/printersupport/windows/windows.pri b/src/plugins/platforms/printersupport/windows/windows.pri
new file mode 100644
index 0000000000..67d49b22f3
--- /dev/null
+++ b/src/plugins/platforms/printersupport/windows/windows.pri
@@ -0,0 +1,7 @@
+INCLUDEPATH += $$PWD $$QT_SOURCE_TREE/src/3rdparty/harfbuzz/src
+
+HEADERS += $$PWD/qwindowsprintersupport.h \
+ $$PWD/qprintengine_win_p.h
+SOURCES += $$PWD/qwindowsprintersupport.cpp \
+ $$PWD/qprintengine_win.cpp
+QT += core-private widgets-private
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index 48aeae7601..d47bec60ef 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -46,6 +46,8 @@
#include "qxcbwindowsurface.h"
#include "qxcbnativeinterface.h"
+#include <qgenericunixprintersupport.h>
+
#include <xcb/xcb.h>
#include <private/qpixmap_raster_p.h>
@@ -59,7 +61,7 @@
#endif
QXcbIntegration::QXcbIntegration()
- : m_connection(new QXcbConnection)
+ : m_connection(new QXcbConnection), m_printerSupport(new QGenericUnixPrinterSupport)
{
foreach (QXcbScreen *screen, m_connection->screens())
m_screens << screen;
@@ -148,3 +150,8 @@ QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
{
return m_nativeInterface;
}
+
+QPlatformPrinterSupport *QXcbIntegration::printerSupport() const
+{
+ return m_printerSupport;
+}
diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h
index 647eb500c3..36c792fe48 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.h
+++ b/src/plugins/platforms/xcb/qxcbintegration.h
@@ -69,6 +69,8 @@ public:
QPlatformNativeInterface *nativeInterface()const;
+ QPlatformPrinterSupport *printerSupport() const;
+
private:
bool hasOpenGL() const;
QList<QPlatformScreen *> m_screens;
@@ -76,6 +78,7 @@ private:
QPlatformFontDatabase *m_fontDatabase;
QPlatformNativeInterface *m_nativeInterface;
+ QPlatformPrinterSupport *m_printerSupport;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro
index 93a226bd06..c6bf17f0ef 100644
--- a/src/plugins/platforms/xcb/xcb.pro
+++ b/src/plugins/platforms/xcb/xcb.pro
@@ -69,6 +69,7 @@ contains(QT_CONFIG, opengl) {
LIBS += -lxcb -lxcb-image -lxcb-keysyms -lxcb-icccm -lxcb-sync
include (../fontdatabases/genericunix/genericunix.pri)
+include (../printersupport/genericunix/genericunix.pri)
target.path += $$[QT_INSTALL_PLUGINS]/platforms
INSTALLS += target