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