Add QPlatformPrinterSupport.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 30 May 2011 09:18:46 +0000 (11:18 +0200)
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 30 May 2011 12:21:09 +0000 (14:21 +0200)
Add QPlatformPrinterSupport which provides functionality for
obtaining QPrinterInfo and creating native printer engines.

Rubber-stamped-by: Lars Knoll <lars.knoll@nokia.com>
22 files changed:
src/gui/kernel/qplatformintegration_qpa.cpp
src/gui/kernel/qplatformintegration_qpa.h
src/gui/painting/painting.pri
src/gui/painting/qcups.cpp
src/gui/painting/qcups_p.h
src/gui/painting/qplatformprintersupport_qpa.cpp [new file with mode: 0644]
src/gui/painting/qplatformprintersupport_qpa.h [new file with mode: 0644]
src/gui/painting/qprinter.cpp
src/gui/painting/qprinterinfo.cpp
src/gui/painting/qprinterinfo.h
src/gui/painting/qprinterinfo_p.h
src/gui/painting/qprinterinfo_unix.cpp
src/gui/painting/qprinterinfo_unix_p.h
src/plugins/platforms/printersupport/genericunix/genericunix.pri [new file with mode: 0644]
src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.cpp [new file with mode: 0644]
src/plugins/platforms/printersupport/genericunix/qgenericunixprintersupport.h [new file with mode: 0644]
src/plugins/platforms/printersupport/windows/qwindowsprintersupport.cpp [new file with mode: 0644]
src/plugins/platforms/printersupport/windows/qwindowsprintersupport.h [new file with mode: 0644]
src/plugins/platforms/printersupport/windows/windows.pri [new file with mode: 0644]
src/plugins/platforms/xcb/qxcbintegration.cpp
src/plugins/platforms/xcb/qxcbintegration.h
src/plugins/platforms/xcb/xcb.pro

index 7a95ffa..b335dd5 100644 (file)
@@ -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
index b42a162..c3d311e 100644 (file)
@@ -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
index 3e284c0..aaf3b04 100644 (file)
@@ -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 {
index 3ec5f72..76050d9 100644 (file)
@@ -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
index e6c5311..6b6a55a 100644 (file)
@@ -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 (file)
index 0000000..9fb25c9
--- /dev/null
@@ -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 (file)
index 0000000..90dd260
--- /dev/null
@@ -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
index bfd2c44..059331f 100644 (file)
@@ -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;
index a7ddc85..0049bd2 100644 (file)
@@ -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
index 9ff1bd1..72082cf 100644 (file)
@@ -77,6 +77,7 @@ private:
     QPrinterInfo(const QString &name);
 
 private:
+    friend class QPlatformPrinterSupport;
     Q_DECLARE_PRIVATE(QPrinterInfo)
     QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr;
 };
index a3f7d5d..a3c654e 100644 (file)
@@ -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;
 };
 
 
index 7420bbf..3c66481 100644 (file)
@@ -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
 }
 
index 1ededf5..f8721de 100644 (file)
@@ -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 (file)
index 0000000..ea9c8f0
--- /dev/null
@@ -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 (file)
index 0000000..54d866c
--- /dev/null
@@ -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 (file)
index 0000000..5d7b3b4
--- /dev/null
@@ -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 (file)
index 0000000..d5c185f
--- /dev/null
@@ -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 (file)
index 0000000..d648846
--- /dev/null
@@ -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 (file)
index 0000000..67d49b2
--- /dev/null
@@ -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
index 48aeae7..d47bec6 100644 (file)
@@ -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;
+}
index 647eb50..36c792f 100644 (file)
@@ -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
index 93a226b..c6bf17f 100644 (file)
@@ -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