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