Blame SOURCES/qt-cupsEnumDests.patch

402b94
diff -up qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp.cupsEnumDests qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp
402b94
--- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp.cupsEnumDests	2012-11-23 10:09:53.000000000 +0000
402b94
+++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp	2013-07-03 15:30:06.232936976 +0100
402b94
@@ -50,9 +50,19 @@
402b94
 
402b94
 QT_BEGIN_NAMESPACE
402b94
 
402b94
+typedef int (*CupsEnumDests)(unsigned flags, int msec, int *cancel,
402b94
+			     cups_ptype_t type, cups_ptype_t mask,
402b94
+			     cups_dest_cb_t cb, void *user_data);
402b94
+typedef http_t * (*CupsConnectDest)(cups_dest_t *dest, unsigned flags,
402b94
+				    int msec, int *cancel,
402b94
+				    char *resource, size_t resourcesize,
402b94
+				    cups_dest_cb_t cb, void *user_data);
402b94
+typedef int (*CupsCopyDest)(cups_dest_t *dest, int num_dests,
402b94
+			    cups_dest_t **dests);
402b94
 typedef int (*CupsGetDests)(cups_dest_t **dests);
402b94
 typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests);
402b94
 typedef const char* (*CupsGetPPD)(const char *printer);
402b94
+typedef const char* (*CupsGetPPD2)(http_t *http, const char *printer);
402b94
 typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options);
402b94
 typedef ppd_file_t* (*PPDOpenFile)(const char *filename);
402b94
 typedef void (*PPDMarkDefaults)(ppd_file_t *ppd);
402b94
@@ -66,12 +76,24 @@ typedef const char* (*CupsLangEncoding)(
402b94
 typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options);
402b94
 typedef int (*CupsTempFd)(char *name, int len);
402b94
 typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options);
402b94
+typedef int (*CupsPrintFile2)(http_t *http, const char *name, const char *filename, const char *title, int num_options, cups_option_t *options);
402b94
+
402b94
+typedef struct
402b94
+{
402b94
+    cups_dest_t *printers;
402b94
+    int num_printers;
402b94
+} EnumDestsContext;
402b94
 
402b94
 static bool cupsLoaded = false;
402b94
 static int qt_cups_num_printers = 0;
402b94
+static cups_dest_t *qt_cups_printers = 0;
402b94
+static CupsEnumDests _cupsEnumDests = 0;
402b94
+static CupsConnectDest _cupsConnectDest = 0;
402b94
+static CupsCopyDest _cupsCopyDest = 0;
402b94
 static CupsGetDests _cupsGetDests = 0;
402b94
 static CupsFreeDests _cupsFreeDests = 0;
402b94
 static CupsGetPPD _cupsGetPPD = 0;
402b94
+static CupsGetPPD2 _cupsGetPPD2 = 0;
402b94
 static PPDOpenFile _ppdOpenFile = 0;
402b94
 static PPDMarkDefaults _ppdMarkDefaults = 0;
402b94
 static PPDClose _ppdClose = 0;
402b94
@@ -84,14 +106,35 @@ static CupsLangEncoding _cupsLangEncodin
402b94
 static CupsAddOption _cupsAddOption = 0;
402b94
 static CupsTempFd _cupsTempFd = 0;
402b94
 static CupsPrintFile _cupsPrintFile = 0;
402b94
+static CupsPrintFile2 _cupsPrintFile2 = 0;
402b94
+
402b94
+static int enum_dest_cb (void *user_data, unsigned flags, cups_dest_t *dest)
402b94
+{
402b94
+    EnumDestsContext *context = (EnumDestsContext *) user_data;
402b94
+
402b94
+    if ((flags & (CUPS_DEST_FLAGS_UNCONNECTED |
402b94
+		  CUPS_DEST_FLAGS_REMOVED |
402b94
+		  CUPS_DEST_FLAGS_ERROR |
402b94
+		  CUPS_DEST_FLAGS_RESOLVING |
402b94
+		  CUPS_DEST_FLAGS_CONNECTING |
402b94
+		  CUPS_DEST_FLAGS_CANCELED)) == 0)
402b94
+	context->num_printers = _cupsCopyDest (dest, context->num_printers,
402b94
+					       &context->printers);
402b94
+
402b94
+    return 1;
402b94
+}
402b94
 
402b94
 static void resolveCups()
402b94
 {
402b94
     QLibrary cupsLib(QLatin1String("cups"), 2);
402b94
     if(cupsLib.load()) {
402b94
+        _cupsEnumDests = (CupsEnumDests) cupsLib.resolve("cupsEnumDests");
402b94
+	_cupsConnectDest = (CupsConnectDest) cupsLib.resolve("cupsConnectDest");
402b94
+	_cupsCopyDest = (CupsCopyDest) cupsLib.resolve("cupsCopyDest");
402b94
         _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
402b94
         _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
402b94
         _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
402b94
+        _cupsGetPPD2 = (CupsGetPPD2) cupsLib.resolve("cupsGetPPD2");
402b94
         _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
402b94
         _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
402b94
         _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
402b94
@@ -104,14 +147,27 @@ static void resolveCups()
402b94
         _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
402b94
         _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
402b94
         _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
402b94
+        _cupsPrintFile2 = (CupsPrintFile2) cupsLib.resolve("cupsPrintFile2");
402b94
 
402b94
-        if (_cupsGetDests && _cupsFreeDests) {
402b94
-            cups_dest_t *printers;
402b94
+	if (_cupsEnumDests && _cupsCopyDest &&
402b94
+	    _cupsConnectDest && _cupsGetPPD2 &&
402b94
+	    _cupsPrintFile2) {
402b94
+	    EnumDestsContext context;
402b94
+	    context.printers = 0;
402b94
+	    context.num_printers = 0;
402b94
+	    _cupsEnumDests(0, -1, 0, 0, 0,
402b94
+			   enum_dest_cb, &context);
402b94
+
402b94
+	    qt_cups_printers = context.printers;
402b94
+	    qt_cups_num_printers = context.num_printers;
402b94
+	} else if (_cupsGetDests && _cupsFreeDests) {
402b94
+	    cups_dest_t *printers;
402b94
             int num_printers = _cupsGetDests(&printers);
402b94
-            if (num_printers)
402b94
-                _cupsFreeDests(num_printers, printers);
402b94
-            qt_cups_num_printers = num_printers;
402b94
-        }
402b94
+
402b94
+	    if (num_printers)
402b94
+		_cupsFreeDests(num_printers, printers);
402b94
+	    qt_cups_num_printers = num_printers;
402b94
+	}
402b94
     }
402b94
     cupsLoaded = true;
402b94
 }
402b94
@@ -134,7 +190,15 @@ QCUPSSupport::QCUPSSupport()
402b94
         return;
402b94
 
402b94
     // Update the available printer count
402b94
-    qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
402b94
+    if (qt_cups_printers && _cupsCopyDest) {
402b94
+      int i;
402b94
+      for (i = 0; i < qt_cups_num_printers; ++i) {
402b94
+	  prnCount = _cupsCopyDest (&qt_cups_printers[i],
402b94
+				    prnCount,
402b94
+				    &printers);
402b94
+      }
402b94
+    } else
402b94
+      qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
402b94
 
402b94
     for (int i = 0; i <  prnCount; ++i) {
402b94
         if (printers[i].is_default) {
402b94
@@ -188,7 +252,19 @@ const ppd_file_t* QCUPSSupport::setCurre
402b94
     currPPD = 0;
402b94
     page_sizes = 0;
402b94
 
402b94
-    const char *ppdFile = _cupsGetPPD(printers[index].name);
402b94
+    const char *ppdFile = 0;
402b94
+    if (_cupsConnectDest && _cupsGetPPD2) {
402b94
+	char resource[HTTP_MAX_URI];
402b94
+	http_t *http = _cupsConnectDest (&printers[index], 0, -1, 0,
402b94
+					 resource, sizeof (resource),
402b94
+					 0, 0);
402b94
+	if (http) {
402b94
+	    char *name = strrchr (resource, '/');
402b94
+	    if (name)
402b94
+		ppdFile = _cupsGetPPD2 (http, ++name);
402b94
+	}
402b94
+    } else
402b94
+	ppdFile = _cupsGetPPD(printers[index].name);
402b94
 
402b94
     if (!ppdFile)
402b94
       return 0;
402b94
@@ -343,7 +419,29 @@ bool QCUPSSupport::printerHasPPD(const c
402b94
 {
402b94
     if (!isAvailable())
402b94
         return false;
402b94
-    const char *ppdFile = _cupsGetPPD(printerName);
402b94
+
402b94
+    const char *ppdFile = 0;
402b94
+    if (_cupsConnectDest && _cupsGetPPD2) {
402b94
+	int i;
402b94
+	for (i = 0; i < prnCount; ++i)
402b94
+	    if (!strcmp (printers[i].name, printerName))
402b94
+		break;
402b94
+
402b94
+	if (i == prnCount)
402b94
+	    return false;
402b94
+
402b94
+	char resource[HTTP_MAX_URI];
402b94
+	http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
402b94
+					 resource, sizeof (resource),
402b94
+					 0, 0);
402b94
+	if (http) {
402b94
+	    char *name = strrchr (resource, '/');
402b94
+	    if (name)
402b94
+		ppdFile = _cupsGetPPD2 (http, ++name);
402b94
+	}
402b94
+    } else
402b94
+	ppdFile = _cupsGetPPD(printerName);
402b94
+
402b94
     if (ppdFile)
402b94
         unlink(ppdFile);
402b94
     return (ppdFile != 0);
402b94
@@ -394,6 +492,26 @@ QPair<int, QString> QCUPSSupport::tempFd
402b94
 int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title,
402b94
                             int num_options, cups_option_t * options)
402b94
 {
402b94
+    if (_cupsConnectDest && _cupsPrintFile2) {
402b94
+	int i;
402b94
+	for (i = 0; i < prnCount; ++i)
402b94
+	    if (!strcmp (printers[i].name, printerName))
402b94
+		break;
402b94
+
402b94
+	if (i != prnCount) {
402b94
+	    char resource[HTTP_MAX_URI];
402b94
+	    http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
402b94
+					     resource, sizeof (resource),
402b94
+					     0, 0);
402b94
+	    if (http) {
402b94
+		char *name = strrchr (resource, '/');
402b94
+		if (name)
402b94
+		    return _cupsPrintFile2 (http, ++name, filename, title,
402b94
+					    num_options, options);
402b94
+	    }
402b94
+	}
402b94
+    }
402b94
+
402b94
     return _cupsPrintFile(printerName, filename, title, num_options, options);
402b94
 }
402b94
 
402b94
diff -up qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h.cupsEnumDests qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h
402b94
--- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h.cupsEnumDests	2012-11-23 10:09:53.000000000 +0000
402b94
+++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h	2013-07-03 15:27:24.733343017 +0100
402b94
@@ -92,7 +92,7 @@ public:
402b94
 
402b94
     QStringList options() const;
402b94
 
402b94
-    static bool printerHasPPD(const char *printerName);
402b94
+    bool printerHasPPD(const char *printerName);
402b94
 
402b94
     QString unicodeString(const char *s);
402b94
 
402b94
diff -up qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp.cupsEnumDests qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp
402b94
--- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp.cupsEnumDests	2013-07-03 15:27:24.531342277 +0100
402b94
+++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp	2013-07-03 15:27:24.733343017 +0100
402b94
@@ -844,7 +844,7 @@ void QPrinter::setPrinterName(const QStr
402b94
     if(d->use_default_engine
402b94
         && d->outputFormat == QPrinter::NativeFormat) {
402b94
         if (QCUPSSupport::cupsVersion() >= 10200
402b94
-            && QCUPSSupport::printerHasPPD(name.toLocal8Bit().constData()))
402b94
+            && QCUPSSupport().printerHasPPD(name.toLocal8Bit().constData()))
402b94
             setOutputFormat(QPrinter::PdfFormat);
402b94
         else
402b94
             setOutputFormat(QPrinter::PostScriptFormat);