]> git.pld-linux.org Git - packages/qt4.git/blob - qt-cupsEnumDests.patch
rebuild with openssl 3.0.0
[packages/qt4.git] / qt-cupsEnumDests.patch
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
4 @@ -50,9 +50,19 @@
5  
6  QT_BEGIN_NAMESPACE
7  
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);
29 +
30 +typedef struct
31 +{
32 +    cups_dest_t *printers;
33 +    int num_printers;
34 +} EnumDestsContext;
35  
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;
54 +
55 +static int enum_dest_cb (void *user_data, unsigned flags, cups_dest_t *dest)
56 +{
57 +    EnumDestsContext *context = (EnumDestsContext *) user_data;
58 +
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);
67 +
68 +    return 1;
69 +}
70  
71  static void resolveCups()
72  {
73      QLibrary cupsLib(QLatin1String("cups"), 2);
74      if(cupsLib.load()) {
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");
90  
91 -        if (_cupsGetDests && _cupsFreeDests) {
92 -            cups_dest_t *printers;
93 +       if (_cupsEnumDests && _cupsCopyDest &&
94 +           _cupsConnectDest && _cupsGetPPD2 &&
95 +           _cupsPrintFile2) {
96 +           EnumDestsContext context;
97 +           context.printers = 0;
98 +           context.num_printers = 0;
99 +           _cupsEnumDests(0, -1, 0, 0, 0,
100 +                          enum_dest_cb, &context);
101 +
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);
107 -            if (num_printers)
108 -                _cupsFreeDests(num_printers, printers);
109 -            qt_cups_num_printers = num_printers;
110 -        }
111 +
112 +           if (num_printers)
113 +               _cupsFreeDests(num_printers, printers);
114 +           qt_cups_num_printers = num_printers;
115 +       }
116      }
117      cupsLoaded = true;
118  }
119 @@ -134,7 +190,15 @@ QCUPSSupport::QCUPSSupport()
120          return;
121  
122      // Update the available printer count
123 -    qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
124 +    if (qt_cups_printers && _cupsCopyDest) {
125 +      int i;
126 +      for (i = 0; i < qt_cups_num_printers; ++i) {
127 +         prnCount = _cupsCopyDest (&qt_cups_printers[i],
128 +                                   prnCount,
129 +                                   &printers);
130 +      }
131 +    } else
132 +      qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
133  
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
137      currPPD = 0;
138      page_sizes = 0;
139  
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),
146 +                                        0, 0);
147 +       if (http) {
148 +           char *name = strrchr (resource, '/');
149 +           if (name)
150 +               ppdFile = _cupsGetPPD2 (http, ++name);
151 +       }
152 +    } else
153 +       ppdFile = _cupsGetPPD(printers[index].name);
154  
155      if (!ppdFile)
156        return 0;
157 @@ -343,7 +419,29 @@ bool QCUPSSupport::printerHasPPD(const c
158  {
159      if (!isAvailable())
160          return false;
161 -    const char *ppdFile = _cupsGetPPD(printerName);
162 +
163 +    const char *ppdFile = 0;
164 +    if (_cupsConnectDest && _cupsGetPPD2) {
165 +       int i;
166 +       for (i = 0; i < prnCount; ++i)
167 +           if (!strcmp (printers[i].name, printerName))
168 +               break;
169 +
170 +       if (i == prnCount)
171 +           return false;
172 +
173 +       char resource[HTTP_MAX_URI];
174 +       http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
175 +                                        resource, sizeof (resource),
176 +                                        0, 0);
177 +       if (http) {
178 +           char *name = strrchr (resource, '/');
179 +           if (name)
180 +               ppdFile = _cupsGetPPD2 (http, ++name);
181 +       }
182 +    } else
183 +       ppdFile = _cupsGetPPD(printerName);
184 +
185      if (ppdFile)
186          unlink(ppdFile);
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)
191  {
192 +    if (_cupsConnectDest && _cupsPrintFile2) {
193 +       int i;
194 +       for (i = 0; i < prnCount; ++i)
195 +           if (!strcmp (printers[i].name, printerName))
196 +               break;
197 +
198 +       if (i != prnCount) {
199 +           char resource[HTTP_MAX_URI];
200 +           http_t *http = _cupsConnectDest (&printers[i], 0, -1, 0,
201 +                                            resource, sizeof (resource),
202 +                                            0, 0);
203 +           if (http) {
204 +               char *name = strrchr (resource, '/');
205 +               if (name)
206 +                   return _cupsPrintFile2 (http, ++name, filename, title,
207 +                                           num_options, options);
208 +           }
209 +       }
210 +    }
211 +
212      return _cupsPrintFile(printerName, filename, title, num_options, options);
213  }
214  
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:
219  
220      QStringList options() const;
221  
222 -    static bool printerHasPPD(const char *printerName);
223 +    bool printerHasPPD(const char *printerName);
224  
225      QString unicodeString(const char *s);
226  
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);
237          else
238              setOutputFormat(QPrinter::PostScriptFormat);
This page took 0.047138 seconds and 3 git commands to generate.