$OpenBSD: patch-src_gui_painting_qprinter_cpp,v 1.1 2013/10/04 13:15:41 dcoppa Exp $

Improve CUPS support.

https://bugreports.qt-project.org/browse/QTBUG-6433
https://bugs.kde.org/show_bug.cgi?id=180051

--- src/gui/painting/qprinter.cpp.orig	Fri Jun  7 07:16:59 2013
+++ src/gui/painting/qprinter.cpp	Fri Sep 27 10:29:54 2013
@@ -609,6 +609,44 @@ QPrinter::QPrinter(PrinterMode mode)
                && d_ptr->paintEngine->type() != QPaintEngine::MacPrinter) {
         setOutputFormat(QPrinter::PdfFormat);
     }
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+    // fill in defaults from ppd file
+    QCUPSSupport cups;
+
+    int printernum = -1;
+    for (int i = 0; i < cups.availablePrintersCount(); i++) {
+        if (printerName().toLocal8Bit() == cups.availablePrinters()[i].name)
+            printernum = i;
+    }
+    if (printernum >= 0) {
+        cups.setCurrentPrinter(printernum);
+
+        const ppd_option_t* duplex = cups.ppdOption("Duplex");
+        if (duplex) {
+            // copy default ppd duplex to qt dialog
+            if (qstrcmp(duplex->defchoice, "DuplexTumble") == 0)
+                setDuplex(DuplexShortSide);
+            else if (qstrcmp(duplex->defchoice, "DuplexNoTumble") == 0)
+                setDuplex(DuplexLongSide);
+            else
+                setDuplex(DuplexNone);
+        }
+
+        if (cups.currentPPD()) {
+            // set default color
+            if (cups.currentPPD()->color_device)
+                setColorMode(Color);
+            else
+                setColorMode(GrayScale);
+        }
+
+        // set collation
+        const ppd_option_t *collate = cups.ppdOption("Collate");
+        if (collate)
+            setCollateCopies(qstrcmp(collate->defchoice, "True")==0);
+    }
+#endif
 }
 
 /*!
