forked from pool/libqt5-qtbase
8d99fc9a15
- Update to 5.11.0 * New bugfix release * For more details please see: * http://code.qt.io/cgit/qt/qtbase.git/plain/dist/changes-5.11.0/?h=v5.11.0 - Remove patches, now upstream: * 0001-Do-a-static_cast-in-bit-blasts-that-are-UB.patch * 0001-sqlite-Check-that-there-are-values-to-be-set-when-bi.patch * 0002-sqlite-Bind-duplicated-named-placeholders-correctly.patch * 0003-sqlite-Prevent-a-crash-when-sqlite-does-not-detect-a.patch - Update to 5.11.0-rc * New bugfix release * No changelog available - Update to 5.11.0-beta4 * New bugfix release * No changelog available - Refresh patches: * force-cmake-private-headers.patch - Remove patches, now upstream: * 0001-Extend-the-MariaDB-define-check-to-cover-the-later-v.patch - Update to 5.11.0-beta3 * New bugfix release * No changelog available - Update to 5.11.0-beta2 * New bugfix release * No changelog available (forwarded request 611481 from Vogtinator) OBS-URL: https://build.opensuse.org/request/show/611696 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/libqt5-qtbase?expand=0&rev=81
290 lines
11 KiB
Diff
290 lines
11 KiB
Diff
From d3faa880d19d9bf5b411dc81c0d5d881a323997d Mon Sep 17 00:00:00 2001
|
|
From: Antonio Larrosa <larrosa@kde.org>
|
|
Date: Tue, 6 Jun 2017 16:34:32 +0200
|
|
Subject: [PATCH] Add remote print queue support
|
|
|
|
Cups servers which announce themselves on avahi will be shown in
|
|
the printer dialog. This adds a delay the first time the print dialog
|
|
is opened in order to search for print queues . Because of this delay,
|
|
the remote print queue discovery is disabled by default and can be enabled
|
|
by setting the QT_ENABLE_PRINTER_DISCOVERY environment variable to 1.
|
|
|
|
The commit to Qt (which enabled the discovery by default) has
|
|
a Change-Id: Ib70715d331e8f380a3c9039011bb8521986652aa
|
|
---
|
|
src/plugins/printsupport/cups/qcupsprintengine.cpp | 35 +++++++-
|
|
.../printsupport/cups/qcupsprintersupport.cpp | 95 ++++++++++++++++++++--
|
|
.../printsupport/cups/qcupsprintersupport_p.h | 8 ++
|
|
src/plugins/printsupport/cups/qppdprintdevice.cpp | 33 +++++++-
|
|
4 files changed, 160 insertions(+), 11 deletions(-)
|
|
|
|
Index: qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintengine.cpp
|
|
===================================================================
|
|
--- qtbase-everywhere-src-5.11.0-beta1.orig/src/plugins/printsupport/cups/qcupsprintengine.cpp
|
|
+++ qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintengine.cpp
|
|
@@ -48,6 +48,7 @@
|
|
#include <qbuffer.h>
|
|
#include "private/qcups_p.h" // Only needed for PPK_CupsOptions
|
|
#include <QtGui/qpagelayout.h>
|
|
+#include "qcupsprintersupport_p.h"
|
|
|
|
#include <cups/cups.h>
|
|
|
|
@@ -243,8 +244,40 @@ void QCupsPrintEnginePrivate::closePrint
|
|
const auto parts = printerName.splitRef(QLatin1Char('/'));
|
|
const auto printerOriginalName = parts.at(0);
|
|
cups_option_t* optPtr = cupsOptStruct.size() ? &cupsOptStruct.first() : 0;
|
|
- cupsPrintFile(printerOriginalName.toLocal8Bit().constData(), tempFile.toLocal8Bit().constData(),
|
|
+
|
|
+ bool fallbackToLocal = false;
|
|
+ cups_dest_t *cupsDest = NULL;
|
|
+
|
|
+ if (!qEnvironmentVariableIsSet("QT_ENABLE_PRINTER_DISCOVERY")) {
|
|
+ fallbackToLocal = true;
|
|
+ } else {
|
|
+ cupsDest = cupsGetDest(printerOriginalName.toLocal8Bit(), NULL, QCupsPrinterSupport::cupsPrintersCount(), QCupsPrinterSupport::cupsPrinters());
|
|
+ }
|
|
+
|
|
+ if (cupsDest) {
|
|
+ char resource[HTTP_MAX_URI];
|
|
+ http_t *http = cupsConnectDest (cupsDest, 0, -1, 0,
|
|
+ resource, sizeof (resource),
|
|
+ 0, 0);
|
|
+ if (http) {
|
|
+ char *name = strrchr (resource, '/');
|
|
+ qDebug() << "resource:" << resource << "," << name;
|
|
+ if (name)
|
|
+ cupsPrintFile2 (http, ++name, tempFile.toLocal8Bit().constData(),
|
|
title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);
|
|
+ httpClose(http);
|
|
+ } else {
|
|
+ fallbackToLocal=true;
|
|
+ }
|
|
+ }
|
|
+ else {
|
|
+ fallbackToLocal=true;
|
|
+ }
|
|
+
|
|
+ if (fallbackToLocal) {
|
|
+ cupsPrintFile(printerOriginalName.toLocal8Bit().constData(), tempFile.toLocal8Bit().constData(),
|
|
+ title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);
|
|
+ }
|
|
|
|
QFile::remove(tempFile);
|
|
}
|
|
Index: qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintersupport.cpp
|
|
===================================================================
|
|
--- qtbase-everywhere-src-5.11.0-beta1.orig/src/plugins/printsupport/cups/qcupsprintersupport.cpp
|
|
+++ qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintersupport.cpp
|
|
@@ -52,6 +52,35 @@
|
|
# include <cups/language.h>
|
|
#endif
|
|
|
|
+typedef struct
|
|
+{
|
|
+ cups_dest_t *printers;
|
|
+ int num_printers;
|
|
+} EnumDestsContext;
|
|
+
|
|
+static int enum_dest_cb2 (void *user_data, unsigned flags, cups_dest_t *dest)
|
|
+{
|
|
+ EnumDestsContext *context = (EnumDestsContext *) user_data;
|
|
+ if ((flags & (CUPS_DEST_FLAGS_UNCONNECTED |
|
|
+ CUPS_DEST_FLAGS_REMOVED |
|
|
+ CUPS_DEST_FLAGS_ERROR |
|
|
+ CUPS_DEST_FLAGS_RESOLVING |
|
|
+ CUPS_DEST_FLAGS_CONNECTING |
|
|
+ CUPS_DEST_FLAGS_CANCELED)) == 0) {
|
|
+
|
|
+ context->num_printers = cupsCopyDest (dest, context->num_printers,
|
|
+ &context->printers);
|
|
+
|
|
+ // Also copy whether this is the local default /
|
|
+ cups_dest_t *the_dest;
|
|
+ the_dest = cupsGetDest(dest->name, dest->instance,
|
|
+ context->num_printers, context->printers);
|
|
+ the_dest->is_default = dest->is_default;
|
|
+ qDebug() << dest->name << "_" << dest->instance << "_" << context->num_printers;
|
|
+ }
|
|
+ return 1;
|
|
+}
|
|
+
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
QCupsPrinterSupport::QCupsPrinterSupport()
|
|
@@ -81,17 +110,35 @@ QPrintDevice QCupsPrinterSupport::create
|
|
|
|
QStringList QCupsPrinterSupport::availablePrintDeviceIds() const
|
|
{
|
|
- QStringList list;
|
|
+/* // Reset cache disabled for now
|
|
+ if (qt_cups_printers) {
|
|
+ cupsFreeDests( qt_cups_num_printers, qt_cups_printers );
|
|
+ qt_cups_printers = NULL;
|
|
+ qt_cups_num_printers = 0;
|
|
+ }
|
|
+*/
|
|
cups_dest_t *dests;
|
|
- int count = cupsGetDests(&dests);
|
|
- list.reserve(count);
|
|
- for (int i = 0; i < count; ++i) {
|
|
+ bool enablePrinterDiscovery = qEnvironmentVariableIsSet("QT_ENABLE_PRINTER_DISCOVERY");
|
|
+ if (!enablePrinterDiscovery) {
|
|
+ qt_cups_num_printers = cupsGetDests(&dests);
|
|
+ } else {
|
|
+ if (qt_cups_num_printers == 0)
|
|
+ QCupsPrinterSupport::fillCupsPrinters();
|
|
+
|
|
+ dests = qt_cups_printers;
|
|
+ }
|
|
+ QStringList list;
|
|
+ list.reserve(qt_cups_num_printers);
|
|
+ for (int i = 0; i < qt_cups_num_printers; ++i) {
|
|
QString printerId = QString::fromLocal8Bit(dests[i].name);
|
|
if (dests[i].instance)
|
|
printerId += QLatin1Char('/') + QString::fromLocal8Bit(dests[i].instance);
|
|
list.append(printerId);
|
|
}
|
|
- cupsFreeDests(count, dests);
|
|
+ if (!enablePrinterDiscovery) {
|
|
+ cupsFreeDests(qt_cups_num_printers, dests);
|
|
+ }
|
|
+
|
|
return list;
|
|
}
|
|
|
|
@@ -99,8 +146,18 @@ QString QCupsPrinterSupport::defaultPrin
|
|
{
|
|
QString printerId;
|
|
cups_dest_t *dests;
|
|
- int count = cupsGetDests(&dests);
|
|
- for (int i = 0; i < count; ++i) {
|
|
+
|
|
+ bool enablePrinterDiscovery = qEnvironmentVariableIsSet("QT_ENABLE_PRINTER_DISCOVERY");
|
|
+ if (!enablePrinterDiscovery) {
|
|
+ qt_cups_num_printers = cupsGetDests(&dests);
|
|
+ } else {
|
|
+ if (qt_cups_num_printers == 0)
|
|
+ QCupsPrinterSupport::fillCupsPrinters();
|
|
+
|
|
+ dests = qt_cups_printers;
|
|
+ }
|
|
+
|
|
+ for (int i = 0; i < qt_cups_num_printers; ++i) {
|
|
if (dests[i].is_default) {
|
|
printerId = QString::fromLocal8Bit(dests[i].name);
|
|
if (dests[i].instance) {
|
|
@@ -109,8 +166,30 @@ QString QCupsPrinterSupport::defaultPrin
|
|
}
|
|
}
|
|
}
|
|
- cupsFreeDests(count, dests);
|
|
+ if (!enablePrinterDiscovery) {
|
|
+ cupsFreeDests(qt_cups_num_printers, dests);
|
|
+ }
|
|
return printerId;
|
|
}
|
|
|
|
+void QCupsPrinterSupport::fillCupsPrinters()
|
|
+{
|
|
+ EnumDestsContext context;
|
|
+ context.printers = 0;
|
|
+ context.num_printers = 0;
|
|
+
|
|
+ qDebug() << "begin enumerating printers";
|
|
+
|
|
+ cupsEnumDests(CUPS_DEST_FLAGS_NONE, 4000, NULL, 0, 0,
|
|
+ enum_dest_cb2, &context);
|
|
+
|
|
+ qDebug() << "end enumerating printers";
|
|
+ qt_cups_printers = context.printers;
|
|
+ qt_cups_num_printers = context.num_printers;
|
|
+}
|
|
+
|
|
+cups_dest_t *QCupsPrinterSupport::qt_cups_printers = NULL;
|
|
+int QCupsPrinterSupport::qt_cups_num_printers = 0;
|
|
+
|
|
+
|
|
QT_END_NAMESPACE
|
|
Index: qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintersupport_p.h
|
|
===================================================================
|
|
--- qtbase-everywhere-src-5.11.0-beta1.orig/src/plugins/printsupport/cups/qcupsprintersupport_p.h
|
|
+++ qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qcupsprintersupport_p.h
|
|
@@ -56,6 +56,8 @@
|
|
|
|
#include <QtCore/qstringlist.h>
|
|
|
|
+#include <cups/cups.h>
|
|
+
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class QCupsPrinterSupport : public QPlatformPrinterSupport
|
|
@@ -71,8 +73,14 @@ public:
|
|
QStringList availablePrintDeviceIds() const override;
|
|
QString defaultPrintDeviceId() const override;
|
|
|
|
+ static void fillCupsPrinters();
|
|
+ static cups_dest_t *cupsPrinters() { return qt_cups_printers; };
|
|
+ static int cupsPrintersCount() { return qt_cups_num_printers; };
|
|
private:
|
|
QString cupsOption(int i, const QString &key) const;
|
|
+
|
|
+ static cups_dest_t *qt_cups_printers;
|
|
+ static int qt_cups_num_printers;
|
|
};
|
|
|
|
QT_END_NAMESPACE
|
|
Index: qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qppdprintdevice.cpp
|
|
===================================================================
|
|
--- qtbase-everywhere-src-5.11.0-beta1.orig/src/plugins/printsupport/cups/qppdprintdevice.cpp
|
|
+++ qtbase-everywhere-src-5.11.0-beta1/src/plugins/printsupport/cups/qppdprintdevice.cpp
|
|
@@ -39,6 +39,7 @@
|
|
|
|
#include "qppdprintdevice.h"
|
|
|
|
+#include "qcupsprintersupport_p.h"
|
|
#include <QtCore/QMimeDatabase>
|
|
#include <qdebug.h>
|
|
|
|
@@ -493,10 +494,38 @@ void QPpdPrintDevice::loadPrinter()
|
|
m_cupsDest = 0;
|
|
}
|
|
|
|
+ bool enablePrinterDiscovery = qEnvironmentVariableIsSet("QT_ENABLE_PRINTER_DISCOVERY");
|
|
+
|
|
// Get the print instance and PPD file
|
|
- m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance.isNull() ? nullptr : m_cupsInstance.constData());
|
|
+
|
|
+ if (!enablePrinterDiscovery) {
|
|
+ m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance.isNull() ? nullptr : m_cupsInstance.constData());
|
|
+ } else {
|
|
+ cups_dest_t *cupsDest = cupsGetDest( m_cupsName,
|
|
+ (m_cupsInstance.isEmpty() ? nullptr : m_cupsInstance.data()),
|
|
+ QCupsPrinterSupport::cupsPrintersCount(),
|
|
+ QCupsPrinterSupport::cupsPrinters() );
|
|
+ cupsCopyDest(cupsDest, 0, &m_cupsDest);
|
|
+ }
|
|
if (m_cupsDest) {
|
|
- const char *ppdFile = cupsGetPPD(m_cupsName);
|
|
+ char resource[HTTP_MAX_URI];
|
|
+ http_t *http = NULL;
|
|
+ const char *ppdFile = NULL;
|
|
+
|
|
+ if (enablePrinterDiscovery) {
|
|
+ http = cupsConnectDest (m_cupsDest, 0, -1, 0,
|
|
+ resource, sizeof (resource),
|
|
+ 0, 0);
|
|
+ }
|
|
+ if (http) {
|
|
+ char *name = strrchr (resource, '/');
|
|
+ if (name)
|
|
+ ppdFile = cupsGetPPD2 (http, ++name);
|
|
+ httpClose(http);
|
|
+ } else {
|
|
+ ppdFile = cupsGetPPD(m_cupsName);
|
|
+ }
|
|
+
|
|
if (ppdFile) {
|
|
m_ppd = ppdOpenFile(ppdFile);
|
|
unlink(ppdFile);
|