1 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
2 --- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp.cupsEnumDests 2012-11-23 10:09:53.000000000 +0000
3 +++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups.cpp 2013-07-03 15:30:06.232936976 +0100
8 +typedef int (*CupsEnumDests)(unsigned flags, int msec, int *cancel,
9 + cups_ptype_t type, cups_ptype_t mask,
10 + cups_dest_cb_t cb, void *user_data);
11 +typedef http_t * (*CupsConnectDest)(cups_dest_t *dest, unsigned flags,
12 + int msec, int *cancel,
13 + char *resource, size_t resourcesize,
14 + cups_dest_cb_t cb, void *user_data);
15 +typedef int (*CupsCopyDest)(cups_dest_t *dest, int num_dests,
16 + cups_dest_t **dests);
17 typedef int (*CupsGetDests)(cups_dest_t **dests);
18 typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests);
19 typedef const char* (*CupsGetPPD)(const char *printer);
20 +typedef const char* (*CupsGetPPD2)(http_t *http, const char *printer);
21 typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options);
22 typedef ppd_file_t* (*PPDOpenFile)(const char *filename);
23 typedef void (*PPDMarkDefaults)(ppd_file_t *ppd);
24 @@ -66,12 +76,24 @@ typedef const char* (*CupsLangEncoding)(
25 typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options);
26 typedef int (*CupsTempFd)(char *name, int len);
27 typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options);
28 +typedef int (*CupsPrintFile2)(http_t *http, const char *name, const char *filename, const char *title, int num_options, cups_option_t *options);
32 + cups_dest_t *printers;
36 static bool cupsLoaded = false;
37 static int qt_cups_num_printers = 0;
38 +static cups_dest_t *qt_cups_printers = 0;
39 +static CupsEnumDests _cupsEnumDests = 0;
40 +static CupsConnectDest _cupsConnectDest = 0;
41 +static CupsCopyDest _cupsCopyDest = 0;
42 static CupsGetDests _cupsGetDests = 0;
43 static CupsFreeDests _cupsFreeDests = 0;
44 static CupsGetPPD _cupsGetPPD = 0;
45 +static CupsGetPPD2 _cupsGetPPD2 = 0;
46 static PPDOpenFile _ppdOpenFile = 0;
47 static PPDMarkDefaults _ppdMarkDefaults = 0;
48 static PPDClose _ppdClose = 0;
49 @@ -84,14 +106,35 @@ static CupsLangEncoding _cupsLangEncodin
50 static CupsAddOption _cupsAddOption = 0;
51 static CupsTempFd _cupsTempFd = 0;
52 static CupsPrintFile _cupsPrintFile = 0;
53 +static CupsPrintFile2 _cupsPrintFile2 = 0;
55 +static int enum_dest_cb (void *user_data, unsigned flags, cups_dest_t *dest)
57 + EnumDestsContext *context = (EnumDestsContext *) user_data;
59 + if ((flags & (CUPS_DEST_FLAGS_UNCONNECTED |
60 + CUPS_DEST_FLAGS_REMOVED |
61 + CUPS_DEST_FLAGS_ERROR |
62 + CUPS_DEST_FLAGS_RESOLVING |
63 + CUPS_DEST_FLAGS_CONNECTING |
64 + CUPS_DEST_FLAGS_CANCELED)) == 0)
65 + context->num_printers = _cupsCopyDest (dest, context->num_printers,
66 + &context->printers);
71 static void resolveCups()
73 QLibrary cupsLib(QLatin1String("cups"), 2);
75 + _cupsEnumDests = (CupsEnumDests) cupsLib.resolve("cupsEnumDests");
76 + _cupsConnectDest = (CupsConnectDest) cupsLib.resolve("cupsConnectDest");
77 + _cupsCopyDest = (CupsCopyDest) cupsLib.resolve("cupsCopyDest");
78 _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
79 _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
80 _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
81 + _cupsGetPPD2 = (CupsGetPPD2) cupsLib.resolve("cupsGetPPD2");
82 _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
83 _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
84 _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
85 @@ -104,14 +147,27 @@ static void resolveCups()
86 _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
87 _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
88 _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
89 + _cupsPrintFile2 = (CupsPrintFile2) cupsLib.resolve("cupsPrintFile2");
91 - if (_cupsGetDests && _cupsFreeDests) {
92 - cups_dest_t *printers;
93 + if (_cupsEnumDests && _cupsCopyDest &&
94 + _cupsConnectDest && _cupsGetPPD2 &&
96 + EnumDestsContext context;
97 + context.printers = 0;
98 + context.num_printers = 0;
99 + _cupsEnumDests(0, -1, 0, 0, 0,
100 + enum_dest_cb, &context);
102 + qt_cups_printers = context.printers;
103 + qt_cups_num_printers = context.num_printers;
104 + } else if (_cupsGetDests && _cupsFreeDests) {
105 + cups_dest_t *printers;
106 int num_printers = _cupsGetDests(&printers);
108 - _cupsFreeDests(num_printers, printers);
109 - qt_cups_num_printers = num_printers;
113 + _cupsFreeDests(num_printers, printers);
114 + qt_cups_num_printers = num_printers;
119 @@ -134,7 +190,15 @@ QCUPSSupport::QCUPSSupport()
122 // Update the available printer count
123 - qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
124 + if (qt_cups_printers && _cupsCopyDest) {
126 + for (i = 0; i < qt_cups_num_printers; ++i) {
127 + prnCount = _cupsCopyDest (&qt_cups_printers[i],
132 + qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
134 for (int i = 0; i < prnCount; ++i) {
135 if (printers[i].is_default) {
136 @@ -188,7 +252,19 @@ const ppd_file_t* QCUPSSupport::setCurre
140 - const char *ppdFile = _cupsGetPPD(printers[index].name);
141 + const char *ppdFile = 0;
142 + if (_cupsConnectDest && _cupsGetPPD2) {
143 + char resource[HTTP_MAX_URI];
144 + http_t *http = _cupsConnectDest (&printers[index], 0, -1, 0,
145 + resource, sizeof (resource),
148 + char *name = strrchr (resource, '/');
150 + ppdFile = _cupsGetPPD2 (http, ++name);
153 + ppdFile = _cupsGetPPD(printers[index].name);
157 @@ -343,7 +419,29 @@ bool QCUPSSupport::printerHasPPD(const c
161 - const char *ppdFile = _cupsGetPPD(printerName);
163 + const char *ppdFile = 0;
164 + if (_cupsConnectDest && _cupsGetPPD2) {
166 + for (i = 0; i < prnCount; ++i)
167 + if (!strcmp (printers[i].name, printerName))
173 + char resource[HTTP_MAX_URI];
174 + http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
175 + resource, sizeof (resource),
178 + char *name = strrchr (resource, '/');
180 + ppdFile = _cupsGetPPD2 (http, ++name);
183 + ppdFile = _cupsGetPPD(printerName);
187 return (ppdFile != 0);
188 @@ -394,6 +492,26 @@ QPair<int, QString> QCUPSSupport::tempFd
189 int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title,
190 int num_options, cups_option_t * options)
192 + if (_cupsConnectDest && _cupsPrintFile2) {
194 + for (i = 0; i < prnCount; ++i)
195 + if (!strcmp (printers[i].name, printerName))
198 + if (i != prnCount) {
199 + char resource[HTTP_MAX_URI];
200 + http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
201 + resource, sizeof (resource),
204 + char *name = strrchr (resource, '/');
206 + return _cupsPrintFile2 (http, ++name, filename, title,
207 + num_options, options);
212 return _cupsPrintFile(printerName, filename, title, num_options, options);
215 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
216 --- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h.cupsEnumDests 2012-11-23 10:09:53.000000000 +0000
217 +++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qcups_p.h 2013-07-03 15:27:24.733343017 +0100
218 @@ -92,7 +92,7 @@ public:
220 QStringList options() const;
222 - static bool printerHasPPD(const char *printerName);
223 + bool printerHasPPD(const char *printerName);
225 QString unicodeString(const char *s);
227 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
228 --- qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp.cupsEnumDests 2013-07-03 15:27:24.531342277 +0100
229 +++ qt-everywhere-opensource-src-4.8.4/src/gui/painting/qprinter.cpp 2013-07-03 15:27:24.733343017 +0100
230 @@ -844,7 +844,7 @@ void QPrinter::setPrinterName(const QStr
231 if(d->use_default_engine
232 && d->outputFormat == QPrinter::NativeFormat) {
233 if (QCUPSSupport::cupsVersion() >= 10200
234 - && QCUPSSupport::printerHasPPD(name.toLocal8Bit().constData()))
235 + && QCUPSSupport().printerHasPPD(name.toLocal8Bit().constData()))
236 setOutputFormat(QPrinter::PdfFormat);
238 setOutputFormat(QPrinter::PostScriptFormat);