Merge lp:~jonas-drange/ubuntu-ui-extras/add-cmake-extras into lp:ubuntu-ui-extras
- add-cmake-extras
- Merge into trunk
Proposed by
Jonas G. Drange
Status: | Superseded |
---|---|
Proposed branch: | lp:~jonas-drange/ubuntu-ui-extras/add-cmake-extras |
Merge into: | lp:ubuntu-ui-extras |
Diff against target: |
9817 lines (+9465/-4) 55 files modified
debian/control (+3/-0) modules/Ubuntu/Components/Extras/CMakeLists.txt (+1/-0) modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml (+117/-0) modules/Ubuntu/Components/Extras/Example/Printers.qml (+603/-0) modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt (+68/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp (+350/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend.h (+223/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+787/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h (+152/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp (+119/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.h (+47/-0) modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp (+988/-0) modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h (+121/-0) modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.cpp (+128/-0) modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.h (+61/-0) modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp (+53/-0) modules/Ubuntu/Components/Extras/Printers/cups/printerloader.h (+49/-0) modules/Ubuntu/Components/Extras/Printers/enums.h (+141/-0) modules/Ubuntu/Components/Extras/Printers/i18n.cpp (+44/-0) modules/Ubuntu/Components/Extras/Printers/i18n.h (+29/-0) modules/Ubuntu/Components/Extras/Printers/models/drivermodel.cpp (+175/-0) modules/Ubuntu/Components/Extras/Printers/models/drivermodel.h (+82/-0) modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp (+391/-0) modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h (+125/-0) modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+533/-0) modules/Ubuntu/Components/Extras/Printers/models/printermodel.h (+161/-0) modules/Ubuntu/Components/Extras/Printers/org.cups.cupsd.Notifier.xml (+146/-0) modules/Ubuntu/Components/Extras/Printers/plugin.cpp (+58/-0) modules/Ubuntu/Components/Extras/Printers/plugin.h (+33/-0) modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+358/-0) modules/Ubuntu/Components/Extras/Printers/printer/printer.h (+109/-0) modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp (+514/-0) modules/Ubuntu/Components/Extras/Printers/printer/printerjob.h (+174/-0) modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.cpp (+69/-0) modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.h (+55/-0) modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+251/-0) modules/Ubuntu/Components/Extras/Printers/printers/printers.h (+107/-0) modules/Ubuntu/Components/Extras/Printers/printers_global.h (+23/-0) modules/Ubuntu/Components/Extras/Printers/qmldir (+2/-0) modules/Ubuntu/Components/Extras/Printers/structs.h (+103/-0) modules/Ubuntu/Components/Extras/Printers/utils.h (+110/-0) po/CMakeLists.txt (+2/-1) po/ubuntu-ui-extras.pot (+27/-3) tests/unittests/CMakeLists.txt (+2/-0) tests/unittests/Printers/CMakeLists.txt (+48/-0) tests/unittests/Printers/mockbackend.h (+443/-0) tests/unittests/Printers/tst_drivermodel.cpp (+136/-0) tests/unittests/Printers/tst_jobfilter.cpp (+55/-0) tests/unittests/Printers/tst_jobmodel.cpp (+120/-0) tests/unittests/Printers/tst_printer.cpp (+284/-0) tests/unittests/Printers/tst_printerfilter.cpp (+117/-0) tests/unittests/Printers/tst_printerjob.cpp (+207/-0) tests/unittests/Printers/tst_printermodel.cpp (+161/-0) tests/unittests/Printers/tst_printers.cpp (+156/-0) tests/unittests/Printers/tst_signalhandler.cpp (+44/-0) |
To merge this branch: | bzr merge lp:~jonas-drange/ubuntu-ui-extras/add-cmake-extras |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+317968@code.launchpad.net |
Commit message
adds cmake extras, required by printer stuff
Description of the change
To post a comment you must log in.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2016-08-24 15:46:52 +0000 | |||
3 | +++ debian/control 2017-02-22 12:44:26 +0000 | |||
4 | @@ -3,8 +3,10 @@ | |||
5 | 3 | Priority: optional | 3 | Priority: optional |
6 | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
7 | 5 | Build-Depends: cmake (>= 2.8.9), | 5 | Build-Depends: cmake (>= 2.8.9), |
8 | 6 | cmake-extras (>= 0.10), | ||
9 | 6 | debhelper (>= 9), | 7 | debhelper (>= 9), |
10 | 7 | gettext, | 8 | gettext, |
11 | 9 | libcups2-dev, | ||
12 | 8 | pkg-config, | 10 | pkg-config, |
13 | 9 | python:any, | 11 | python:any, |
14 | 10 | qt5-default, | 12 | qt5-default, |
15 | @@ -27,6 +29,7 @@ | |||
16 | 27 | Architecture: any | 29 | Architecture: any |
17 | 28 | Depends: ${misc:Depends}, | 30 | Depends: ${misc:Depends}, |
18 | 29 | ${shlibs:Depends}, | 31 | ${shlibs:Depends}, |
19 | 32 | libqt5printsupport5, | ||
20 | 30 | qml-module-qtquick2, | 33 | qml-module-qtquick2, |
21 | 31 | qml-module-ubuntu-components, | 34 | qml-module-ubuntu-components, |
22 | 32 | qml-module-qtquick-window2, | 35 | qml-module-qtquick-window2, |
23 | 33 | 36 | ||
24 | === modified file 'modules/Ubuntu/Components/Extras/CMakeLists.txt' | |||
25 | --- modules/Ubuntu/Components/Extras/CMakeLists.txt 2016-12-08 14:26:41 +0000 | |||
26 | +++ modules/Ubuntu/Components/Extras/CMakeLists.txt 2017-02-22 12:44:26 +0000 | |||
27 | @@ -13,4 +13,5 @@ | |||
28 | 13 | add_subdirectory(plugin) | 13 | add_subdirectory(plugin) |
29 | 14 | add_subdirectory(Example) | 14 | add_subdirectory(Example) |
30 | 15 | add_subdirectory(PhotoEditor) | 15 | add_subdirectory(PhotoEditor) |
31 | 16 | add_subdirectory(Printers) | ||
32 | 16 | add_subdirectory(TabsBar) | 17 | add_subdirectory(TabsBar) |
33 | 17 | 18 | ||
34 | === added file 'modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml' | |||
35 | --- modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 1970-01-01 00:00:00 +0000 | |||
36 | +++ modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 2017-02-22 12:44:26 +0000 | |||
37 | @@ -0,0 +1,117 @@ | |||
38 | 1 | /* | ||
39 | 2 | * Copyright 2017 Canonical Ltd. | ||
40 | 3 | * | ||
41 | 4 | * This program is free software; you can redistribute it and/or modify | ||
42 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
43 | 6 | * the Free Software Foundation; version 3. | ||
44 | 7 | * | ||
45 | 8 | * This program is distributed in the hope that it will be useful, | ||
46 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
47 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
48 | 11 | * GNU Lesser General Public License for more details. | ||
49 | 12 | * | ||
50 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
51 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
52 | 15 | * | ||
53 | 16 | * Authored by Jonas G. Drange <jonas.drange@canonical.com> | ||
54 | 17 | * Andrew Hayzen <andrew.hayzen@canonical.com> | ||
55 | 18 | */ | ||
56 | 19 | |||
57 | 20 | import QtQuick 2.4 | ||
58 | 21 | import QtQuick.Layouts 1.1 | ||
59 | 22 | import Ubuntu.Components 1.3 | ||
60 | 23 | import Ubuntu.Components.ListItems 1.3 as ListItems | ||
61 | 24 | import Ubuntu.Components.Extras.Printers 0.1 | ||
62 | 25 | |||
63 | 26 | MainView { | ||
64 | 27 | width: units.gu(50) | ||
65 | 28 | height: units.gu(90) | ||
66 | 29 | |||
67 | 30 | Component { | ||
68 | 31 | id: queuePage | ||
69 | 32 | |||
70 | 33 | Page { | ||
71 | 34 | header: PageHeader { | ||
72 | 35 | title: "Queue: " + printer.name | ||
73 | 36 | flickable: queueView | ||
74 | 37 | } | ||
75 | 38 | visible: false | ||
76 | 39 | |||
77 | 40 | property var printer | ||
78 | 41 | |||
79 | 42 | ListView { | ||
80 | 43 | id: queueView | ||
81 | 44 | anchors { | ||
82 | 45 | fill: parent | ||
83 | 46 | } | ||
84 | 47 | delegate: ListItem { | ||
85 | 48 | height: modelLayout.height + (divider.visible ? divider.height : 0) | ||
86 | 49 | ListItemLayout { | ||
87 | 50 | id: modelLayout | ||
88 | 51 | title.text: displayName | ||
89 | 52 | subtitle.text: "Job: " + model.id + " State: " + model.state | ||
90 | 53 | + " Color: " + model.colorModel + " CreationTime: " | ||
91 | 54 | + model.creationTime + " PageRange: " | ||
92 | 55 | + model.printRange + " Messages: " + model.messages; | ||
93 | 56 | subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||
94 | 57 | subtitle.maximumLineCount: 3 | ||
95 | 58 | } | ||
96 | 59 | onClicked: { | ||
97 | 60 | console.debug("Cancel:", printer.name, model.id); | ||
98 | 61 | Printers.cancelJob(printer.name, model.id); | ||
99 | 62 | } | ||
100 | 63 | } | ||
101 | 64 | model: printer.jobs | ||
102 | 65 | |||
103 | 66 | Label { | ||
104 | 67 | anchors { | ||
105 | 68 | centerIn: parent | ||
106 | 69 | } | ||
107 | 70 | text: "Empty queue" | ||
108 | 71 | visible: queueView.count === 0 | ||
109 | 72 | } | ||
110 | 73 | } | ||
111 | 74 | } | ||
112 | 75 | } | ||
113 | 76 | |||
114 | 77 | PageStack { | ||
115 | 78 | id: pageStack | ||
116 | 79 | |||
117 | 80 | Page { | ||
118 | 81 | id: printersPage | ||
119 | 82 | header: PageHeader { | ||
120 | 83 | title: "Printers" | ||
121 | 84 | flickable: printerList | ||
122 | 85 | } | ||
123 | 86 | visible: false | ||
124 | 87 | |||
125 | 88 | ListView { | ||
126 | 89 | id: printerList | ||
127 | 90 | anchors { fill: parent } | ||
128 | 91 | model: Printers.allPrintersWithPdf | ||
129 | 92 | delegate: ListItem { | ||
130 | 93 | height: modelLayout.height + (divider.visible ? divider.height : 0) | ||
131 | 94 | ListItemLayout { | ||
132 | 95 | id: modelLayout | ||
133 | 96 | title.text: displayName | ||
134 | 97 | title.font.bold: model.default | ||
135 | 98 | subtitle.text: description | ||
136 | 99 | |||
137 | 100 | Icon { | ||
138 | 101 | id: icon | ||
139 | 102 | width: height | ||
140 | 103 | height: units.gu(2.5) | ||
141 | 104 | name: "printer-symbolic" | ||
142 | 105 | SlotsLayout.position: SlotsLayout.First | ||
143 | 106 | } | ||
144 | 107 | |||
145 | 108 | ProgressionSlot {} | ||
146 | 109 | } | ||
147 | 110 | onClicked: pageStack.push(queuePage, { printer: model }) | ||
148 | 111 | } | ||
149 | 112 | } | ||
150 | 113 | } | ||
151 | 114 | |||
152 | 115 | Component.onCompleted: push(printersPage) | ||
153 | 116 | } | ||
154 | 117 | } | ||
155 | 0 | 118 | ||
156 | === added file 'modules/Ubuntu/Components/Extras/Example/Printers.qml' | |||
157 | --- modules/Ubuntu/Components/Extras/Example/Printers.qml 1970-01-01 00:00:00 +0000 | |||
158 | +++ modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-02-22 12:44:26 +0000 | |||
159 | @@ -0,0 +1,603 @@ | |||
160 | 1 | /* | ||
161 | 2 | * Copyright 2017 Canonical Ltd. | ||
162 | 3 | * | ||
163 | 4 | * This program is free software; you can redistribute it and/or modify | ||
164 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
165 | 6 | * the Free Software Foundation; version 3. | ||
166 | 7 | * | ||
167 | 8 | * This program is distributed in the hope that it will be useful, | ||
168 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
169 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
170 | 11 | * GNU Lesser General Public License for more details. | ||
171 | 12 | * | ||
172 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
173 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
174 | 15 | * | ||
175 | 16 | * Authored by Jonas G. Drange <jonas.drange@canonical.com> | ||
176 | 17 | */ | ||
177 | 18 | |||
178 | 19 | import QtQuick 2.4 | ||
179 | 20 | import QtQuick.Layouts 1.1 | ||
180 | 21 | import Ubuntu.Components 1.3 | ||
181 | 22 | import Ubuntu.Components.Popups 1.3 | ||
182 | 23 | import Ubuntu.Components.ListItems 1.3 as ListItems | ||
183 | 24 | import Ubuntu.Components.Extras.Printers 0.1 | ||
184 | 25 | |||
185 | 26 | MainView { | ||
186 | 27 | width: units.gu(50) | ||
187 | 28 | height: units.gu(90) | ||
188 | 29 | |||
189 | 30 | Component { | ||
190 | 31 | id: printerPage | ||
191 | 32 | |||
192 | 33 | Page { | ||
193 | 34 | visible: false | ||
194 | 35 | property var printer | ||
195 | 36 | header: PageHeader { | ||
196 | 37 | id: printerPageHeader | ||
197 | 38 | title: printer.name | ||
198 | 39 | flickable: printerFlickable | ||
199 | 40 | } | ||
200 | 41 | |||
201 | 42 | Component { | ||
202 | 43 | id: printerPageNotYetLoaded | ||
203 | 44 | |||
204 | 45 | Item { | ||
205 | 46 | anchors.fill: parent | ||
206 | 47 | ActivityIndicator { | ||
207 | 48 | anchors.centerIn: parent | ||
208 | 49 | running: true | ||
209 | 50 | } | ||
210 | 51 | } | ||
211 | 52 | } | ||
212 | 53 | |||
213 | 54 | Component.onCompleted: { | ||
214 | 55 | printer.description; | ||
215 | 56 | } | ||
216 | 57 | |||
217 | 58 | Flickable { | ||
218 | 59 | id: printerFlickable | ||
219 | 60 | anchors.fill: parent | ||
220 | 61 | |||
221 | 62 | Loader { | ||
222 | 63 | id: printerPageBitsLoader | ||
223 | 64 | anchors.fill: parent | ||
224 | 65 | sourceComponent: printer.isLoaded ? printerPageLoaded : printerPageNotYetLoaded | ||
225 | 66 | } | ||
226 | 67 | } | ||
227 | 68 | |||
228 | 69 | Component { | ||
229 | 70 | id: printerPageLoaded | ||
230 | 71 | |||
231 | 72 | Column { | ||
232 | 73 | spacing: units.gu(2) | ||
233 | 74 | anchors { | ||
234 | 75 | top: parent.top | ||
235 | 76 | topMargin: units.gu(2) | ||
236 | 77 | left: parent.left | ||
237 | 78 | right: parent.right | ||
238 | 79 | } | ||
239 | 80 | |||
240 | 81 | ListItems.Standard { | ||
241 | 82 | anchors { | ||
242 | 83 | left: parent.left | ||
243 | 84 | right: parent.right | ||
244 | 85 | } | ||
245 | 86 | text: "Enabled" | ||
246 | 87 | |||
247 | 88 | control: Switch { | ||
248 | 89 | checked: printer.printerEnabled | ||
249 | 90 | onCheckedChanged: printer.printerEnabled = checked | ||
250 | 91 | } | ||
251 | 92 | } | ||
252 | 93 | |||
253 | 94 | ListItems.Standard { | ||
254 | 95 | anchors { | ||
255 | 96 | left: parent.left | ||
256 | 97 | right: parent.right | ||
257 | 98 | } | ||
258 | 99 | text: "Accepting jobs" | ||
259 | 100 | |||
260 | 101 | control: Switch { | ||
261 | 102 | checked: printer.acceptJobs | ||
262 | 103 | onCheckedChanged: printer.acceptJobs = checked | ||
263 | 104 | } | ||
264 | 105 | } | ||
265 | 106 | |||
266 | 107 | ListItems.Standard { | ||
267 | 108 | anchors { | ||
268 | 109 | left: parent.left | ||
269 | 110 | right: parent.right | ||
270 | 111 | } | ||
271 | 112 | text: "Jobs" | ||
272 | 113 | progression: true | ||
273 | 114 | onClicked: pageStack.push(jobPage, { printer: printer }) | ||
274 | 115 | } | ||
275 | 116 | |||
276 | 117 | Label { | ||
277 | 118 | anchors { | ||
278 | 119 | left: parent.left | ||
279 | 120 | right: parent.right | ||
280 | 121 | margins: units.gu(2) | ||
281 | 122 | } | ||
282 | 123 | text: "Description" | ||
283 | 124 | } | ||
284 | 125 | |||
285 | 126 | ListItems.SingleControl { | ||
286 | 127 | anchors { | ||
287 | 128 | left: parent.left | ||
288 | 129 | right: parent.right | ||
289 | 130 | } | ||
290 | 131 | |||
291 | 132 | control: TextField { | ||
292 | 133 | anchors { | ||
293 | 134 | margins: units.gu(1) | ||
294 | 135 | left: parent.left | ||
295 | 136 | right: parent.right | ||
296 | 137 | |||
297 | 138 | } | ||
298 | 139 | text: printer.description | ||
299 | 140 | onTextChanged: printer.description = text | ||
300 | 141 | } | ||
301 | 142 | } | ||
302 | 143 | |||
303 | 144 | |||
304 | 145 | ListItems.ValueSelector { | ||
305 | 146 | anchors { | ||
306 | 147 | left: parent.left | ||
307 | 148 | right: parent.right | ||
308 | 149 | } | ||
309 | 150 | enabled: values.length > 1 | ||
310 | 151 | text: "Duplex" | ||
311 | 152 | values: printer.supportedDuplexModes | ||
312 | 153 | onSelectedIndexChanged: printer.duplexMode = selectedIndex | ||
313 | 154 | Component.onCompleted: { | ||
314 | 155 | if (enabled) { | ||
315 | 156 | selectedIndex = printer.duplexMode | ||
316 | 157 | } | ||
317 | 158 | } | ||
318 | 159 | } | ||
319 | 160 | |||
320 | 161 | ListItems.ValueSelector { | ||
321 | 162 | anchors { | ||
322 | 163 | left: parent.left | ||
323 | 164 | right: parent.right | ||
324 | 165 | } | ||
325 | 166 | text: "Page size" | ||
326 | 167 | values: printer.supportedPageSizes | ||
327 | 168 | onSelectedIndexChanged: printer.pageSize = selectedIndex | ||
328 | 169 | Component.onCompleted: selectedIndex = printer.supportedPageSizes.indexOf(printer.pageSize) | ||
329 | 170 | } | ||
330 | 171 | |||
331 | 172 | ListItems.ValueSelector { | ||
332 | 173 | anchors { | ||
333 | 174 | left: parent.left | ||
334 | 175 | right: parent.right | ||
335 | 176 | } | ||
336 | 177 | visible: printer.supportedColorModels.length | ||
337 | 178 | text: "Color model" | ||
338 | 179 | values: printer.supportedColorModels | ||
339 | 180 | enabled: values.length > 1 | ||
340 | 181 | onSelectedIndexChanged: printer.colorModel = selectedIndex | ||
341 | 182 | Component.onCompleted: { | ||
342 | 183 | if (enabled) | ||
343 | 184 | selectedIndex = printer.colorModel | ||
344 | 185 | } | ||
345 | 186 | } | ||
346 | 187 | |||
347 | 188 | ListItems.ValueSelector { | ||
348 | 189 | anchors { | ||
349 | 190 | left: parent.left | ||
350 | 191 | right: parent.right | ||
351 | 192 | } | ||
352 | 193 | visible: printer.supportedPrintQualities.length | ||
353 | 194 | text: "Quality" | ||
354 | 195 | values: printer.supportedPrintQualities | ||
355 | 196 | enabled: values.length > 1 | ||
356 | 197 | onSelectedIndexChanged: printer.printQuality = selectedIndex | ||
357 | 198 | Component.onCompleted: { | ||
358 | 199 | if (enabled) | ||
359 | 200 | selectedIndex = printer.printQuality | ||
360 | 201 | } | ||
361 | 202 | } | ||
362 | 203 | } | ||
363 | 204 | } | ||
364 | 205 | } | ||
365 | 206 | } | ||
366 | 207 | |||
367 | 208 | Component { | ||
368 | 209 | id: jobPage | ||
369 | 210 | Page { | ||
370 | 211 | property var printer | ||
371 | 212 | header: PageHeader { | ||
372 | 213 | id: jobPageHeader | ||
373 | 214 | title: "%1 (%2 jobs)".arg(printer.name).arg(jobList.count) | ||
374 | 215 | flickable: jobList | ||
375 | 216 | } | ||
376 | 217 | |||
377 | 218 | ListView { | ||
378 | 219 | id: jobList | ||
379 | 220 | anchors.fill: parent | ||
380 | 221 | model: printer.jobs | ||
381 | 222 | delegate: ListItem { | ||
382 | 223 | height: jobLayout.height + (divider.visible ? divider.height : 0) | ||
383 | 224 | ListItemLayout { | ||
384 | 225 | id: jobLayout | ||
385 | 226 | title.text: displayName | ||
386 | 227 | |||
387 | 228 | Icon { | ||
388 | 229 | id: icon | ||
389 | 230 | width: height | ||
390 | 231 | height: units.gu(2.5) | ||
391 | 232 | name: "stock_document" | ||
392 | 233 | SlotsLayout.position: SlotsLayout.First | ||
393 | 234 | } | ||
394 | 235 | } | ||
395 | 236 | } | ||
396 | 237 | } | ||
397 | 238 | } | ||
398 | 239 | } | ||
399 | 240 | |||
400 | 241 | |||
401 | 242 | Component { | ||
402 | 243 | id: allJobsPage | ||
403 | 244 | Page { | ||
404 | 245 | header: PageHeader { | ||
405 | 246 | id: allJobsHeader | ||
406 | 247 | title: "Printer jobs" | ||
407 | 248 | flickable: jobsList | ||
408 | 249 | } | ||
409 | 250 | |||
410 | 251 | ListView { | ||
411 | 252 | id: jobsList | ||
412 | 253 | anchors.fill: parent | ||
413 | 254 | model: Printers.printJobs | ||
414 | 255 | delegate: ListItem { | ||
415 | 256 | height: jobsLayout.height + (divider.visible ? divider.height : 0) | ||
416 | 257 | ListItemLayout { | ||
417 | 258 | id: jobsLayout | ||
418 | 259 | title.text: displayName | ||
419 | 260 | |||
420 | 261 | Icon { | ||
421 | 262 | id: icon | ||
422 | 263 | width: height | ||
423 | 264 | height: units.gu(2.5) | ||
424 | 265 | name: "stock_document" | ||
425 | 266 | SlotsLayout.position: SlotsLayout.First | ||
426 | 267 | } | ||
427 | 268 | } | ||
428 | 269 | } | ||
429 | 270 | } | ||
430 | 271 | } | ||
431 | 272 | } | ||
432 | 273 | |||
433 | 274 | |||
434 | 275 | PageStack { | ||
435 | 276 | id: pageStack | ||
436 | 277 | |||
437 | 278 | Component.onCompleted: push(printersPage) | ||
438 | 279 | |||
439 | 280 | Page { | ||
440 | 281 | id: printersPage | ||
441 | 282 | header: PageHeader { | ||
442 | 283 | title: "Printers" | ||
443 | 284 | flickable: printerList | ||
444 | 285 | trailingActionBar { | ||
445 | 286 | actions: [ | ||
446 | 287 | Action { | ||
447 | 288 | iconName: "add" | ||
448 | 289 | text: "Add printer" | ||
449 | 290 | onTriggered: pageStack.push(addPrinterPageComponent) | ||
450 | 291 | }, | ||
451 | 292 | Action { | ||
452 | 293 | iconName: "document-print" | ||
453 | 294 | text: "Printer jobs" | ||
454 | 295 | onTriggered: pageStack.push(allJobsPage) | ||
455 | 296 | } | ||
456 | 297 | ] | ||
457 | 298 | } | ||
458 | 299 | } | ||
459 | 300 | visible: false | ||
460 | 301 | |||
461 | 302 | ListView { | ||
462 | 303 | id: printerList | ||
463 | 304 | anchors { fill: parent } | ||
464 | 305 | model: Printers.allPrintersWithPdf | ||
465 | 306 | delegate: ListItem { | ||
466 | 307 | height: modelLayout.height + (divider.visible ? divider.height : 0) | ||
467 | 308 | trailingActions: ListItemActions { | ||
468 | 309 | actions: [ | ||
469 | 310 | Action { | ||
470 | 311 | iconName: "delete" | ||
471 | 312 | onTriggered: { | ||
472 | 313 | if (!Printers.removePrinter(model.name)) { | ||
473 | 314 | console.error('failed to remove printer', Printers.lastMessage); | ||
474 | 315 | } | ||
475 | 316 | } | ||
476 | 317 | }, | ||
477 | 318 | Action { | ||
478 | 319 | iconName: model.default ? "starred" : "non-starred" | ||
479 | 320 | enabled: !model.default | ||
480 | 321 | onTriggered: Printers.defaultPrinterName = model.name | ||
481 | 322 | } | ||
482 | 323 | |||
483 | 324 | ] | ||
484 | 325 | } | ||
485 | 326 | ListItemLayout { | ||
486 | 327 | id: modelLayout | ||
487 | 328 | title.text: displayName | ||
488 | 329 | title.font.bold: model.default | ||
489 | 330 | |||
490 | 331 | Icon { | ||
491 | 332 | id: icon | ||
492 | 333 | width: height | ||
493 | 334 | height: units.gu(2.5) | ||
494 | 335 | name: "printer-symbolic" | ||
495 | 336 | SlotsLayout.position: SlotsLayout.First | ||
496 | 337 | } | ||
497 | 338 | |||
498 | 339 | ProgressionSlot {} | ||
499 | 340 | } | ||
500 | 341 | onClicked: pageStack.push(printerPage, { printer: model }) | ||
501 | 342 | } | ||
502 | 343 | } | ||
503 | 344 | } | ||
504 | 345 | } | ||
505 | 346 | |||
506 | 347 | Component { | ||
507 | 348 | id: addPrinterPageComponent | ||
508 | 349 | Page { | ||
509 | 350 | id: addPrinterPage | ||
510 | 351 | states: [ | ||
511 | 352 | State { | ||
512 | 353 | name: "success" | ||
513 | 354 | PropertyChanges { | ||
514 | 355 | target: okAction | ||
515 | 356 | enabled: false | ||
516 | 357 | } | ||
517 | 358 | PropertyChanges { | ||
518 | 359 | target: closeAction | ||
519 | 360 | enabled: false | ||
520 | 361 | } | ||
521 | 362 | PropertyChanges { | ||
522 | 363 | target: addPrinterCol | ||
523 | 364 | enabled: false | ||
524 | 365 | } | ||
525 | 366 | StateChangeScript { | ||
526 | 367 | script: okTimer.start() | ||
527 | 368 | } | ||
528 | 369 | }, | ||
529 | 370 | State { | ||
530 | 371 | name: "failure" | ||
531 | 372 | PropertyChanges { | ||
532 | 373 | target: errorMessageContainer | ||
533 | 374 | visible: true | ||
534 | 375 | } | ||
535 | 376 | } | ||
536 | 377 | ] | ||
537 | 378 | header: PageHeader { | ||
538 | 379 | title: "Add printer" | ||
539 | 380 | flickable: addPrinterFlickable | ||
540 | 381 | leadingActionBar.actions: [ | ||
541 | 382 | Action { | ||
542 | 383 | id: closeAction | ||
543 | 384 | iconName: "close" | ||
544 | 385 | text: "Abort" | ||
545 | 386 | onTriggered: pageStack.pop() | ||
546 | 387 | } | ||
547 | 388 | ] | ||
548 | 389 | trailingActionBar { | ||
549 | 390 | actions: [ | ||
550 | 391 | Action { | ||
551 | 392 | id: okAction | ||
552 | 393 | iconName: "ok" | ||
553 | 394 | text: "Complete" | ||
554 | 395 | onTriggered: { | ||
555 | 396 | var ret; | ||
556 | 397 | if (driverSelector.selectedIndex == 0) { | ||
557 | 398 | ret = Printers.addPrinter( | ||
558 | 399 | printerName.text, | ||
559 | 400 | driversView.selectedDriver, | ||
560 | 401 | printerUri.text, | ||
561 | 402 | printerDescription.text, | ||
562 | 403 | printerLocation.text | ||
563 | 404 | ); | ||
564 | 405 | } else { | ||
565 | 406 | ret = Printers.addPrinterWithPpdFile( | ||
566 | 407 | printerName.text, | ||
567 | 408 | printerPpd.text, | ||
568 | 409 | printerUri.text, | ||
569 | 410 | printerDescription.text, | ||
570 | 411 | printerLocation.text | ||
571 | 412 | ); | ||
572 | 413 | } | ||
573 | 414 | if (ret) { | ||
574 | 415 | addPrinterPage.state = "success" | ||
575 | 416 | } else { | ||
576 | 417 | errorMessage.text = Printers.lastMessage; | ||
577 | 418 | addPrinterPage.state = "failure" | ||
578 | 419 | } | ||
579 | 420 | } | ||
580 | 421 | } | ||
581 | 422 | ] | ||
582 | 423 | } | ||
583 | 424 | } | ||
584 | 425 | |||
585 | 426 | Component.onCompleted: { | ||
586 | 427 | Printers.prepareToAddPrinter(); | ||
587 | 428 | } | ||
588 | 429 | |||
589 | 430 | Timer { | ||
590 | 431 | id: okTimer | ||
591 | 432 | interval: 2000 | ||
592 | 433 | onTriggered: pageStack.pop(); | ||
593 | 434 | } | ||
594 | 435 | |||
595 | 436 | Flickable { | ||
596 | 437 | id: addPrinterFlickable | ||
597 | 438 | anchors.fill: parent | ||
598 | 439 | |||
599 | 440 | Column { | ||
600 | 441 | id: addPrinterCol | ||
601 | 442 | property bool enabled: true | ||
602 | 443 | anchors { | ||
603 | 444 | left: parent.left | ||
604 | 445 | right: parent.right | ||
605 | 446 | } | ||
606 | 447 | |||
607 | 448 | Item { | ||
608 | 449 | id: errorMessageContainer | ||
609 | 450 | visible: false | ||
610 | 451 | anchors { | ||
611 | 452 | left: parent.left | ||
612 | 453 | right: parent.right | ||
613 | 454 | margins: units.gu(2) | ||
614 | 455 | } | ||
615 | 456 | height: units.gu(6) | ||
616 | 457 | Label { | ||
617 | 458 | id: errorMessage | ||
618 | 459 | anchors { | ||
619 | 460 | top: parent.top | ||
620 | 461 | topMargin: units.gu(2) | ||
621 | 462 | horizontalCenter: parent.horizontalCenter | ||
622 | 463 | } | ||
623 | 464 | } | ||
624 | 465 | |||
625 | 466 | } | ||
626 | 467 | |||
627 | 468 | ListItems.Standard { | ||
628 | 469 | text: "Device URI" | ||
629 | 470 | control: TextField { | ||
630 | 471 | id: printerUri | ||
631 | 472 | placeholderText: "ipp://server.local/my-queue" | ||
632 | 473 | } | ||
633 | 474 | enabled: parent.enabled | ||
634 | 475 | } | ||
635 | 476 | |||
636 | 477 | ListItems.ValueSelector { | ||
637 | 478 | id: driverSelector | ||
638 | 479 | anchors { | ||
639 | 480 | left: parent.left | ||
640 | 481 | right: parent.right | ||
641 | 482 | } | ||
642 | 483 | text: "Choose driver" | ||
643 | 484 | values: [ | ||
644 | 485 | "Select printer from database", | ||
645 | 486 | "Provide PPD file" | ||
646 | 487 | ] | ||
647 | 488 | enabled: parent.enabled | ||
648 | 489 | } | ||
649 | 490 | |||
650 | 491 | ListItems.Standard { | ||
651 | 492 | anchors { | ||
652 | 493 | left: parent.left | ||
653 | 494 | right: parent.right | ||
654 | 495 | } | ||
655 | 496 | text: "Filter drivers" | ||
656 | 497 | control: TextField { | ||
657 | 498 | id: driverFilter | ||
658 | 499 | onTextChanged: Printers.driverFilter = text | ||
659 | 500 | } | ||
660 | 501 | visible: driverSelector.selectedIndex == 0 | ||
661 | 502 | enabled: parent.enabled | ||
662 | 503 | } | ||
663 | 504 | |||
664 | 505 | ListView { | ||
665 | 506 | id: driversView | ||
666 | 507 | property string selectedDriver | ||
667 | 508 | property bool loading: true | ||
668 | 509 | visible: driverSelector.selectedIndex == 0 | ||
669 | 510 | model: Printers.drivers | ||
670 | 511 | anchors { left: parent.left; right: parent.right } | ||
671 | 512 | height: units.gu(30) | ||
672 | 513 | clip: true | ||
673 | 514 | enabled: parent.enabled | ||
674 | 515 | highlightFollowsCurrentItem: false | ||
675 | 516 | highlight: Rectangle { | ||
676 | 517 | z: 0 | ||
677 | 518 | y: driversView.currentItem.y | ||
678 | 519 | width: driversView.currentItem.width | ||
679 | 520 | height: driversView.currentItem.height | ||
680 | 521 | color: theme.palette.selected.background | ||
681 | 522 | } | ||
682 | 523 | delegate: ListItem { | ||
683 | 524 | height: driverLayout.height + (divider.visible ? divider.height : 0) | ||
684 | 525 | ListItemLayout { | ||
685 | 526 | id: driverLayout | ||
686 | 527 | title.text: displayName | ||
687 | 528 | subtitle.text: name | ||
688 | 529 | summary.text: deviceId | ||
689 | 530 | } | ||
690 | 531 | onClicked: { | ||
691 | 532 | driversView.selectedDriver = name | ||
692 | 533 | driversView.currentIndex = index | ||
693 | 534 | } | ||
694 | 535 | } | ||
695 | 536 | |||
696 | 537 | ActivityIndicator { | ||
697 | 538 | anchors.centerIn: parent | ||
698 | 539 | running: parent.loading | ||
699 | 540 | } | ||
700 | 541 | |||
701 | 542 | Connections { | ||
702 | 543 | target: driversView | ||
703 | 544 | onCountChanged: { | ||
704 | 545 | target = null; | ||
705 | 546 | driversView.loading = false; | ||
706 | 547 | } | ||
707 | 548 | } | ||
708 | 549 | } | ||
709 | 550 | |||
710 | 551 | ListItems.Standard { | ||
711 | 552 | text: "PPD File" | ||
712 | 553 | visible: driverSelector.selectedIndex == 1 | ||
713 | 554 | control: TextField { | ||
714 | 555 | id: printerPpd | ||
715 | 556 | placeholderText: "/usr/share/cups/foo.ppd" | ||
716 | 557 | } | ||
717 | 558 | enabled: parent.enabled | ||
718 | 559 | } | ||
719 | 560 | |||
720 | 561 | ListItems.Standard { | ||
721 | 562 | anchors { | ||
722 | 563 | left: parent.left | ||
723 | 564 | right: parent.right | ||
724 | 565 | } | ||
725 | 566 | text: "Printer name" | ||
726 | 567 | control: TextField { | ||
727 | 568 | id: printerName | ||
728 | 569 | placeholderText: "laserjet" | ||
729 | 570 | } | ||
730 | 571 | enabled: parent.enabled | ||
731 | 572 | } | ||
732 | 573 | |||
733 | 574 | ListItems.Standard { | ||
734 | 575 | anchors { | ||
735 | 576 | left: parent.left | ||
736 | 577 | right: parent.right | ||
737 | 578 | } | ||
738 | 579 | text: "Description (optional)" | ||
739 | 580 | control: TextField { | ||
740 | 581 | id: printerDescription | ||
741 | 582 | placeholderText: "HP Laserjet with Duplexer" | ||
742 | 583 | } | ||
743 | 584 | enabled: parent.enabled | ||
744 | 585 | } | ||
745 | 586 | |||
746 | 587 | ListItems.Standard { | ||
747 | 588 | anchors { | ||
748 | 589 | left: parent.left | ||
749 | 590 | right: parent.right | ||
750 | 591 | } | ||
751 | 592 | text: "Location (optional)" | ||
752 | 593 | control: TextField { | ||
753 | 594 | id: printerLocation | ||
754 | 595 | placeholderText: "Lab 1" | ||
755 | 596 | } | ||
756 | 597 | enabled: parent.enabled | ||
757 | 598 | } | ||
758 | 599 | } | ||
759 | 600 | } | ||
760 | 601 | } | ||
761 | 602 | } | ||
762 | 603 | } | ||
763 | 0 | 604 | ||
764 | === added directory 'modules/Ubuntu/Components/Extras/Printers' | |||
765 | === added file 'modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt' | |||
766 | --- modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
767 | +++ modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 2017-02-22 12:44:26 +0000 | |||
768 | @@ -0,0 +1,68 @@ | |||
769 | 1 | project(UbuntuComponentsExtrasPrintersQml) | ||
770 | 2 | |||
771 | 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra") | ||
772 | 4 | |||
773 | 5 | add_definitions(-DUBUNTUCOMPONENTSEXTRASPRINTERS_LIBRARY) | ||
774 | 6 | |||
775 | 7 | include(FindCups) | ||
776 | 8 | |||
777 | 9 | include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CUPS_INCLUDE_DIR}) | ||
778 | 10 | |||
779 | 11 | find_package(Qt5Gui REQUIRED) | ||
780 | 12 | find_package(Qt5PrintSupport REQUIRED) | ||
781 | 13 | find_package(Qt5Qml REQUIRED) | ||
782 | 14 | find_package(Qt5DBus REQUIRED) | ||
783 | 15 | find_package(Qt5Concurrent REQUIRED) | ||
784 | 16 | |||
785 | 17 | if(NOT CUPS_FOUND) | ||
786 | 18 | message(FATAL_ERROR "Could not find cups.") | ||
787 | 19 | endif() | ||
788 | 20 | |||
789 | 21 | qt5_add_dbus_interface( | ||
790 | 22 | GEN_SOURCES | ||
791 | 23 | ${CMAKE_CURRENT_SOURCE_DIR}/org.cups.cupsd.Notifier.xml | ||
792 | 24 | cupsdnotifier) | ||
793 | 25 | |||
794 | 26 | add_library(UbuntuComponentsExtrasPrintersQml SHARED | ||
795 | 27 | ${GEN_SOURCES} | ||
796 | 28 | backend/backend.cpp | ||
797 | 29 | backend/backend_cups.cpp | ||
798 | 30 | backend/backend_pdf.cpp | ||
799 | 31 | |||
800 | 32 | cups/ippclient.cpp | ||
801 | 33 | cups/printerdriverloader.cpp | ||
802 | 34 | cups/printerloader.cpp | ||
803 | 35 | |||
804 | 36 | models/drivermodel.cpp | ||
805 | 37 | models/jobmodel.cpp | ||
806 | 38 | models/printermodel.cpp | ||
807 | 39 | |||
808 | 40 | printer/printer.cpp | ||
809 | 41 | printer/printerjob.cpp | ||
810 | 42 | printer/printersignalhandler.cpp | ||
811 | 43 | printers/printers.cpp | ||
812 | 44 | |||
813 | 45 | enums.h | ||
814 | 46 | i18n.cpp | ||
815 | 47 | plugin.cpp | ||
816 | 48 | structs.h | ||
817 | 49 | utils.h | ||
818 | 50 | ) | ||
819 | 51 | |||
820 | 52 | target_link_libraries(UbuntuComponentsExtrasPrintersQml | ||
821 | 53 | Qt5::DBus | ||
822 | 54 | Qt5::Gui | ||
823 | 55 | Qt5::PrintSupport | ||
824 | 56 | Qt5::Qml | ||
825 | 57 | Qt5::Concurrent | ||
826 | 58 | ${CUPS_LIBRARIES} | ||
827 | 59 | ) | ||
828 | 60 | |||
829 | 61 | find_package(QmlPlugins) | ||
830 | 62 | |||
831 | 63 | macro(add_plugin PLUGIN VERSION PATH) | ||
832 | 64 | export_qmlfiles(${PLUGIN} ${PATH} DESTINATION ${QT_IMPORTS_DIR} ${ARGN}) | ||
833 | 65 | export_qmlplugin(${PLUGIN} ${VERSION} ${PATH} DESTINATION ${QT_IMPORTS_DIR} ${ARGN}) | ||
834 | 66 | endmacro() | ||
835 | 67 | |||
836 | 68 | add_plugin(Ubuntu.Components.Extras.Printers 0.1 Ubuntu/Components/Extras/Printers TARGETS UbuntuComponentsExtrasPrintersQml) | ||
837 | 0 | 69 | ||
838 | === added directory 'modules/Ubuntu/Components/Extras/Printers/backend' | |||
839 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp' | |||
840 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 1970-01-01 00:00:00 +0000 | |||
841 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-02-22 12:44:26 +0000 | |||
842 | @@ -0,0 +1,350 @@ | |||
843 | 1 | /* | ||
844 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
845 | 3 | * | ||
846 | 4 | * This program is free software; you can redistribute it and/or modify | ||
847 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
848 | 6 | * the Free Software Foundation; version 3. | ||
849 | 7 | * | ||
850 | 8 | * This program is distributed in the hope that it will be useful, | ||
851 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
852 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
853 | 11 | * GNU Lesser General Public License for more details. | ||
854 | 12 | * | ||
855 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
856 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
857 | 15 | */ | ||
858 | 16 | |||
859 | 17 | #include "backend/backend.h" | ||
860 | 18 | |||
861 | 19 | PrinterBackend::PrinterBackend(const QString &printerName, QObject *parent) | ||
862 | 20 | : QObject(parent) | ||
863 | 21 | , m_printerName(printerName) | ||
864 | 22 | , m_type(PrinterEnum::PrinterType::ProxyType) | ||
865 | 23 | { | ||
866 | 24 | } | ||
867 | 25 | |||
868 | 26 | PrinterBackend::~PrinterBackend() | ||
869 | 27 | { | ||
870 | 28 | } | ||
871 | 29 | |||
872 | 30 | bool PrinterBackend::holdsDefinition() const | ||
873 | 31 | { | ||
874 | 32 | return false; | ||
875 | 33 | } | ||
876 | 34 | |||
877 | 35 | QString PrinterBackend::printerAdd(const QString &name, | ||
878 | 36 | const QString &uri, | ||
879 | 37 | const QString &ppdFile, | ||
880 | 38 | const QString &info, | ||
881 | 39 | const QString &location) | ||
882 | 40 | { | ||
883 | 41 | Q_UNUSED(name); | ||
884 | 42 | Q_UNUSED(uri); | ||
885 | 43 | Q_UNUSED(ppdFile); | ||
886 | 44 | Q_UNUSED(info); | ||
887 | 45 | Q_UNUSED(location); | ||
888 | 46 | return QString(); | ||
889 | 47 | } | ||
890 | 48 | |||
891 | 49 | QString PrinterBackend::printerAddWithPpd(const QString &name, | ||
892 | 50 | const QString &uri, | ||
893 | 51 | const QString &ppdFileName, | ||
894 | 52 | const QString &info, | ||
895 | 53 | const QString &location) | ||
896 | 54 | { | ||
897 | 55 | Q_UNUSED(name); | ||
898 | 56 | Q_UNUSED(uri); | ||
899 | 57 | Q_UNUSED(ppdFileName); | ||
900 | 58 | Q_UNUSED(info); | ||
901 | 59 | Q_UNUSED(location); | ||
902 | 60 | return QString(); | ||
903 | 61 | } | ||
904 | 62 | |||
905 | 63 | QString PrinterBackend::printerDelete(const QString &name) | ||
906 | 64 | { | ||
907 | 65 | Q_UNUSED(name); | ||
908 | 66 | return QString(); | ||
909 | 67 | } | ||
910 | 68 | |||
911 | 69 | QString PrinterBackend::printerSetDefault(const QString &name) | ||
912 | 70 | { | ||
913 | 71 | Q_UNUSED(name); | ||
914 | 72 | return QString(); | ||
915 | 73 | } | ||
916 | 74 | |||
917 | 75 | QString PrinterBackend::printerSetEnabled(const QString &name, | ||
918 | 76 | const bool enabled) | ||
919 | 77 | { | ||
920 | 78 | Q_UNUSED(name); | ||
921 | 79 | Q_UNUSED(enabled); | ||
922 | 80 | return QString(); | ||
923 | 81 | } | ||
924 | 82 | |||
925 | 83 | QString PrinterBackend::printerSetAcceptJobs( | ||
926 | 84 | const QString &name, | ||
927 | 85 | const bool enabled, | ||
928 | 86 | const QString &reason) | ||
929 | 87 | { | ||
930 | 88 | Q_UNUSED(name); | ||
931 | 89 | Q_UNUSED(enabled); | ||
932 | 90 | Q_UNUSED(reason); | ||
933 | 91 | return QString(); | ||
934 | 92 | } | ||
935 | 93 | |||
936 | 94 | QString PrinterBackend::printerSetInfo(const QString &name, | ||
937 | 95 | const QString &info) | ||
938 | 96 | { | ||
939 | 97 | Q_UNUSED(name); | ||
940 | 98 | Q_UNUSED(info); | ||
941 | 99 | return QString(); | ||
942 | 100 | } | ||
943 | 101 | |||
944 | 102 | QString PrinterBackend::printerSetLocation(const QString &name, | ||
945 | 103 | const QString &location) | ||
946 | 104 | { | ||
947 | 105 | Q_UNUSED(name); | ||
948 | 106 | Q_UNUSED(location); | ||
949 | 107 | return QString(); | ||
950 | 108 | } | ||
951 | 109 | |||
952 | 110 | QString PrinterBackend::printerSetShared(const QString &name, | ||
953 | 111 | const bool shared) | ||
954 | 112 | { | ||
955 | 113 | Q_UNUSED(name); | ||
956 | 114 | Q_UNUSED(shared); | ||
957 | 115 | return QString(); | ||
958 | 116 | } | ||
959 | 117 | |||
960 | 118 | QString PrinterBackend::printerSetJobSheets(const QString &name, | ||
961 | 119 | const QString &start, | ||
962 | 120 | const QString &end) | ||
963 | 121 | { | ||
964 | 122 | Q_UNUSED(name); | ||
965 | 123 | Q_UNUSED(start); | ||
966 | 124 | Q_UNUSED(end); | ||
967 | 125 | return QString(); | ||
968 | 126 | } | ||
969 | 127 | |||
970 | 128 | QString PrinterBackend::printerSetErrorPolicy(const QString &name, | ||
971 | 129 | const PrinterEnum::ErrorPolicy &policy) | ||
972 | 130 | { | ||
973 | 131 | Q_UNUSED(name); | ||
974 | 132 | Q_UNUSED(policy); | ||
975 | 133 | return QString(); | ||
976 | 134 | } | ||
977 | 135 | |||
978 | 136 | |||
979 | 137 | QString PrinterBackend::printerSetOpPolicy(const QString &name, | ||
980 | 138 | const PrinterEnum::OperationPolicy &policy) | ||
981 | 139 | { | ||
982 | 140 | Q_UNUSED(name); | ||
983 | 141 | Q_UNUSED(policy); | ||
984 | 142 | return QString(); | ||
985 | 143 | } | ||
986 | 144 | |||
987 | 145 | QString PrinterBackend::printerSetUsersAllowed(const QString &name, | ||
988 | 146 | const QStringList &users) | ||
989 | 147 | { | ||
990 | 148 | Q_UNUSED(name); | ||
991 | 149 | Q_UNUSED(users); | ||
992 | 150 | return QString(); | ||
993 | 151 | } | ||
994 | 152 | |||
995 | 153 | QString PrinterBackend::printerSetUsersDenied(const QString &name, | ||
996 | 154 | const QStringList &users) | ||
997 | 155 | { | ||
998 | 156 | Q_UNUSED(name); | ||
999 | 157 | Q_UNUSED(users); | ||
1000 | 158 | return QString(); | ||
1001 | 159 | } | ||
1002 | 160 | |||
1003 | 161 | QString PrinterBackend::printerAddOptionDefault(const QString &name, | ||
1004 | 162 | const QString &option, | ||
1005 | 163 | const QStringList &values) | ||
1006 | 164 | { | ||
1007 | 165 | Q_UNUSED(name); | ||
1008 | 166 | Q_UNUSED(option); | ||
1009 | 167 | Q_UNUSED(values); | ||
1010 | 168 | return QString(); | ||
1011 | 169 | } | ||
1012 | 170 | |||
1013 | 171 | QString PrinterBackend::printerDeleteOptionDefault(const QString &name, | ||
1014 | 172 | const QString &value) | ||
1015 | 173 | { | ||
1016 | 174 | Q_UNUSED(name); | ||
1017 | 175 | Q_UNUSED(value); | ||
1018 | 176 | return QString(); | ||
1019 | 177 | } | ||
1020 | 178 | |||
1021 | 179 | QString PrinterBackend::printerAddOption(const QString &name, | ||
1022 | 180 | const QString &option, | ||
1023 | 181 | const QStringList &values) | ||
1024 | 182 | { | ||
1025 | 183 | Q_UNUSED(name); | ||
1026 | 184 | Q_UNUSED(option); | ||
1027 | 185 | Q_UNUSED(values); | ||
1028 | 186 | return QString(); | ||
1029 | 187 | } | ||
1030 | 188 | |||
1031 | 189 | QVariant PrinterBackend::printerGetOption(const QString &name, | ||
1032 | 190 | const QString &option) const | ||
1033 | 191 | { | ||
1034 | 192 | Q_UNUSED(name); | ||
1035 | 193 | Q_UNUSED(option); | ||
1036 | 194 | return QVariant(); | ||
1037 | 195 | } | ||
1038 | 196 | |||
1039 | 197 | QMap<QString, QVariant> PrinterBackend::printerGetOptions( | ||
1040 | 198 | const QString &name, const QStringList &options) const | ||
1041 | 199 | { | ||
1042 | 200 | Q_UNUSED(name); | ||
1043 | 201 | Q_UNUSED(options); | ||
1044 | 202 | return QMap<QString, QVariant>(); | ||
1045 | 203 | } | ||
1046 | 204 | |||
1047 | 205 | // FIXME: maybe have a PrinterDest iface that has a CupsDest impl? | ||
1048 | 206 | cups_dest_t* PrinterBackend::makeDest(const QString &name, | ||
1049 | 207 | const PrinterJob *options) | ||
1050 | 208 | { | ||
1051 | 209 | Q_UNUSED(name); | ||
1052 | 210 | Q_UNUSED(options); | ||
1053 | 211 | return Q_NULLPTR; | ||
1054 | 212 | } | ||
1055 | 213 | |||
1056 | 214 | void PrinterBackend::cancelJob(const QString &name, const int jobId) | ||
1057 | 215 | { | ||
1058 | 216 | Q_UNUSED(jobId); | ||
1059 | 217 | Q_UNUSED(name); | ||
1060 | 218 | } | ||
1061 | 219 | |||
1062 | 220 | int PrinterBackend::printFileToDest(const QString &filepath, | ||
1063 | 221 | const QString &title, | ||
1064 | 222 | const cups_dest_t *dest) | ||
1065 | 223 | { | ||
1066 | 224 | Q_UNUSED(filepath); | ||
1067 | 225 | Q_UNUSED(title); | ||
1068 | 226 | Q_UNUSED(dest); | ||
1069 | 227 | return -1; | ||
1070 | 228 | } | ||
1071 | 229 | |||
1072 | 230 | QList<QSharedPointer<PrinterJob>> PrinterBackend::printerGetJobs() | ||
1073 | 231 | { | ||
1074 | 232 | return QList<QSharedPointer<PrinterJob>>{}; | ||
1075 | 233 | } | ||
1076 | 234 | |||
1077 | 235 | QMap<QString, QVariant> PrinterBackend::printerGetJobAttributes( | ||
1078 | 236 | const QString &name, const int jobId) | ||
1079 | 237 | { | ||
1080 | 238 | Q_UNUSED(name); | ||
1081 | 239 | Q_UNUSED(jobId); | ||
1082 | 240 | return QMap<QString, QVariant>(); | ||
1083 | 241 | } | ||
1084 | 242 | |||
1085 | 243 | QString PrinterBackend::printerName() const | ||
1086 | 244 | { | ||
1087 | 245 | return m_printerName; | ||
1088 | 246 | } | ||
1089 | 247 | |||
1090 | 248 | QString PrinterBackend::description() const | ||
1091 | 249 | { | ||
1092 | 250 | return QString(); | ||
1093 | 251 | } | ||
1094 | 252 | |||
1095 | 253 | QString PrinterBackend::location() const | ||
1096 | 254 | { | ||
1097 | 255 | return QString(); | ||
1098 | 256 | } | ||
1099 | 257 | |||
1100 | 258 | QString PrinterBackend::makeAndModel() const | ||
1101 | 259 | { | ||
1102 | 260 | return QString(); | ||
1103 | 261 | } | ||
1104 | 262 | |||
1105 | 263 | PrinterEnum::State PrinterBackend::state() const | ||
1106 | 264 | { | ||
1107 | 265 | return PrinterEnum::State::IdleState; | ||
1108 | 266 | } | ||
1109 | 267 | |||
1110 | 268 | QList<QPageSize> PrinterBackend::supportedPageSizes() const | ||
1111 | 269 | { | ||
1112 | 270 | return QList<QPageSize>(); | ||
1113 | 271 | } | ||
1114 | 272 | |||
1115 | 273 | QPageSize PrinterBackend::defaultPageSize() const | ||
1116 | 274 | { | ||
1117 | 275 | return QPageSize(); | ||
1118 | 276 | } | ||
1119 | 277 | |||
1120 | 278 | bool PrinterBackend::supportsCustomPageSizes() const | ||
1121 | 279 | { | ||
1122 | 280 | return false; | ||
1123 | 281 | } | ||
1124 | 282 | |||
1125 | 283 | QPageSize PrinterBackend::minimumPhysicalPageSize() const | ||
1126 | 284 | { | ||
1127 | 285 | return QPageSize(); | ||
1128 | 286 | } | ||
1129 | 287 | |||
1130 | 288 | QPageSize PrinterBackend::maximumPhysicalPageSize() const | ||
1131 | 289 | { | ||
1132 | 290 | return QPageSize(); | ||
1133 | 291 | } | ||
1134 | 292 | |||
1135 | 293 | QList<int> PrinterBackend::supportedResolutions() const | ||
1136 | 294 | { | ||
1137 | 295 | return QList<int>(); | ||
1138 | 296 | } | ||
1139 | 297 | |||
1140 | 298 | PrinterEnum::DuplexMode PrinterBackend::defaultDuplexMode() const | ||
1141 | 299 | { | ||
1142 | 300 | return PrinterEnum::DuplexMode::DuplexNone; | ||
1143 | 301 | } | ||
1144 | 302 | |||
1145 | 303 | QList<PrinterEnum::DuplexMode> PrinterBackend::supportedDuplexModes() const | ||
1146 | 304 | { | ||
1147 | 305 | return QList<PrinterEnum::DuplexMode>(); | ||
1148 | 306 | } | ||
1149 | 307 | |||
1150 | 308 | QList<QSharedPointer<Printer>> PrinterBackend::availablePrinters() | ||
1151 | 309 | { | ||
1152 | 310 | return QList<QSharedPointer<Printer>>(); | ||
1153 | 311 | } | ||
1154 | 312 | |||
1155 | 313 | QStringList PrinterBackend::availablePrinterNames() | ||
1156 | 314 | { | ||
1157 | 315 | return QStringList(); | ||
1158 | 316 | } | ||
1159 | 317 | |||
1160 | 318 | QSharedPointer<Printer> PrinterBackend::getPrinter(const QString &printerName) | ||
1161 | 319 | { | ||
1162 | 320 | Q_UNUSED(printerName); | ||
1163 | 321 | return QSharedPointer<Printer>(Q_NULLPTR); | ||
1164 | 322 | } | ||
1165 | 323 | |||
1166 | 324 | QString PrinterBackend::defaultPrinterName() | ||
1167 | 325 | { | ||
1168 | 326 | return QString(); | ||
1169 | 327 | } | ||
1170 | 328 | |||
1171 | 329 | void PrinterBackend::requestPrinterDrivers() | ||
1172 | 330 | { | ||
1173 | 331 | } | ||
1174 | 332 | |||
1175 | 333 | void PrinterBackend::requestPrinter(const QString &printerName) | ||
1176 | 334 | { | ||
1177 | 335 | Q_UNUSED(printerName); | ||
1178 | 336 | } | ||
1179 | 337 | |||
1180 | 338 | PrinterEnum::PrinterType PrinterBackend::type() const | ||
1181 | 339 | { | ||
1182 | 340 | return m_type; | ||
1183 | 341 | } | ||
1184 | 342 | |||
1185 | 343 | void PrinterBackend::setPrinterNameInternal(const QString &printerName) | ||
1186 | 344 | { | ||
1187 | 345 | m_printerName = printerName; | ||
1188 | 346 | } | ||
1189 | 347 | |||
1190 | 348 | void PrinterBackend::refresh() | ||
1191 | 349 | { | ||
1192 | 350 | } | ||
1193 | 0 | 351 | ||
1194 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.h' | |||
1195 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.h 1970-01-01 00:00:00 +0000 | |||
1196 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-02-22 12:44:26 +0000 | |||
1197 | @@ -0,0 +1,223 @@ | |||
1198 | 1 | /* | ||
1199 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1200 | 3 | * | ||
1201 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1202 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
1203 | 6 | * the Free Software Foundation; version 3. | ||
1204 | 7 | * | ||
1205 | 8 | * This program is distributed in the hope that it will be useful, | ||
1206 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1207 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1208 | 11 | * GNU Lesser General Public License for more details. | ||
1209 | 12 | * | ||
1210 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1211 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1212 | 15 | */ | ||
1213 | 16 | |||
1214 | 17 | #ifndef USC_PRINTERS_BACKEND_H | ||
1215 | 18 | #define USC_PRINTERS_BACKEND_H | ||
1216 | 19 | |||
1217 | 20 | #include "printer/printer.h" | ||
1218 | 21 | #include "printer/printerjob.h" | ||
1219 | 22 | |||
1220 | 23 | // TODO: remove cups specific things from this API | ||
1221 | 24 | #include <cups/cups.h> | ||
1222 | 25 | |||
1223 | 26 | #include <QObject> | ||
1224 | 27 | #include <QPageSize> | ||
1225 | 28 | #include <QList> | ||
1226 | 29 | #include <QString> | ||
1227 | 30 | #include <QStringList> | ||
1228 | 31 | |||
1229 | 32 | class Printer; | ||
1230 | 33 | class PrinterJob; | ||
1231 | 34 | class PRINTERS_DECL_EXPORT PrinterBackend : public QObject | ||
1232 | 35 | { | ||
1233 | 36 | Q_OBJECT | ||
1234 | 37 | public: | ||
1235 | 38 | explicit PrinterBackend(QObject *parent = Q_NULLPTR); | ||
1236 | 39 | explicit PrinterBackend(const QString &printerName, | ||
1237 | 40 | QObject *parent = Q_NULLPTR); | ||
1238 | 41 | virtual ~PrinterBackend(); | ||
1239 | 42 | |||
1240 | 43 | virtual bool holdsDefinition() const; | ||
1241 | 44 | |||
1242 | 45 | // Add a printer using an already existing ppd. | ||
1243 | 46 | virtual QString printerAdd(const QString &name, | ||
1244 | 47 | const QString &uri, | ||
1245 | 48 | const QString &ppdFile, | ||
1246 | 49 | const QString &info, | ||
1247 | 50 | const QString &location); | ||
1248 | 51 | |||
1249 | 52 | // Add a printer and provide a ppd file. | ||
1250 | 53 | virtual QString printerAddWithPpd(const QString &name, | ||
1251 | 54 | const QString &uri, | ||
1252 | 55 | const QString &ppdFileName, | ||
1253 | 56 | const QString &info, | ||
1254 | 57 | const QString &location); | ||
1255 | 58 | virtual QString printerDelete(const QString &name); | ||
1256 | 59 | virtual QString printerSetDefault(const QString &name); | ||
1257 | 60 | virtual QString printerSetEnabled(const QString &name, | ||
1258 | 61 | const bool enabled); | ||
1259 | 62 | virtual QString printerSetAcceptJobs( | ||
1260 | 63 | const QString &name, | ||
1261 | 64 | const bool accept, | ||
1262 | 65 | const QString &reason = QString::null); | ||
1263 | 66 | virtual QString printerSetInfo(const QString &name, | ||
1264 | 67 | const QString &info); | ||
1265 | 68 | virtual QString printerSetLocation(const QString &name, | ||
1266 | 69 | const QString &location); | ||
1267 | 70 | virtual QString printerSetShared(const QString &name, | ||
1268 | 71 | const bool shared); | ||
1269 | 72 | virtual QString printerSetJobSheets(const QString &name, | ||
1270 | 73 | const QString &start, | ||
1271 | 74 | const QString &end); | ||
1272 | 75 | virtual QString printerSetErrorPolicy(const QString &name, | ||
1273 | 76 | const PrinterEnum::ErrorPolicy &policy); | ||
1274 | 77 | |||
1275 | 78 | virtual QString printerSetOpPolicy(const QString &name, | ||
1276 | 79 | const PrinterEnum::OperationPolicy &policy); | ||
1277 | 80 | virtual QString printerSetUsersAllowed(const QString &name, | ||
1278 | 81 | const QStringList &users); | ||
1279 | 82 | virtual QString printerSetUsersDenied(const QString &name, | ||
1280 | 83 | const QStringList &users); | ||
1281 | 84 | virtual QString printerAddOptionDefault(const QString &name, | ||
1282 | 85 | const QString &option, | ||
1283 | 86 | const QStringList &values); | ||
1284 | 87 | virtual QString printerDeleteOptionDefault(const QString &name, | ||
1285 | 88 | const QString &value); | ||
1286 | 89 | virtual QString printerAddOption(const QString &name, | ||
1287 | 90 | const QString &option, | ||
1288 | 91 | const QStringList &values); | ||
1289 | 92 | |||
1290 | 93 | virtual QVariant printerGetOption(const QString &name, | ||
1291 | 94 | const QString &option) const; | ||
1292 | 95 | virtual QMap<QString, QVariant> printerGetOptions( | ||
1293 | 96 | const QString &name, const QStringList &options) const; | ||
1294 | 97 | // FIXME: maybe have a PrinterDest iface that has a CupsDest impl? | ||
1295 | 98 | virtual cups_dest_t* makeDest(const QString &name, | ||
1296 | 99 | const PrinterJob *options); | ||
1297 | 100 | |||
1298 | 101 | virtual void cancelJob(const QString &name, const int jobId); | ||
1299 | 102 | virtual int printFileToDest(const QString &filepath, | ||
1300 | 103 | const QString &title, | ||
1301 | 104 | const cups_dest_t *dest); | ||
1302 | 105 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(); | ||
1303 | 106 | virtual QMap<QString, QVariant> printerGetJobAttributes( | ||
1304 | 107 | const QString &name, const int jobId); | ||
1305 | 108 | |||
1306 | 109 | virtual QString printerName() const; | ||
1307 | 110 | virtual QString description() const; | ||
1308 | 111 | virtual QString location() const; | ||
1309 | 112 | virtual QString makeAndModel() const; | ||
1310 | 113 | |||
1311 | 114 | virtual PrinterEnum::State state() const; | ||
1312 | 115 | virtual QList<QPageSize> supportedPageSizes() const; | ||
1313 | 116 | virtual QPageSize defaultPageSize() const; | ||
1314 | 117 | virtual bool supportsCustomPageSizes() const; | ||
1315 | 118 | |||
1316 | 119 | virtual QPageSize minimumPhysicalPageSize() const; | ||
1317 | 120 | virtual QPageSize maximumPhysicalPageSize() const; | ||
1318 | 121 | virtual QList<int> supportedResolutions() const; | ||
1319 | 122 | virtual PrinterEnum::DuplexMode defaultDuplexMode() const; | ||
1320 | 123 | virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const; | ||
1321 | 124 | |||
1322 | 125 | virtual QList<QSharedPointer<Printer>> availablePrinters(); | ||
1323 | 126 | virtual QStringList availablePrinterNames(); | ||
1324 | 127 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName); | ||
1325 | 128 | virtual QString defaultPrinterName(); | ||
1326 | 129 | |||
1327 | 130 | virtual void requestPrinterDrivers(); | ||
1328 | 131 | virtual void requestPrinter(const QString &printerName); | ||
1329 | 132 | |||
1330 | 133 | virtual PrinterEnum::PrinterType type() const; | ||
1331 | 134 | |||
1332 | 135 | virtual void setPrinterNameInternal(const QString &printerName); | ||
1333 | 136 | |||
1334 | 137 | public Q_SLOTS: | ||
1335 | 138 | virtual void refresh(); | ||
1336 | 139 | |||
1337 | 140 | Q_SIGNALS: | ||
1338 | 141 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); | ||
1339 | 142 | void printerDriversFailedToLoad(const QString &errorMessage); | ||
1340 | 143 | |||
1341 | 144 | void printerLoaded(QSharedPointer<Printer> printers); | ||
1342 | 145 | |||
1343 | 146 | void jobCompleted( | ||
1344 | 147 | const QString &text, | ||
1345 | 148 | const QString &printerUri, | ||
1346 | 149 | const QString &printerName, | ||
1347 | 150 | uint printerState, | ||
1348 | 151 | const QString &printerStateReason, | ||
1349 | 152 | bool acceptingJobs, | ||
1350 | 153 | uint jobId, | ||
1351 | 154 | uint jobState, | ||
1352 | 155 | const QString &jobStateReason, | ||
1353 | 156 | const QString &job_name, | ||
1354 | 157 | uint jobImpressionsCompleted | ||
1355 | 158 | ); | ||
1356 | 159 | void jobCreated( | ||
1357 | 160 | const QString &text, | ||
1358 | 161 | const QString &printerUri, | ||
1359 | 162 | const QString &printerName, | ||
1360 | 163 | uint printerState, | ||
1361 | 164 | const QString &printerStateReason, | ||
1362 | 165 | bool acceptingJobs, | ||
1363 | 166 | uint jobId, | ||
1364 | 167 | uint jobState, | ||
1365 | 168 | const QString &jobStateReason, | ||
1366 | 169 | const QString &job_name, | ||
1367 | 170 | uint jobImpressionsCompleted | ||
1368 | 171 | ); | ||
1369 | 172 | void jobState( | ||
1370 | 173 | const QString &text, | ||
1371 | 174 | const QString &printerUri, | ||
1372 | 175 | const QString &printerName, | ||
1373 | 176 | uint printerState, | ||
1374 | 177 | const QString &printerStateReason, | ||
1375 | 178 | bool acceptingJobs, | ||
1376 | 179 | uint jobId, | ||
1377 | 180 | uint jobState, | ||
1378 | 181 | const QString &jobStateReason, | ||
1379 | 182 | const QString &job_name, | ||
1380 | 183 | uint jobImpressionsCompleted | ||
1381 | 184 | ); | ||
1382 | 185 | void printerAdded( | ||
1383 | 186 | const QString &text, | ||
1384 | 187 | const QString &printerUri, | ||
1385 | 188 | const QString &printerName, | ||
1386 | 189 | uint printerState, | ||
1387 | 190 | const QString &printerStateReason, | ||
1388 | 191 | bool acceptingJobs | ||
1389 | 192 | ); | ||
1390 | 193 | void printerDeleted( | ||
1391 | 194 | const QString &text, | ||
1392 | 195 | const QString &printerUri, | ||
1393 | 196 | const QString &printerName, | ||
1394 | 197 | uint printerState, | ||
1395 | 198 | const QString &printerStateReason, | ||
1396 | 199 | bool acceptingJobs | ||
1397 | 200 | ); | ||
1398 | 201 | void printerModified( | ||
1399 | 202 | const QString &text, | ||
1400 | 203 | const QString &printerUri, | ||
1401 | 204 | const QString &printerName, | ||
1402 | 205 | uint printerState, | ||
1403 | 206 | const QString &printerStateReason, | ||
1404 | 207 | bool acceptingJobs | ||
1405 | 208 | ); | ||
1406 | 209 | void printerStateChanged( | ||
1407 | 210 | const QString &text, | ||
1408 | 211 | const QString &printerUri, | ||
1409 | 212 | const QString &printerName, | ||
1410 | 213 | uint printerState, | ||
1411 | 214 | const QString &printerStateReason, | ||
1412 | 215 | bool acceptingJobs | ||
1413 | 216 | ); | ||
1414 | 217 | |||
1415 | 218 | protected: | ||
1416 | 219 | QString m_printerName; | ||
1417 | 220 | PrinterEnum::PrinterType m_type; | ||
1418 | 221 | }; | ||
1419 | 222 | |||
1420 | 223 | #endif // USC_PRINTERS_BACKEND_H | ||
1421 | 0 | 224 | ||
1422 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp' | |||
1423 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 1970-01-01 00:00:00 +0000 | |||
1424 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-02-22 12:44:26 +0000 | |||
1425 | @@ -0,0 +1,787 @@ | |||
1426 | 1 | /* | ||
1427 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1428 | 3 | * | ||
1429 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1430 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
1431 | 6 | * the Free Software Foundation; version 3. | ||
1432 | 7 | * | ||
1433 | 8 | * This program is distributed in the hope that it will be useful, | ||
1434 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1435 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1436 | 11 | * GNU Lesser General Public License for more details. | ||
1437 | 12 | * | ||
1438 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1439 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1440 | 15 | */ | ||
1441 | 16 | |||
1442 | 17 | #include "backend/backend_cups.h" | ||
1443 | 18 | #include "cups/printerdriverloader.h" | ||
1444 | 19 | #include "cups/printerloader.h" | ||
1445 | 20 | #include "utils.h" | ||
1446 | 21 | |||
1447 | 22 | #include <cups/http.h> | ||
1448 | 23 | #include <cups/ipp.h> | ||
1449 | 24 | #include <cups/ppd.h> | ||
1450 | 25 | |||
1451 | 26 | #include <QLocale> | ||
1452 | 27 | #include <QThread> | ||
1453 | 28 | #include <QTimeZone> | ||
1454 | 29 | |||
1455 | 30 | #define __CUPS_ADD_OPTION(dest, name, value) dest->num_options = \ | ||
1456 | 31 | cupsAddOption(name, value, dest->num_options, &dest->options); | ||
1457 | 32 | |||
1458 | 33 | #define __CUPS_ATTR_EXISTS(map, attr, type) map.contains(attr) \ | ||
1459 | 34 | && map.value(attr).canConvert<type>() | ||
1460 | 35 | |||
1461 | 36 | PrinterCupsBackend::PrinterCupsBackend(IppClient *client, QPrinterInfo info, | ||
1462 | 37 | OrgCupsCupsdNotifierInterface *notifier, | ||
1463 | 38 | QObject *parent) | ||
1464 | 39 | : PrinterBackend(info.printerName(), parent) | ||
1465 | 40 | , m_knownQualityOptions({ | ||
1466 | 41 | "Quality", "PrintQuality", "HPPrintQuality", "StpQuality", | ||
1467 | 42 | "OutputMode",}) | ||
1468 | 43 | , m_client(client) | ||
1469 | 44 | , m_info(info) | ||
1470 | 45 | , m_notifier(notifier) | ||
1471 | 46 | , m_cupsSubscriptionId(-1) | ||
1472 | 47 | { | ||
1473 | 48 | m_type = PrinterEnum::PrinterType::CupsType; | ||
1474 | 49 | connect(m_notifier, SIGNAL(JobCompleted(const QString&, const QString&, | ||
1475 | 50 | const QString&, uint, | ||
1476 | 51 | const QString&, bool, uint, uint, | ||
1477 | 52 | const QString&, const QString&, uint)), | ||
1478 | 53 | this, SIGNAL(jobCompleted(const QString&, const QString&, | ||
1479 | 54 | const QString&, uint, const QString&, | ||
1480 | 55 | bool, uint, uint, const QString&, | ||
1481 | 56 | const QString&, uint))); | ||
1482 | 57 | connect(m_notifier, SIGNAL(JobCreated(const QString&, const QString&, | ||
1483 | 58 | const QString&, uint, const QString&, | ||
1484 | 59 | bool, uint, uint, const QString&, | ||
1485 | 60 | const QString&, uint)), | ||
1486 | 61 | this, SIGNAL(jobCreated(const QString&, const QString&, | ||
1487 | 62 | const QString&, uint, const QString&, bool, | ||
1488 | 63 | uint, uint, const QString&, const QString&, | ||
1489 | 64 | uint))); | ||
1490 | 65 | connect(m_notifier, SIGNAL(JobState(const QString&, const QString&, | ||
1491 | 66 | const QString&, uint, const QString&, | ||
1492 | 67 | bool, uint, uint, const QString&, | ||
1493 | 68 | const QString&, uint)), | ||
1494 | 69 | this, SIGNAL(jobState(const QString&, const QString&, | ||
1495 | 70 | const QString&, uint, const QString&, bool, | ||
1496 | 71 | uint, uint, const QString&, const QString&, | ||
1497 | 72 | uint))); | ||
1498 | 73 | connect(m_notifier, SIGNAL(PrinterAdded(const QString&, const QString&, | ||
1499 | 74 | const QString&, uint, | ||
1500 | 75 | const QString&, bool)), | ||
1501 | 76 | this, SIGNAL(printerAdded(const QString&, const QString&, | ||
1502 | 77 | const QString&, uint, | ||
1503 | 78 | const QString&, bool))); | ||
1504 | 79 | connect(m_notifier, SIGNAL(PrinterDeleted(const QString&, const QString&, | ||
1505 | 80 | const QString&, uint, | ||
1506 | 81 | const QString&, bool)), | ||
1507 | 82 | this, SIGNAL(printerDeleted(const QString&, const QString&, | ||
1508 | 83 | const QString&, uint, | ||
1509 | 84 | const QString&, bool))); | ||
1510 | 85 | connect(m_notifier, SIGNAL(PrinterModified(const QString&, const QString&, | ||
1511 | 86 | const QString&, uint, | ||
1512 | 87 | const QString&, bool)), | ||
1513 | 88 | this, SIGNAL(printerModified(const QString&, const QString&, | ||
1514 | 89 | const QString&, uint, | ||
1515 | 90 | const QString&, bool))); | ||
1516 | 91 | connect(m_notifier, SIGNAL(PrinterStateChanged(const QString&, | ||
1517 | 92 | const QString&, | ||
1518 | 93 | const QString&, uint, | ||
1519 | 94 | const QString&, bool)), | ||
1520 | 95 | this, SIGNAL(printerStateChanged(const QString&, const QString&, | ||
1521 | 96 | const QString&, uint, | ||
1522 | 97 | const QString&, bool))); | ||
1523 | 98 | |||
1524 | 99 | } | ||
1525 | 100 | |||
1526 | 101 | PrinterCupsBackend::~PrinterCupsBackend() | ||
1527 | 102 | { | ||
1528 | 103 | Q_FOREACH(auto dest, m_dests) { | ||
1529 | 104 | if (dest) | ||
1530 | 105 | cupsFreeDests(1, dest); | ||
1531 | 106 | } | ||
1532 | 107 | Q_FOREACH(auto ppd, m_ppds) { | ||
1533 | 108 | if (ppd) | ||
1534 | 109 | ppdClose(ppd); | ||
1535 | 110 | } | ||
1536 | 111 | |||
1537 | 112 | cancelSubscription(); | ||
1538 | 113 | Q_EMIT cancelWorkers(); | ||
1539 | 114 | } | ||
1540 | 115 | |||
1541 | 116 | QString PrinterCupsBackend::printerAdd(const QString &name, | ||
1542 | 117 | const QString &uri, | ||
1543 | 118 | const QString &ppdFile, | ||
1544 | 119 | const QString &info, | ||
1545 | 120 | const QString &location) | ||
1546 | 121 | { | ||
1547 | 122 | if (!m_client->printerAdd(name, uri, ppdFile, info, location)) { | ||
1548 | 123 | return m_client->getLastError(); | ||
1549 | 124 | } | ||
1550 | 125 | return QString(); | ||
1551 | 126 | } | ||
1552 | 127 | |||
1553 | 128 | QString PrinterCupsBackend::printerAddWithPpd(const QString &name, | ||
1554 | 129 | const QString &uri, | ||
1555 | 130 | const QString &ppdFileName, | ||
1556 | 131 | const QString &info, | ||
1557 | 132 | const QString &location) | ||
1558 | 133 | { | ||
1559 | 134 | if (!m_client->printerAddWithPpdFile(name, uri, ppdFileName, info, location)) { | ||
1560 | 135 | return m_client->getLastError(); | ||
1561 | 136 | } | ||
1562 | 137 | return QString(); | ||
1563 | 138 | } | ||
1564 | 139 | |||
1565 | 140 | bool PrinterCupsBackend::holdsDefinition() const | ||
1566 | 141 | { | ||
1567 | 142 | return !m_info.isNull(); | ||
1568 | 143 | } | ||
1569 | 144 | |||
1570 | 145 | QString PrinterCupsBackend::printerDelete(const QString &name) | ||
1571 | 146 | { | ||
1572 | 147 | if (!m_client->printerDelete(name)) { | ||
1573 | 148 | return m_client->getLastError(); | ||
1574 | 149 | } | ||
1575 | 150 | return QString(); | ||
1576 | 151 | } | ||
1577 | 152 | |||
1578 | 153 | QString PrinterCupsBackend::printerSetDefault(const QString &name) | ||
1579 | 154 | { | ||
1580 | 155 | if (!m_client->printerSetDefault(name)) { | ||
1581 | 156 | return m_client->getLastError(); | ||
1582 | 157 | } | ||
1583 | 158 | return QString(); | ||
1584 | 159 | } | ||
1585 | 160 | |||
1586 | 161 | QString PrinterCupsBackend::printerSetEnabled(const QString &name, | ||
1587 | 162 | const bool enabled) | ||
1588 | 163 | { | ||
1589 | 164 | if (!m_client->printerSetEnabled(name, enabled)) { | ||
1590 | 165 | return m_client->getLastError(); | ||
1591 | 166 | } | ||
1592 | 167 | return QString(); | ||
1593 | 168 | } | ||
1594 | 169 | |||
1595 | 170 | QString PrinterCupsBackend::printerSetAcceptJobs( | ||
1596 | 171 | const QString &name, | ||
1597 | 172 | const bool accept, | ||
1598 | 173 | const QString &reason) | ||
1599 | 174 | { | ||
1600 | 175 | if (!m_client->printerSetAcceptJobs(name, accept, reason)) { | ||
1601 | 176 | return m_client->getLastError(); | ||
1602 | 177 | } | ||
1603 | 178 | return QString(); | ||
1604 | 179 | } | ||
1605 | 180 | |||
1606 | 181 | QString PrinterCupsBackend::printerSetInfo(const QString &name, | ||
1607 | 182 | const QString &info) | ||
1608 | 183 | { | ||
1609 | 184 | if (!m_client->printerClassSetInfo(name, info)) { | ||
1610 | 185 | return m_client->getLastError(); | ||
1611 | 186 | } | ||
1612 | 187 | return QString(); | ||
1613 | 188 | } | ||
1614 | 189 | |||
1615 | 190 | QString PrinterCupsBackend::printerSetLocation(const QString &name, | ||
1616 | 191 | const QString &location) | ||
1617 | 192 | { | ||
1618 | 193 | Q_UNUSED(name); | ||
1619 | 194 | Q_UNUSED(location); | ||
1620 | 195 | return QString(); | ||
1621 | 196 | } | ||
1622 | 197 | |||
1623 | 198 | QString PrinterCupsBackend::printerSetShared(const QString &name, | ||
1624 | 199 | const bool shared) | ||
1625 | 200 | { | ||
1626 | 201 | Q_UNUSED(name); | ||
1627 | 202 | Q_UNUSED(shared); | ||
1628 | 203 | return QString(); | ||
1629 | 204 | } | ||
1630 | 205 | |||
1631 | 206 | QString PrinterCupsBackend::printerSetJobSheets(const QString &name, | ||
1632 | 207 | const QString &start, | ||
1633 | 208 | const QString &end) | ||
1634 | 209 | { | ||
1635 | 210 | Q_UNUSED(name); | ||
1636 | 211 | Q_UNUSED(start); | ||
1637 | 212 | Q_UNUSED(end); | ||
1638 | 213 | return QString(); | ||
1639 | 214 | } | ||
1640 | 215 | |||
1641 | 216 | QString PrinterCupsBackend::printerSetErrorPolicy(const QString &name, | ||
1642 | 217 | const PrinterEnum::ErrorPolicy &policy) | ||
1643 | 218 | { | ||
1644 | 219 | Q_UNUSED(name); | ||
1645 | 220 | Q_UNUSED(policy); | ||
1646 | 221 | return QString(); | ||
1647 | 222 | } | ||
1648 | 223 | |||
1649 | 224 | QString PrinterCupsBackend::printerSetOpPolicy(const QString &name, | ||
1650 | 225 | const PrinterEnum::OperationPolicy &policy) | ||
1651 | 226 | { | ||
1652 | 227 | Q_UNUSED(name); | ||
1653 | 228 | Q_UNUSED(policy); | ||
1654 | 229 | return QString(); | ||
1655 | 230 | } | ||
1656 | 231 | |||
1657 | 232 | QString PrinterCupsBackend::printerSetUsersAllowed(const QString &name, | ||
1658 | 233 | const QStringList &users) | ||
1659 | 234 | { | ||
1660 | 235 | Q_UNUSED(name); | ||
1661 | 236 | Q_UNUSED(users); | ||
1662 | 237 | return QString(); | ||
1663 | 238 | } | ||
1664 | 239 | |||
1665 | 240 | QString PrinterCupsBackend::printerSetUsersDenied(const QString &name, | ||
1666 | 241 | const QStringList &users) | ||
1667 | 242 | { | ||
1668 | 243 | Q_UNUSED(name); | ||
1669 | 244 | Q_UNUSED(users); | ||
1670 | 245 | return QString(); | ||
1671 | 246 | } | ||
1672 | 247 | |||
1673 | 248 | QString PrinterCupsBackend::printerAddOptionDefault(const QString &name, | ||
1674 | 249 | const QString &option, | ||
1675 | 250 | const QStringList &values) | ||
1676 | 251 | { | ||
1677 | 252 | Q_UNUSED(name); | ||
1678 | 253 | Q_UNUSED(option); | ||
1679 | 254 | Q_UNUSED(values); | ||
1680 | 255 | return QString(); | ||
1681 | 256 | } | ||
1682 | 257 | |||
1683 | 258 | QString PrinterCupsBackend::printerDeleteOptionDefault(const QString &name, | ||
1684 | 259 | const QString &value) | ||
1685 | 260 | { | ||
1686 | 261 | Q_UNUSED(name); | ||
1687 | 262 | Q_UNUSED(value); | ||
1688 | 263 | return QString(); | ||
1689 | 264 | } | ||
1690 | 265 | |||
1691 | 266 | QString PrinterCupsBackend::printerAddOption(const QString &name, | ||
1692 | 267 | const QString &option, | ||
1693 | 268 | const QStringList &values) | ||
1694 | 269 | { | ||
1695 | 270 | if (!m_client->printerClassSetOption(name, option, values)) { | ||
1696 | 271 | return m_client->getLastError(); | ||
1697 | 272 | } | ||
1698 | 273 | |||
1699 | 274 | return QString(); | ||
1700 | 275 | } | ||
1701 | 276 | |||
1702 | 277 | QVariant PrinterCupsBackend::printerGetOption(const QString &name, | ||
1703 | 278 | const QString &option) const | ||
1704 | 279 | { | ||
1705 | 280 | auto res = printerGetOptions(name, QStringList({option})); | ||
1706 | 281 | return res[option]; | ||
1707 | 282 | } | ||
1708 | 283 | |||
1709 | 284 | QMap<QString, QVariant> PrinterCupsBackend::printerGetOptions( | ||
1710 | 285 | const QString &name, const QStringList &options) const | ||
1711 | 286 | { | ||
1712 | 287 | QMap<QString, QVariant> ret; | ||
1713 | 288 | |||
1714 | 289 | cups_dest_t *dest = getDest(name); | ||
1715 | 290 | ppd_file_t* ppd = getPpd(name); | ||
1716 | 291 | |||
1717 | 292 | if (!dest || !ppd) { | ||
1718 | 293 | return ret; | ||
1719 | 294 | } | ||
1720 | 295 | |||
1721 | 296 | Q_FOREACH(const QString &option, options) { | ||
1722 | 297 | if (option == QStringLiteral("DefaultColorModel")) { | ||
1723 | 298 | ColorModel model; | ||
1724 | 299 | ppd_option_t *ppdColorModel = ppdFindOption(ppd, "ColorModel"); | ||
1725 | 300 | if (ppdColorModel) { | ||
1726 | 301 | ppd_choice_t* def = ppdFindChoice(ppdColorModel, | ||
1727 | 302 | ppdColorModel->defchoice); | ||
1728 | 303 | if (def) { | ||
1729 | 304 | model = Utils::parsePpdColorModel(def->choice, | ||
1730 | 305 | def->text, | ||
1731 | 306 | "ColorModel"); | ||
1732 | 307 | } | ||
1733 | 308 | } | ||
1734 | 309 | ret[option] = QVariant::fromValue(model); | ||
1735 | 310 | } else if (option == QStringLiteral("DefaultPrintQuality")) { | ||
1736 | 311 | PrintQuality quality; | ||
1737 | 312 | Q_FOREACH(const QString opt, m_knownQualityOptions) { | ||
1738 | 313 | ppd_option_t *ppdQuality = ppdFindOption(ppd, opt.toUtf8()); | ||
1739 | 314 | if (ppdQuality) { | ||
1740 | 315 | ppd_choice_t* def = ppdFindChoice(ppdQuality, | ||
1741 | 316 | ppdQuality->defchoice); | ||
1742 | 317 | if (def) { | ||
1743 | 318 | quality = Utils::parsePpdPrintQuality(def->choice, | ||
1744 | 319 | def->text, opt); | ||
1745 | 320 | } | ||
1746 | 321 | } | ||
1747 | 322 | } | ||
1748 | 323 | ret[option] = QVariant::fromValue(quality); | ||
1749 | 324 | } else if (option == QStringLiteral("SupportedPrintQualities")) { | ||
1750 | 325 | QList<PrintQuality> qualities; | ||
1751 | 326 | Q_FOREACH(const QString &opt, m_knownQualityOptions) { | ||
1752 | 327 | ppd_option_t *qualityOpt = ppdFindOption(ppd, opt.toUtf8()); | ||
1753 | 328 | if (qualityOpt) { | ||
1754 | 329 | for (int i = 0; i < qualityOpt->num_choices; ++i) { | ||
1755 | 330 | qualities.append( | ||
1756 | 331 | Utils::parsePpdPrintQuality( | ||
1757 | 332 | qualityOpt->choices[i].choice, | ||
1758 | 333 | qualityOpt->choices[i].text, | ||
1759 | 334 | opt | ||
1760 | 335 | ) | ||
1761 | 336 | ); | ||
1762 | 337 | } | ||
1763 | 338 | } | ||
1764 | 339 | } | ||
1765 | 340 | ret[option] = QVariant::fromValue(qualities); | ||
1766 | 341 | } else if (option == QStringLiteral("SupportedColorModels")) { | ||
1767 | 342 | QList<ColorModel> models; | ||
1768 | 343 | ppd_option_t *colorModels = ppdFindOption(ppd, "ColorModel"); | ||
1769 | 344 | if (colorModels) { | ||
1770 | 345 | for (int i = 0; i < colorModels->num_choices; ++i) { | ||
1771 | 346 | models.append( | ||
1772 | 347 | Utils::parsePpdColorModel( | ||
1773 | 348 | colorModels->choices[i].choice, | ||
1774 | 349 | colorModels->choices[i].text, | ||
1775 | 350 | QStringLiteral("ColorModel") | ||
1776 | 351 | ) | ||
1777 | 352 | ); | ||
1778 | 353 | } | ||
1779 | 354 | } | ||
1780 | 355 | ret[option] = QVariant::fromValue(models); | ||
1781 | 356 | } else if (option == QStringLiteral("AcceptJobs")) { | ||
1782 | 357 | // "true" if the destination is accepting new jobs, "false" if not. | ||
1783 | 358 | QString res = cupsGetOption("printer-is-accepting-jobs", | ||
1784 | 359 | dest->num_options, dest->options); | ||
1785 | 360 | ret[option] = res.contains("true"); | ||
1786 | 361 | } else { | ||
1787 | 362 | ppd_option_t *val = ppdFindOption(ppd, option.toUtf8()); | ||
1788 | 363 | |||
1789 | 364 | if (val) { | ||
1790 | 365 | qWarning() << "asking for" << option << "returns" << val->text; | ||
1791 | 366 | } else { | ||
1792 | 367 | qWarning() << "option" << option << "yielded no option"; | ||
1793 | 368 | } | ||
1794 | 369 | } | ||
1795 | 370 | } | ||
1796 | 371 | return ret; | ||
1797 | 372 | } | ||
1798 | 373 | |||
1799 | 374 | // FIXME: maybe have a PrinterDest iface that has a CupsDest impl? | ||
1800 | 375 | cups_dest_t* PrinterCupsBackend::makeDest(const QString &name, | ||
1801 | 376 | const PrinterJob *options) | ||
1802 | 377 | { | ||
1803 | 378 | // Get the cups dest | ||
1804 | 379 | cups_dest_t *dest = getDest(name); | ||
1805 | 380 | |||
1806 | 381 | if (options->collate()) { | ||
1807 | 382 | __CUPS_ADD_OPTION(dest, "Collate", "True"); | ||
1808 | 383 | } else { | ||
1809 | 384 | __CUPS_ADD_OPTION(dest, "Collate", "False"); | ||
1810 | 385 | } | ||
1811 | 386 | |||
1812 | 387 | if (options->copies() > 1) { | ||
1813 | 388 | __CUPS_ADD_OPTION(dest, "copies", QString::number(options->copies()).toLocal8Bit()); | ||
1814 | 389 | } | ||
1815 | 390 | |||
1816 | 391 | __CUPS_ADD_OPTION(dest, "ColorModel", options->getColorModel().name.toLocal8Bit()); | ||
1817 | 392 | __CUPS_ADD_OPTION(dest, "Duplex", Utils::duplexModeToPpdChoice(options->getDuplexMode()).toLocal8Bit()); | ||
1818 | 393 | |||
1819 | 394 | if (options->landscape()) { | ||
1820 | 395 | __CUPS_ADD_OPTION(dest, "landscape", ""); | ||
1821 | 396 | } | ||
1822 | 397 | |||
1823 | 398 | if (options->printRangeMode() == PrinterEnum::PrintRange::PageRange | ||
1824 | 399 | && !options->printRange().isEmpty()) { | ||
1825 | 400 | __CUPS_ADD_OPTION(dest, "page-ranges", options->printRange().toLocal8Bit()); | ||
1826 | 401 | } | ||
1827 | 402 | |||
1828 | 403 | PrintQuality quality = options->getPrintQuality(); | ||
1829 | 404 | __CUPS_ADD_OPTION(dest, quality.originalOption.toLocal8Bit(), | ||
1830 | 405 | quality.name.toLocal8Bit()); | ||
1831 | 406 | |||
1832 | 407 | if (options->reverse()) { | ||
1833 | 408 | __CUPS_ADD_OPTION(dest, "OutputOrder", "Reverse"); | ||
1834 | 409 | } else { | ||
1835 | 410 | __CUPS_ADD_OPTION(dest, "OutputOrder", "Normal"); | ||
1836 | 411 | } | ||
1837 | 412 | |||
1838 | 413 | // Always scale to fit the page for now | ||
1839 | 414 | __CUPS_ADD_OPTION(dest, "fit-to-page", "True"); | ||
1840 | 415 | |||
1841 | 416 | return dest; | ||
1842 | 417 | } | ||
1843 | 418 | |||
1844 | 419 | void PrinterCupsBackend::cancelJob(const QString &name, const int jobId) | ||
1845 | 420 | { | ||
1846 | 421 | int ret = cupsCancelJob(name.toLocal8Bit(), jobId); | ||
1847 | 422 | |||
1848 | 423 | if (!ret) { | ||
1849 | 424 | qWarning() << "Failed to cancel job:" << jobId << "for" << name; | ||
1850 | 425 | } | ||
1851 | 426 | } | ||
1852 | 427 | |||
1853 | 428 | int PrinterCupsBackend::printFileToDest(const QString &filepath, | ||
1854 | 429 | const QString &title, | ||
1855 | 430 | const cups_dest_t *dest) | ||
1856 | 431 | { | ||
1857 | 432 | qDebug() << "Printing:" << filepath << title << dest->name << dest->num_options; | ||
1858 | 433 | return cupsPrintFile(dest->name, | ||
1859 | 434 | filepath.toLocal8Bit(), | ||
1860 | 435 | title.toLocal8Bit(), | ||
1861 | 436 | dest->num_options, | ||
1862 | 437 | dest->options); | ||
1863 | 438 | } | ||
1864 | 439 | |||
1865 | 440 | |||
1866 | 441 | QList<cups_job_t *> PrinterCupsBackend::getCupsJobs(const QString &name) | ||
1867 | 442 | { | ||
1868 | 443 | QList<cups_job_t *> list; | ||
1869 | 444 | cups_job_t *jobs; | ||
1870 | 445 | |||
1871 | 446 | // Get a list of the jobs that are 'mine' and only active ones | ||
1872 | 447 | // https://www.cups.org/doc/api-cups.html#cupsGetJobs | ||
1873 | 448 | int count; | ||
1874 | 449 | if (name.isEmpty()) { | ||
1875 | 450 | count = cupsGetJobs(&jobs, NULL, 1, CUPS_WHICHJOBS_ACTIVE); | ||
1876 | 451 | } else { | ||
1877 | 452 | count = cupsGetJobs(&jobs, name.toLocal8Bit(), 1, CUPS_WHICHJOBS_ACTIVE); | ||
1878 | 453 | } | ||
1879 | 454 | |||
1880 | 455 | for (int i=0; i < count; i++) { | ||
1881 | 456 | list.append(&jobs[i]); | ||
1882 | 457 | } | ||
1883 | 458 | |||
1884 | 459 | return list; | ||
1885 | 460 | } | ||
1886 | 461 | |||
1887 | 462 | QMap<QString, QVariant> PrinterCupsBackend::printerGetJobAttributes( | ||
1888 | 463 | const QString &name, const int jobId) | ||
1889 | 464 | { | ||
1890 | 465 | Q_UNUSED(name); | ||
1891 | 466 | QMap<QString, QVariant> rawMap = m_client->printerGetJobAttributes(jobId); | ||
1892 | 467 | QMap<QString, QVariant> map; | ||
1893 | 468 | |||
1894 | 469 | // Filter attributes to know values | ||
1895 | 470 | // Do this here so we can use things such as m_knownQualityOptions | ||
1896 | 471 | |||
1897 | 472 | if (__CUPS_ATTR_EXISTS(rawMap, "Collate", bool)) { | ||
1898 | 473 | map.insert("Collate", rawMap.value("Collate")); | ||
1899 | 474 | } else { | ||
1900 | 475 | map.insert("Collate", QVariant(true)); | ||
1901 | 476 | } | ||
1902 | 477 | |||
1903 | 478 | if (__CUPS_ATTR_EXISTS(rawMap, "copies", int)) { | ||
1904 | 479 | map.insert("copies", rawMap.value("copies")); | ||
1905 | 480 | } else { | ||
1906 | 481 | map.insert("copies", QVariant(1)); | ||
1907 | 482 | } | ||
1908 | 483 | |||
1909 | 484 | if (__CUPS_ATTR_EXISTS(rawMap, "ColorModel", QString)) { | ||
1910 | 485 | map.insert("ColorModel", rawMap.value("ColorModel")); | ||
1911 | 486 | } else { | ||
1912 | 487 | map.insert("ColorModel", QVariant("")); | ||
1913 | 488 | } | ||
1914 | 489 | |||
1915 | 490 | if (__CUPS_ATTR_EXISTS(rawMap, "Duplex", QString)) { | ||
1916 | 491 | map.insert("Duplex", rawMap.value("Duplex")); | ||
1917 | 492 | } else { | ||
1918 | 493 | map.insert("Duplex", QVariant("")); | ||
1919 | 494 | } | ||
1920 | 495 | |||
1921 | 496 | if (__CUPS_ATTR_EXISTS(rawMap, "landscape", bool)) { | ||
1922 | 497 | map.insert("landscape", rawMap.value("landscape")); | ||
1923 | 498 | } else { | ||
1924 | 499 | map.insert("landscape", QVariant(false)); | ||
1925 | 500 | } | ||
1926 | 501 | |||
1927 | 502 | if (__CUPS_ATTR_EXISTS(rawMap, "page-ranges", QList<QVariant>)) { | ||
1928 | 503 | QList<QVariant> range = rawMap.value("page-ranges").toList(); | ||
1929 | 504 | QStringList rangeStrings; | ||
1930 | 505 | |||
1931 | 506 | Q_FOREACH(QVariant var, range) { | ||
1932 | 507 | rangeStrings << var.toString(); | ||
1933 | 508 | } | ||
1934 | 509 | |||
1935 | 510 | map.insert("page-ranges", QVariant(rangeStrings)); | ||
1936 | 511 | } else { | ||
1937 | 512 | map.insert("page-ranges", QVariant(QStringList())); | ||
1938 | 513 | } | ||
1939 | 514 | |||
1940 | 515 | Q_FOREACH(QString qualityOption, m_knownQualityOptions) { | ||
1941 | 516 | if (rawMap.contains(qualityOption) | ||
1942 | 517 | && rawMap.value(qualityOption).canConvert<QString>()) { | ||
1943 | 518 | map.insert("quality", rawMap.value(qualityOption).toString()); | ||
1944 | 519 | } | ||
1945 | 520 | } | ||
1946 | 521 | |||
1947 | 522 | if (!map.contains("quality")) { | ||
1948 | 523 | map.insert("quality", QVariant("")); | ||
1949 | 524 | } | ||
1950 | 525 | |||
1951 | 526 | if (__CUPS_ATTR_EXISTS(rawMap, "OutputOrder", QString)) { | ||
1952 | 527 | map.insert("OutputOrder", rawMap.value("OutputOrder")); | ||
1953 | 528 | } else { | ||
1954 | 529 | map.insert("OutputOrder", "Normal"); | ||
1955 | 530 | } | ||
1956 | 531 | |||
1957 | 532 | // Generate a list of messages | ||
1958 | 533 | // TODO: for now just using job-printer-state-message, are there others? | ||
1959 | 534 | QStringList messages; | ||
1960 | 535 | |||
1961 | 536 | if (__CUPS_ATTR_EXISTS(rawMap, "job-printer-state-message", QString)) { | ||
1962 | 537 | messages << rawMap.value("job-printer-state-message").toString(); | ||
1963 | 538 | } | ||
1964 | 539 | |||
1965 | 540 | map.insert("messages", QVariant(messages)); | ||
1966 | 541 | |||
1967 | 542 | return map; | ||
1968 | 543 | } | ||
1969 | 544 | |||
1970 | 545 | |||
1971 | 546 | QList<QSharedPointer<PrinterJob>> PrinterCupsBackend::printerGetJobs() | ||
1972 | 547 | { | ||
1973 | 548 | auto jobs = getCupsJobs(); | ||
1974 | 549 | QList<QSharedPointer<PrinterJob>> list; | ||
1975 | 550 | |||
1976 | 551 | Q_FOREACH(auto job, jobs) { | ||
1977 | 552 | auto newJob = QSharedPointer<PrinterJob>( | ||
1978 | 553 | new PrinterJob(QString::fromUtf8(job->dest), this, job->id) | ||
1979 | 554 | ); | ||
1980 | 555 | |||
1981 | 556 | // Extract the times | ||
1982 | 557 | QDateTime completedTime; | ||
1983 | 558 | completedTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
1984 | 559 | completedTime.setTime_t(job->completed_time); | ||
1985 | 560 | |||
1986 | 561 | QDateTime creationTime; | ||
1987 | 562 | creationTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
1988 | 563 | creationTime.setTime_t(job->creation_time); | ||
1989 | 564 | |||
1990 | 565 | QDateTime processingTime; | ||
1991 | 566 | processingTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
1992 | 567 | processingTime.setTime_t(job->processing_time); | ||
1993 | 568 | |||
1994 | 569 | // Load the information from the cups struct | ||
1995 | 570 | newJob->setCompletedTime(completedTime); | ||
1996 | 571 | newJob->setCreationTime(creationTime); | ||
1997 | 572 | newJob->setProcessingTime(processingTime); | ||
1998 | 573 | newJob->setSize(job->size); | ||
1999 | 574 | newJob->setState(static_cast<PrinterEnum::JobState>(job->state)); | ||
2000 | 575 | newJob->setTitle(QString::fromLocal8Bit(job->title)); | ||
2001 | 576 | newJob->setUser(QString::fromLocal8Bit(job->user)); | ||
2002 | 577 | |||
2003 | 578 | list.append(newJob); | ||
2004 | 579 | } | ||
2005 | 580 | if (!list.isEmpty()) | ||
2006 | 581 | cupsFreeJobs(list.size(), jobs.first()); | ||
2007 | 582 | |||
2008 | 583 | return list; | ||
2009 | 584 | } | ||
2010 | 585 | |||
2011 | 586 | QString PrinterCupsBackend::printerName() const | ||
2012 | 587 | { | ||
2013 | 588 | return m_printerName; | ||
2014 | 589 | } | ||
2015 | 590 | |||
2016 | 591 | QString PrinterCupsBackend::description() const | ||
2017 | 592 | { | ||
2018 | 593 | return m_info.description(); | ||
2019 | 594 | } | ||
2020 | 595 | |||
2021 | 596 | QString PrinterCupsBackend::location() const | ||
2022 | 597 | { | ||
2023 | 598 | return m_info.location(); | ||
2024 | 599 | } | ||
2025 | 600 | |||
2026 | 601 | QString PrinterCupsBackend::makeAndModel() const | ||
2027 | 602 | { | ||
2028 | 603 | return m_info.makeAndModel(); | ||
2029 | 604 | } | ||
2030 | 605 | |||
2031 | 606 | PrinterEnum::State PrinterCupsBackend::state() const | ||
2032 | 607 | { | ||
2033 | 608 | switch (m_info.state()) { | ||
2034 | 609 | case QPrinter::Active: | ||
2035 | 610 | return PrinterEnum::State::ActiveState; | ||
2036 | 611 | case QPrinter::Aborted: | ||
2037 | 612 | return PrinterEnum::State::AbortedState; | ||
2038 | 613 | case QPrinter::Error: | ||
2039 | 614 | return PrinterEnum::State::ErrorState; | ||
2040 | 615 | case QPrinter::Idle: | ||
2041 | 616 | default: | ||
2042 | 617 | return PrinterEnum::State::IdleState; | ||
2043 | 618 | } | ||
2044 | 619 | } | ||
2045 | 620 | |||
2046 | 621 | QList<QPageSize> PrinterCupsBackend::supportedPageSizes() const | ||
2047 | 622 | { | ||
2048 | 623 | return m_info.supportedPageSizes(); | ||
2049 | 624 | } | ||
2050 | 625 | |||
2051 | 626 | QPageSize PrinterCupsBackend::defaultPageSize() const | ||
2052 | 627 | { | ||
2053 | 628 | return m_info.defaultPageSize(); | ||
2054 | 629 | } | ||
2055 | 630 | |||
2056 | 631 | bool PrinterCupsBackend::supportsCustomPageSizes() const | ||
2057 | 632 | { | ||
2058 | 633 | return m_info.supportsCustomPageSizes(); | ||
2059 | 634 | } | ||
2060 | 635 | |||
2061 | 636 | QPageSize PrinterCupsBackend::minimumPhysicalPageSize() const | ||
2062 | 637 | { | ||
2063 | 638 | return m_info.minimumPhysicalPageSize(); | ||
2064 | 639 | } | ||
2065 | 640 | |||
2066 | 641 | QPageSize PrinterCupsBackend::maximumPhysicalPageSize() const | ||
2067 | 642 | { | ||
2068 | 643 | return m_info.maximumPhysicalPageSize(); | ||
2069 | 644 | } | ||
2070 | 645 | |||
2071 | 646 | QList<int> PrinterCupsBackend::supportedResolutions() const | ||
2072 | 647 | { | ||
2073 | 648 | return m_info.supportedResolutions(); | ||
2074 | 649 | } | ||
2075 | 650 | |||
2076 | 651 | PrinterEnum::DuplexMode PrinterCupsBackend::defaultDuplexMode() const | ||
2077 | 652 | { | ||
2078 | 653 | return Utils::qDuplexModeToDuplexMode(m_info.defaultDuplexMode()); | ||
2079 | 654 | } | ||
2080 | 655 | |||
2081 | 656 | QList<PrinterEnum::DuplexMode> PrinterCupsBackend::supportedDuplexModes() const | ||
2082 | 657 | { | ||
2083 | 658 | QList<PrinterEnum::DuplexMode> list; | ||
2084 | 659 | Q_FOREACH(const QPrinter::DuplexMode mode, m_info.supportedDuplexModes()) { | ||
2085 | 660 | if (mode != QPrinter::DuplexAuto) { | ||
2086 | 661 | list.append(Utils::qDuplexModeToDuplexMode(mode)); | ||
2087 | 662 | } | ||
2088 | 663 | } | ||
2089 | 664 | |||
2090 | 665 | if (list.isEmpty()) | ||
2091 | 666 | list.append(PrinterEnum::DuplexMode::DuplexNone); | ||
2092 | 667 | |||
2093 | 668 | return list; | ||
2094 | 669 | } | ||
2095 | 670 | |||
2096 | 671 | QList<QSharedPointer<Printer>> PrinterCupsBackend::availablePrinters() | ||
2097 | 672 | { | ||
2098 | 673 | return QList<QSharedPointer<Printer>>(); | ||
2099 | 674 | } | ||
2100 | 675 | |||
2101 | 676 | QStringList PrinterCupsBackend::availablePrinterNames() | ||
2102 | 677 | { | ||
2103 | 678 | return QPrinterInfo::availablePrinterNames(); | ||
2104 | 679 | } | ||
2105 | 680 | |||
2106 | 681 | QSharedPointer<Printer> PrinterCupsBackend::getPrinter(const QString &printerName) | ||
2107 | 682 | { | ||
2108 | 683 | QPrinterInfo info = QPrinterInfo::printerInfo(printerName); | ||
2109 | 684 | return QSharedPointer<Printer>(new Printer(new PrinterCupsBackend(m_client, info, m_notifier))); | ||
2110 | 685 | } | ||
2111 | 686 | |||
2112 | 687 | QString PrinterCupsBackend::defaultPrinterName() | ||
2113 | 688 | { | ||
2114 | 689 | return QPrinterInfo::defaultPrinterName(); | ||
2115 | 690 | } | ||
2116 | 691 | |||
2117 | 692 | void PrinterCupsBackend::requestPrinter(const QString &printerName) | ||
2118 | 693 | { | ||
2119 | 694 | auto thread = new QThread; | ||
2120 | 695 | auto loader = new PrinterLoader(printerName, m_client, m_notifier); | ||
2121 | 696 | loader->moveToThread(thread); | ||
2122 | 697 | connect(thread, SIGNAL(started()), loader, SLOT(load())); | ||
2123 | 698 | connect(loader, SIGNAL(finished()), thread, SLOT(quit())); | ||
2124 | 699 | connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater())); | ||
2125 | 700 | connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)), | ||
2126 | 701 | this, SIGNAL(printerLoaded(QSharedPointer<Printer>))); | ||
2127 | 702 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | ||
2128 | 703 | thread->start(); | ||
2129 | 704 | } | ||
2130 | 705 | |||
2131 | 706 | void PrinterCupsBackend::requestPrinterDrivers() | ||
2132 | 707 | { | ||
2133 | 708 | auto thread = new QThread; | ||
2134 | 709 | auto loader = new PrinterDriverLoader(); | ||
2135 | 710 | loader->moveToThread(thread); | ||
2136 | 711 | connect(loader, SIGNAL(error(const QString&)), | ||
2137 | 712 | this, SIGNAL(printerDriversFailedToLoad(const QString&))); | ||
2138 | 713 | connect(this, SIGNAL(requestPrinterDriverCancel()), loader, SLOT(cancel())); | ||
2139 | 714 | connect(thread, SIGNAL(started()), loader, SLOT(process())); | ||
2140 | 715 | connect(loader, SIGNAL(finished()), thread, SLOT(quit())); | ||
2141 | 716 | connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater())); | ||
2142 | 717 | connect(loader, SIGNAL(loaded(const QList<PrinterDriver>&)), | ||
2143 | 718 | this, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&))); | ||
2144 | 719 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | ||
2145 | 720 | thread->start(); | ||
2146 | 721 | } | ||
2147 | 722 | |||
2148 | 723 | void PrinterCupsBackend::cancelPrinterDriverRequest() | ||
2149 | 724 | { | ||
2150 | 725 | Q_EMIT requestPrinterDriverCancel(); | ||
2151 | 726 | } | ||
2152 | 727 | |||
2153 | 728 | void PrinterCupsBackend::refresh() | ||
2154 | 729 | { | ||
2155 | 730 | if (m_printerName.isEmpty()) { | ||
2156 | 731 | throw std::invalid_argument("Trying to refresh unnamed printer."); | ||
2157 | 732 | } else { | ||
2158 | 733 | m_info = QPrinterInfo::printerInfo(m_printerName); | ||
2159 | 734 | } | ||
2160 | 735 | } | ||
2161 | 736 | |||
2162 | 737 | void PrinterCupsBackend::createSubscription() | ||
2163 | 738 | { | ||
2164 | 739 | m_cupsSubscriptionId = m_client->createSubscription();; | ||
2165 | 740 | } | ||
2166 | 741 | |||
2167 | 742 | void PrinterCupsBackend::cancelSubscription() | ||
2168 | 743 | { | ||
2169 | 744 | if (m_cupsSubscriptionId > 0) | ||
2170 | 745 | m_client->cancelSubscription(m_cupsSubscriptionId); | ||
2171 | 746 | } | ||
2172 | 747 | |||
2173 | 748 | QString PrinterCupsBackend::getPrinterInstance(const QString &name) const | ||
2174 | 749 | { | ||
2175 | 750 | const auto parts = name.splitRef(QLatin1Char('/')); | ||
2176 | 751 | QString instance; | ||
2177 | 752 | if (parts.size() > 1) | ||
2178 | 753 | instance = parts.at(1).toString(); | ||
2179 | 754 | |||
2180 | 755 | return instance; | ||
2181 | 756 | } | ||
2182 | 757 | |||
2183 | 758 | QString PrinterCupsBackend::getPrinterName(const QString &name) const | ||
2184 | 759 | { | ||
2185 | 760 | return name.splitRef(QLatin1Char('/')).first().toString(); | ||
2186 | 761 | } | ||
2187 | 762 | |||
2188 | 763 | cups_dest_t* PrinterCupsBackend::getDest(const QString &name) const | ||
2189 | 764 | { | ||
2190 | 765 | QString printerName = getPrinterName(name); | ||
2191 | 766 | QString instance = getPrinterInstance(name); | ||
2192 | 767 | |||
2193 | 768 | if (m_dests.contains(name)) { | ||
2194 | 769 | return m_dests[name]; | ||
2195 | 770 | } else { | ||
2196 | 771 | m_dests[name] = m_client->getDest(printerName, instance); | ||
2197 | 772 | return m_dests[name]; | ||
2198 | 773 | } | ||
2199 | 774 | } | ||
2200 | 775 | |||
2201 | 776 | ppd_file_t* PrinterCupsBackend::getPpd(const QString &name) const | ||
2202 | 777 | { | ||
2203 | 778 | QString printerName = getPrinterName(name); | ||
2204 | 779 | QString instance = getPrinterInstance(name); | ||
2205 | 780 | |||
2206 | 781 | if (m_ppds.contains(name)) { | ||
2207 | 782 | return m_ppds[name]; | ||
2208 | 783 | } else { | ||
2209 | 784 | m_ppds[name] = m_client->getPpdFile(printerName, instance); | ||
2210 | 785 | return m_ppds[name]; | ||
2211 | 786 | } | ||
2212 | 787 | } | ||
2213 | 0 | 788 | ||
2214 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h' | |||
2215 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 1970-01-01 00:00:00 +0000 | |||
2216 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-02-22 12:44:26 +0000 | |||
2217 | @@ -0,0 +1,152 @@ | |||
2218 | 1 | /* | ||
2219 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2220 | 3 | * | ||
2221 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2222 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
2223 | 6 | * the Free Software Foundation; version 3. | ||
2224 | 7 | * | ||
2225 | 8 | * This program is distributed in the hope that it will be useful, | ||
2226 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2227 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2228 | 11 | * GNU Lesser General Public License for more details. | ||
2229 | 12 | * | ||
2230 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2231 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2232 | 15 | */ | ||
2233 | 16 | |||
2234 | 17 | #ifndef USC_PRINTERS_CUPS_BACKEND_H | ||
2235 | 18 | #define USC_PRINTERS_CUPS_BACKEND_H | ||
2236 | 19 | |||
2237 | 20 | #include "backend/backend.h" | ||
2238 | 21 | #include "cups/ippclient.h" | ||
2239 | 22 | #include "cupsdnotifier.h" // Note: this file was generated. | ||
2240 | 23 | |||
2241 | 24 | #include <cups/cups.h> | ||
2242 | 25 | |||
2243 | 26 | #include <QPrinterInfo> | ||
2244 | 27 | |||
2245 | 28 | class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend | ||
2246 | 29 | { | ||
2247 | 30 | Q_OBJECT | ||
2248 | 31 | public: | ||
2249 | 32 | explicit PrinterCupsBackend(IppClient *client, QPrinterInfo info, | ||
2250 | 33 | OrgCupsCupsdNotifierInterface* notifier, | ||
2251 | 34 | QObject *parent = Q_NULLPTR); | ||
2252 | 35 | virtual ~PrinterCupsBackend() override; | ||
2253 | 36 | |||
2254 | 37 | virtual bool holdsDefinition() const override; | ||
2255 | 38 | |||
2256 | 39 | virtual QString printerAdd(const QString &name, | ||
2257 | 40 | const QString &uri, | ||
2258 | 41 | const QString &ppdFile, | ||
2259 | 42 | const QString &info, | ||
2260 | 43 | const QString &location) override; | ||
2261 | 44 | virtual QString printerAddWithPpd(const QString &name, | ||
2262 | 45 | const QString &uri, | ||
2263 | 46 | const QString &ppdFileName, | ||
2264 | 47 | const QString &info, | ||
2265 | 48 | const QString &location) override; | ||
2266 | 49 | virtual QString printerDelete(const QString &name) override; | ||
2267 | 50 | virtual QString printerSetDefault(const QString &name) override; | ||
2268 | 51 | virtual QString printerSetEnabled(const QString &name, | ||
2269 | 52 | const bool enabled) override; | ||
2270 | 53 | virtual QString printerSetAcceptJobs( | ||
2271 | 54 | const QString &name, | ||
2272 | 55 | const bool accept, | ||
2273 | 56 | const QString &reason = QString::null) override; | ||
2274 | 57 | virtual QString printerSetInfo(const QString &name, | ||
2275 | 58 | const QString &info) override; | ||
2276 | 59 | virtual QString printerSetLocation(const QString &name, | ||
2277 | 60 | const QString &location) override; | ||
2278 | 61 | virtual QString printerSetShared(const QString &name, | ||
2279 | 62 | const bool shared) override; | ||
2280 | 63 | virtual QString printerSetJobSheets(const QString &name, | ||
2281 | 64 | const QString &start, | ||
2282 | 65 | const QString &end) override; | ||
2283 | 66 | virtual QString printerSetErrorPolicy(const QString &name, | ||
2284 | 67 | const PrinterEnum::ErrorPolicy &policy) override; | ||
2285 | 68 | |||
2286 | 69 | virtual QString printerSetOpPolicy(const QString &name, | ||
2287 | 70 | const PrinterEnum::OperationPolicy &policy) override; | ||
2288 | 71 | virtual QString printerSetUsersAllowed(const QString &name, | ||
2289 | 72 | const QStringList &users) override; | ||
2290 | 73 | virtual QString printerSetUsersDenied(const QString &name, | ||
2291 | 74 | const QStringList &users) override; | ||
2292 | 75 | virtual QString printerAddOptionDefault(const QString &name, | ||
2293 | 76 | const QString &option, | ||
2294 | 77 | const QStringList &values) override; | ||
2295 | 78 | virtual QString printerDeleteOptionDefault(const QString &name, | ||
2296 | 79 | const QString &value) override; | ||
2297 | 80 | virtual QString printerAddOption(const QString &name, | ||
2298 | 81 | const QString &option, | ||
2299 | 82 | const QStringList &values) override; | ||
2300 | 83 | |||
2301 | 84 | virtual QVariant printerGetOption(const QString &name, | ||
2302 | 85 | const QString &option) const override; | ||
2303 | 86 | virtual QMap<QString, QVariant> printerGetOptions( | ||
2304 | 87 | const QString &name, const QStringList &options | ||
2305 | 88 | ) const override; | ||
2306 | 89 | // FIXME: maybe have a PrinterDest iface that has a CupsDest impl? | ||
2307 | 90 | virtual cups_dest_t* makeDest(const QString &name, | ||
2308 | 91 | const PrinterJob *options) override; | ||
2309 | 92 | |||
2310 | 93 | virtual void cancelJob(const QString &name, const int jobId) override; | ||
2311 | 94 | virtual int printFileToDest(const QString &filepath, | ||
2312 | 95 | const QString &title, | ||
2313 | 96 | const cups_dest_t *dest) override; | ||
2314 | 97 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs() override; | ||
2315 | 98 | |||
2316 | 99 | virtual QString printerName() const override; | ||
2317 | 100 | virtual QString description() const override; | ||
2318 | 101 | virtual QString location() const override; | ||
2319 | 102 | virtual QString makeAndModel() const override; | ||
2320 | 103 | |||
2321 | 104 | virtual PrinterEnum::State state() const override; | ||
2322 | 105 | virtual QList<QPageSize> supportedPageSizes() const override; | ||
2323 | 106 | virtual QPageSize defaultPageSize() const override; | ||
2324 | 107 | virtual bool supportsCustomPageSizes() const override; | ||
2325 | 108 | |||
2326 | 109 | virtual QPageSize minimumPhysicalPageSize() const override; | ||
2327 | 110 | virtual QPageSize maximumPhysicalPageSize() const override; | ||
2328 | 111 | virtual QList<int> supportedResolutions() const override; | ||
2329 | 112 | virtual PrinterEnum::DuplexMode defaultDuplexMode() const override; | ||
2330 | 113 | virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override; | ||
2331 | 114 | |||
2332 | 115 | virtual QList<QSharedPointer<Printer>> availablePrinters() override; | ||
2333 | 116 | virtual QStringList availablePrinterNames() override; | ||
2334 | 117 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName) override; | ||
2335 | 118 | virtual QString defaultPrinterName() override; | ||
2336 | 119 | virtual void requestPrinterDrivers() override; | ||
2337 | 120 | virtual void requestPrinter(const QString &printerName) override; | ||
2338 | 121 | virtual QMap<QString, QVariant> printerGetJobAttributes( | ||
2339 | 122 | const QString &name, const int jobId) override; | ||
2340 | 123 | |||
2341 | 124 | public Q_SLOTS: | ||
2342 | 125 | virtual void refresh() override; | ||
2343 | 126 | void createSubscription(); | ||
2344 | 127 | |||
2345 | 128 | Q_SIGNALS: | ||
2346 | 129 | void cancelWorkers(); | ||
2347 | 130 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); | ||
2348 | 131 | void printerDriversFailedToLoad(const QString &errorMessage); | ||
2349 | 132 | void requestPrinterDriverCancel(); | ||
2350 | 133 | |||
2351 | 134 | private: | ||
2352 | 135 | void cancelSubscription(); | ||
2353 | 136 | void cancelPrinterDriverRequest(); | ||
2354 | 137 | QList<cups_job_t *> getCupsJobs(const QString &name = QStringLiteral()); | ||
2355 | 138 | |||
2356 | 139 | QString getPrinterName(const QString &name) const; | ||
2357 | 140 | QString getPrinterInstance(const QString &name) const; | ||
2358 | 141 | cups_dest_t* getDest(const QString &name) const; | ||
2359 | 142 | ppd_file_t* getPpd(const QString &name) const; | ||
2360 | 143 | const QStringList m_knownQualityOptions; | ||
2361 | 144 | IppClient *m_client; | ||
2362 | 145 | QPrinterInfo m_info; | ||
2363 | 146 | OrgCupsCupsdNotifierInterface *m_notifier; | ||
2364 | 147 | int m_cupsSubscriptionId; | ||
2365 | 148 | mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest. | ||
2366 | 149 | mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd. | ||
2367 | 150 | }; | ||
2368 | 151 | |||
2369 | 152 | #endif // USC_PRINTERS_CUPS_BACKEND_H | ||
2370 | 0 | 153 | ||
2371 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp' | |||
2372 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 1970-01-01 00:00:00 +0000 | |||
2373 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-02-22 12:44:26 +0000 | |||
2374 | @@ -0,0 +1,119 @@ | |||
2375 | 1 | /* | ||
2376 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2377 | 3 | * | ||
2378 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2379 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
2380 | 6 | * the Free Software Foundation; version 3. | ||
2381 | 7 | * | ||
2382 | 8 | * This program is distributed in the hope that it will be useful, | ||
2383 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2384 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2385 | 11 | * GNU Lesser General Public License for more details. | ||
2386 | 12 | * | ||
2387 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2388 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2389 | 15 | */ | ||
2390 | 16 | |||
2391 | 17 | #include "i18n.h" | ||
2392 | 18 | #include "backend/backend_pdf.h" | ||
2393 | 19 | |||
2394 | 20 | PrinterPdfBackend::PrinterPdfBackend(const QString &printerName, | ||
2395 | 21 | QObject *parent) | ||
2396 | 22 | : PrinterBackend(printerName, parent) | ||
2397 | 23 | { | ||
2398 | 24 | m_type = PrinterEnum::PrinterType::PdfType; | ||
2399 | 25 | } | ||
2400 | 26 | |||
2401 | 27 | QVariant PrinterPdfBackend::printerGetOption(const QString &name, | ||
2402 | 28 | const QString &option) const | ||
2403 | 29 | { | ||
2404 | 30 | auto res = printerGetOptions(name, QStringList({option})); | ||
2405 | 31 | return res[option]; | ||
2406 | 32 | } | ||
2407 | 33 | |||
2408 | 34 | QMap<QString, QVariant> PrinterPdfBackend::printerGetOptions( | ||
2409 | 35 | const QString &name, const QStringList &options) const | ||
2410 | 36 | { | ||
2411 | 37 | Q_UNUSED(name); | ||
2412 | 38 | |||
2413 | 39 | QMap<QString, QVariant> ret; | ||
2414 | 40 | |||
2415 | 41 | ColorModel rgb; | ||
2416 | 42 | rgb.colorType = PrinterEnum::ColorModelType::ColorType; | ||
2417 | 43 | rgb.name = "RGB"; | ||
2418 | 44 | rgb.text = __("Color"); | ||
2419 | 45 | |||
2420 | 46 | PrintQuality quality; | ||
2421 | 47 | quality.name = __("Normal"); | ||
2422 | 48 | |||
2423 | 49 | Q_FOREACH(const QString &option, options) { | ||
2424 | 50 | if (option == QLatin1String("DefaultColorModel")) { | ||
2425 | 51 | ret[option] = QVariant::fromValue(rgb); | ||
2426 | 52 | } else if (option == QLatin1String("DefaultPrintQuality")) { | ||
2427 | 53 | ret[option] = QVariant::fromValue(quality); | ||
2428 | 54 | } else if (option == QLatin1String("SupportedPrintQualities")) { | ||
2429 | 55 | auto qualities = QList<PrintQuality>({quality}); | ||
2430 | 56 | ret[option] = QVariant::fromValue(qualities); | ||
2431 | 57 | } else if (option == QLatin1String("SupportedColorModels")) { | ||
2432 | 58 | auto models = QList<ColorModel>{rgb}; | ||
2433 | 59 | ret[option] = QVariant::fromValue(models); | ||
2434 | 60 | } else if (option == QLatin1String("AcceptJobs")) { | ||
2435 | 61 | ret[option] = true; | ||
2436 | 62 | } else { | ||
2437 | 63 | throw std::invalid_argument("Invalid value for PDF printer: " + option.toStdString()); | ||
2438 | 64 | } | ||
2439 | 65 | } | ||
2440 | 66 | |||
2441 | 67 | return ret; | ||
2442 | 68 | } | ||
2443 | 69 | |||
2444 | 70 | QString PrinterPdfBackend::printerName() const | ||
2445 | 71 | { | ||
2446 | 72 | return m_printerName; | ||
2447 | 73 | } | ||
2448 | 74 | |||
2449 | 75 | PrinterEnum::State PrinterPdfBackend::state() const | ||
2450 | 76 | { | ||
2451 | 77 | return PrinterEnum::State::IdleState; | ||
2452 | 78 | } | ||
2453 | 79 | |||
2454 | 80 | QList<QPageSize> PrinterPdfBackend::supportedPageSizes() const | ||
2455 | 81 | { | ||
2456 | 82 | return QList<QPageSize>{QPageSize(QPageSize::A4)}; | ||
2457 | 83 | } | ||
2458 | 84 | |||
2459 | 85 | QPageSize PrinterPdfBackend::defaultPageSize() const | ||
2460 | 86 | { | ||
2461 | 87 | return QPageSize(QPageSize::A4); | ||
2462 | 88 | } | ||
2463 | 89 | |||
2464 | 90 | bool PrinterPdfBackend::supportsCustomPageSizes() const | ||
2465 | 91 | { | ||
2466 | 92 | return false; | ||
2467 | 93 | } | ||
2468 | 94 | |||
2469 | 95 | QPageSize PrinterPdfBackend::minimumPhysicalPageSize() const | ||
2470 | 96 | { | ||
2471 | 97 | return QPageSize(QPageSize::A4); | ||
2472 | 98 | } | ||
2473 | 99 | |||
2474 | 100 | QPageSize PrinterPdfBackend::maximumPhysicalPageSize() const | ||
2475 | 101 | { | ||
2476 | 102 | return QPageSize(QPageSize::A4); | ||
2477 | 103 | } | ||
2478 | 104 | |||
2479 | 105 | QList<int> PrinterPdfBackend::supportedResolutions() const | ||
2480 | 106 | { | ||
2481 | 107 | return QList<int>{}; | ||
2482 | 108 | } | ||
2483 | 109 | |||
2484 | 110 | PrinterEnum::DuplexMode PrinterPdfBackend::defaultDuplexMode() const | ||
2485 | 111 | { | ||
2486 | 112 | return PrinterEnum::DuplexMode::DuplexNone; | ||
2487 | 113 | } | ||
2488 | 114 | |||
2489 | 115 | QList<PrinterEnum::DuplexMode> PrinterPdfBackend::supportedDuplexModes() const | ||
2490 | 116 | { | ||
2491 | 117 | return QList<PrinterEnum::DuplexMode>{PrinterEnum::DuplexMode::DuplexNone}; | ||
2492 | 118 | } | ||
2493 | 119 | |||
2494 | 0 | 120 | ||
2495 | === added file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.h' | |||
2496 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.h 1970-01-01 00:00:00 +0000 | |||
2497 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.h 2017-02-22 12:44:26 +0000 | |||
2498 | @@ -0,0 +1,47 @@ | |||
2499 | 1 | /* | ||
2500 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2501 | 3 | * | ||
2502 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2503 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
2504 | 6 | * the Free Software Foundation; version 3. | ||
2505 | 7 | * | ||
2506 | 8 | * This program is distributed in the hope that it will be useful, | ||
2507 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2508 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2509 | 11 | * GNU Lesser General Public License for more details. | ||
2510 | 12 | * | ||
2511 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2512 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2513 | 15 | */ | ||
2514 | 16 | |||
2515 | 17 | #ifndef USC_PRINTERS_PDF_BACKEND_H | ||
2516 | 18 | #define USC_PRINTERS_PDF_BACKEND_H | ||
2517 | 19 | |||
2518 | 20 | #include "backend/backend.h" | ||
2519 | 21 | |||
2520 | 22 | class PRINTERS_DECL_EXPORT PrinterPdfBackend : public PrinterBackend | ||
2521 | 23 | { | ||
2522 | 24 | public: | ||
2523 | 25 | explicit PrinterPdfBackend(const QString &printerName, | ||
2524 | 26 | QObject *parent = Q_NULLPTR); | ||
2525 | 27 | virtual QVariant printerGetOption(const QString &name, | ||
2526 | 28 | const QString &option) const override; | ||
2527 | 29 | virtual QMap<QString, QVariant> printerGetOptions( | ||
2528 | 30 | const QString &name, const QStringList &options | ||
2529 | 31 | ) const override; | ||
2530 | 32 | |||
2531 | 33 | virtual QString printerName() const override; | ||
2532 | 34 | |||
2533 | 35 | virtual PrinterEnum::State state() const override; | ||
2534 | 36 | virtual QList<QPageSize> supportedPageSizes() const override; | ||
2535 | 37 | virtual QPageSize defaultPageSize() const override; | ||
2536 | 38 | virtual bool supportsCustomPageSizes() const override; | ||
2537 | 39 | |||
2538 | 40 | virtual QPageSize minimumPhysicalPageSize() const override; | ||
2539 | 41 | virtual QPageSize maximumPhysicalPageSize() const override; | ||
2540 | 42 | virtual QList<int> supportedResolutions() const override; | ||
2541 | 43 | virtual PrinterEnum::DuplexMode defaultDuplexMode() const override; | ||
2542 | 44 | virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override; | ||
2543 | 45 | }; | ||
2544 | 46 | |||
2545 | 47 | #endif // USC_PRINTERS_PDF_BACKEND_H | ||
2546 | 0 | 48 | ||
2547 | === added directory 'modules/Ubuntu/Components/Extras/Printers/cups' | |||
2548 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp' | |||
2549 | --- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 1970-01-01 00:00:00 +0000 | |||
2550 | +++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-02-22 12:44:26 +0000 | |||
2551 | @@ -0,0 +1,988 @@ | |||
2552 | 1 | /* | ||
2553 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2554 | 3 | * Copyright (C) 2014 John Layt <jlayt@kde.org> | ||
2555 | 4 | * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 Red Hat, Inc. | ||
2556 | 5 | * Copyright (C) 2008 Novell, Inc. | ||
2557 | 6 | * | ||
2558 | 7 | * This program is free software; you can redistribute it and/or modify | ||
2559 | 8 | * it under the terms of the GNU Lesser General Public License as published by | ||
2560 | 9 | * the Free Software Foundation; version 3. | ||
2561 | 10 | * | ||
2562 | 11 | * This program is distributed in the hope that it will be useful, | ||
2563 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2564 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2565 | 14 | * GNU Lesser General Public License for more details. | ||
2566 | 15 | * | ||
2567 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
2568 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2569 | 18 | */ | ||
2570 | 19 | |||
2571 | 20 | #include "cups/ippclient.h" | ||
2572 | 21 | |||
2573 | 22 | #include <errno.h> | ||
2574 | 23 | #include <string.h> | ||
2575 | 24 | #include <unistd.h> | ||
2576 | 25 | |||
2577 | 26 | #include <QDebug> | ||
2578 | 27 | #include <QDateTime> | ||
2579 | 28 | #include <QTimeZone> | ||
2580 | 29 | #include <QUrl> | ||
2581 | 30 | |||
2582 | 31 | IppClient::IppClient() | ||
2583 | 32 | : m_connection(httpConnectEncrypt(cupsServer(), | ||
2584 | 33 | ippPort(), | ||
2585 | 34 | cupsEncryption())) | ||
2586 | 35 | { | ||
2587 | 36 | if (!m_connection) { | ||
2588 | 37 | qCritical("Failed to connect to cupsd"); | ||
2589 | 38 | } else { | ||
2590 | 39 | qDebug("Successfully connected to cupsd."); | ||
2591 | 40 | } | ||
2592 | 41 | } | ||
2593 | 42 | |||
2594 | 43 | IppClient::~IppClient() | ||
2595 | 44 | { | ||
2596 | 45 | if (m_connection) | ||
2597 | 46 | httpClose(m_connection); | ||
2598 | 47 | } | ||
2599 | 48 | |||
2600 | 49 | bool IppClient::printerDelete(const QString &printerName) | ||
2601 | 50 | { | ||
2602 | 51 | return sendNewSimpleRequest(CUPS_DELETE_PRINTER, printerName.toUtf8(), | ||
2603 | 52 | CupsResource::CupsResourceAdmin); | ||
2604 | 53 | } | ||
2605 | 54 | |||
2606 | 55 | bool IppClient::printerAdd(const QString &printerName, | ||
2607 | 56 | const QString &printerUri, | ||
2608 | 57 | const QString &ppdFile, | ||
2609 | 58 | const QString &info, | ||
2610 | 59 | const QString &location) | ||
2611 | 60 | { | ||
2612 | 61 | ipp_t *request; | ||
2613 | 62 | |||
2614 | 63 | if (!isPrinterNameValid(printerName)) { | ||
2615 | 64 | setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName)); | ||
2616 | 65 | return false; | ||
2617 | 66 | } | ||
2618 | 67 | |||
2619 | 68 | if (!isStringValid(info)) { | ||
2620 | 69 | setInternalStatus(QString("%1 is not a valid description.").arg(info)); | ||
2621 | 70 | return false; | ||
2622 | 71 | } | ||
2623 | 72 | |||
2624 | 73 | if (!isStringValid(location)) { | ||
2625 | 74 | setInternalStatus(QString("%1 is not a valid location.").arg(location)); | ||
2626 | 75 | return false; | ||
2627 | 76 | } | ||
2628 | 77 | |||
2629 | 78 | if (!isStringValid(ppdFile)) { | ||
2630 | 79 | setInternalStatus(QString("%1 is not a valid ppd file.").arg(ppdFile)); | ||
2631 | 80 | return false; | ||
2632 | 81 | } | ||
2633 | 82 | |||
2634 | 83 | if (!isStringValid(printerUri)) { | ||
2635 | 84 | setInternalStatus(QString("%1 is not a valid printer uri.").arg(printerUri)); | ||
2636 | 85 | return false; | ||
2637 | 86 | } | ||
2638 | 87 | |||
2639 | 88 | |||
2640 | 89 | request = ippNewRequest (CUPS_ADD_MODIFY_PRINTER); | ||
2641 | 90 | addPrinterUri(request, printerName); | ||
2642 | 91 | addRequestingUsername(request, NULL); | ||
2643 | 92 | |||
2644 | 93 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, | ||
2645 | 94 | "printer-name", NULL, printerName.toUtf8()); | ||
2646 | 95 | |||
2647 | 96 | if (!ppdFile.isEmpty()) { | ||
2648 | 97 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, | ||
2649 | 98 | "ppd-name", NULL, ppdFile.toUtf8()); | ||
2650 | 99 | } | ||
2651 | 100 | if (!printerUri.isEmpty()) { | ||
2652 | 101 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, | ||
2653 | 102 | "device-uri", NULL, printerUri.toUtf8()); | ||
2654 | 103 | } | ||
2655 | 104 | if (!info.isEmpty()) { | ||
2656 | 105 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, | ||
2657 | 106 | "printer-info", NULL, info.toUtf8()); | ||
2658 | 107 | } | ||
2659 | 108 | if (!location.isEmpty()) { | ||
2660 | 109 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, | ||
2661 | 110 | "printer-location", NULL, location.toUtf8()); | ||
2662 | 111 | } | ||
2663 | 112 | |||
2664 | 113 | return sendRequest(request, CupsResourceAdmin); | ||
2665 | 114 | } | ||
2666 | 115 | |||
2667 | 116 | bool IppClient::printerAddWithPpdFile(const QString &printerName, | ||
2668 | 117 | const QString &printerUri, | ||
2669 | 118 | const QString &ppdFileName, | ||
2670 | 119 | const QString &info, | ||
2671 | 120 | const QString &location) | ||
2672 | 121 | { | ||
2673 | 122 | ipp_t *request; | ||
2674 | 123 | |||
2675 | 124 | if (!isPrinterNameValid(printerName)) { | ||
2676 | 125 | setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName)); | ||
2677 | 126 | return false; | ||
2678 | 127 | } | ||
2679 | 128 | |||
2680 | 129 | if (!isStringValid(info)) { | ||
2681 | 130 | setInternalStatus(QString("%1 is not a valid description.").arg(info)); | ||
2682 | 131 | return false; | ||
2683 | 132 | } | ||
2684 | 133 | |||
2685 | 134 | if (!isStringValid(location)) { | ||
2686 | 135 | setInternalStatus(QString("%1 is not a valid location.").arg(location)); | ||
2687 | 136 | return false; | ||
2688 | 137 | } | ||
2689 | 138 | |||
2690 | 139 | if (!isStringValid(ppdFileName)) { | ||
2691 | 140 | setInternalStatus(QString("%1 is not a valid ppd file name.").arg(ppdFileName)); | ||
2692 | 141 | return false; | ||
2693 | 142 | } | ||
2694 | 143 | |||
2695 | 144 | if (!isStringValid(printerUri)) { | ||
2696 | 145 | setInternalStatus(QString("%1 is not a valid printer uri.").arg(printerUri)); | ||
2697 | 146 | return false; | ||
2698 | 147 | } | ||
2699 | 148 | |||
2700 | 149 | request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER); | ||
2701 | 150 | addPrinterUri(request, printerName); | ||
2702 | 151 | addRequestingUsername(request, NULL); | ||
2703 | 152 | |||
2704 | 153 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, | ||
2705 | 154 | "printer-name", NULL, printerName.toUtf8()); | ||
2706 | 155 | |||
2707 | 156 | /* In this specific case of ADD_MODIFY, the URI can be NULL/empty since | ||
2708 | 157 | * we provide a complete PPD. And cups fails if we pass an empty | ||
2709 | 158 | * string. */ | ||
2710 | 159 | if (!printerUri.isEmpty()) { | ||
2711 | 160 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, | ||
2712 | 161 | "device-uri", NULL, printerUri.toUtf8()); | ||
2713 | 162 | } | ||
2714 | 163 | |||
2715 | 164 | if (!info.isEmpty()) { | ||
2716 | 165 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, | ||
2717 | 166 | "printer-info", NULL, info.toUtf8()); | ||
2718 | 167 | } | ||
2719 | 168 | if (!location.isEmpty()) { | ||
2720 | 169 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_TEXT, | ||
2721 | 170 | "printer-location", NULL, location.toUtf8()); | ||
2722 | 171 | } | ||
2723 | 172 | |||
2724 | 173 | return postRequest(request, ppdFileName.toUtf8(), CupsResourceAdmin); | ||
2725 | 174 | } | ||
2726 | 175 | |||
2727 | 176 | bool IppClient::printerSetDefault(const QString &printerName) | ||
2728 | 177 | { | ||
2729 | 178 | return sendNewSimpleRequest(CUPS_SET_DEFAULT, printerName.toUtf8(), | ||
2730 | 179 | CupsResource::CupsResourceAdmin); | ||
2731 | 180 | } | ||
2732 | 181 | |||
2733 | 182 | bool IppClient::printerSetEnabled(const QString &printerName, | ||
2734 | 183 | const bool enabled) | ||
2735 | 184 | { | ||
2736 | 185 | ipp_op_t op; | ||
2737 | 186 | op = enabled ? IPP_RESUME_PRINTER : IPP_PAUSE_PRINTER; | ||
2738 | 187 | return sendNewSimpleRequest(op, printerName, CupsResourceAdmin); | ||
2739 | 188 | } | ||
2740 | 189 | |||
2741 | 190 | /* reason must be empty if accept is true */ | ||
2742 | 191 | bool IppClient::printerSetAcceptJobs(const QString &printerName, | ||
2743 | 192 | const bool accept, | ||
2744 | 193 | const QString &reason) | ||
2745 | 194 | { | ||
2746 | 195 | ipp_t *request; | ||
2747 | 196 | |||
2748 | 197 | if (accept && !reason.isEmpty()) { | ||
2749 | 198 | setInternalStatus("Accepting jobs does not take a reason."); | ||
2750 | 199 | return false; | ||
2751 | 200 | } | ||
2752 | 201 | |||
2753 | 202 | if (!isPrinterNameValid(printerName)) { | ||
2754 | 203 | setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName)); | ||
2755 | 204 | return false; | ||
2756 | 205 | } | ||
2757 | 206 | |||
2758 | 207 | if (!isStringValid(reason)) { | ||
2759 | 208 | setInternalStatus(QString("%1 is not a valid reason.").arg(reason)); | ||
2760 | 209 | return false; | ||
2761 | 210 | } | ||
2762 | 211 | |||
2763 | 212 | if (accept) { | ||
2764 | 213 | return sendNewSimpleRequest(CUPS_ACCEPT_JOBS, printerName.toUtf8(), | ||
2765 | 214 | CupsResourceAdmin); | ||
2766 | 215 | } else { | ||
2767 | 216 | request = ippNewRequest(CUPS_REJECT_JOBS); | ||
2768 | 217 | addPrinterUri(request, printerName); | ||
2769 | 218 | addRequestingUsername(request, NULL); | ||
2770 | 219 | |||
2771 | 220 | if (!reason.isEmpty()) | ||
2772 | 221 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT, | ||
2773 | 222 | "printer-state-message", NULL, reason.toUtf8()); | ||
2774 | 223 | |||
2775 | 224 | return sendRequest(request, CupsResourceAdmin); | ||
2776 | 225 | } | ||
2777 | 226 | } | ||
2778 | 227 | |||
2779 | 228 | |||
2780 | 229 | bool IppClient::printerClassSetInfo(const QString &name, | ||
2781 | 230 | const QString &info) | ||
2782 | 231 | { | ||
2783 | 232 | if (!isPrinterNameValid(name)) { | ||
2784 | 233 | setInternalStatus(QString("%1 is not a valid printer name.").arg(name)); | ||
2785 | 234 | return false; | ||
2786 | 235 | } | ||
2787 | 236 | |||
2788 | 237 | if (!isStringValid(info)) { | ||
2789 | 238 | setInternalStatus(QString("%1 is not a valid description.").arg(info)); | ||
2790 | 239 | return false; | ||
2791 | 240 | } | ||
2792 | 241 | |||
2793 | 242 | return sendNewPrinterClassRequest(name, IPP_TAG_PRINTER, IPP_TAG_TEXT, | ||
2794 | 243 | "printer-info", info); | ||
2795 | 244 | } | ||
2796 | 245 | |||
2797 | 246 | bool IppClient::printerClassSetOption(const QString &name, | ||
2798 | 247 | const QString &option, | ||
2799 | 248 | const QStringList &values) | ||
2800 | 249 | { | ||
2801 | 250 | bool isClass; | ||
2802 | 251 | int length = 0; | ||
2803 | 252 | ipp_t *request; | ||
2804 | 253 | ipp_attribute_t *attr; | ||
2805 | 254 | QString newPpdFile; | ||
2806 | 255 | bool retval; | ||
2807 | 256 | |||
2808 | 257 | if (!isPrinterNameValid(name)) { | ||
2809 | 258 | setInternalStatus(QString("%1 is not a valid printer name.").arg(name)); | ||
2810 | 259 | return false; | ||
2811 | 260 | } | ||
2812 | 261 | |||
2813 | 262 | if (!isStringValid(option)) { | ||
2814 | 263 | setInternalStatus(QString("%1 is not a valid option.").arg(option)); | ||
2815 | 264 | return false; | ||
2816 | 265 | } | ||
2817 | 266 | |||
2818 | 267 | Q_FOREACH(const QString &val, values) { | ||
2819 | 268 | if (!isStringValid(val)) { | ||
2820 | 269 | setInternalStatus(QString("%1 is not a valid value.").arg(val)); | ||
2821 | 270 | return false; | ||
2822 | 271 | } | ||
2823 | 272 | length++; | ||
2824 | 273 | } | ||
2825 | 274 | |||
2826 | 275 | if (length == 0) { | ||
2827 | 276 | setInternalStatus("No valid values."); | ||
2828 | 277 | return false; | ||
2829 | 278 | } | ||
2830 | 279 | |||
2831 | 280 | isClass = printerIsClass(name); | ||
2832 | 281 | |||
2833 | 282 | /* We permit only one value to change in PPD file because we are setting | ||
2834 | 283 | * default value in it. */ | ||
2835 | 284 | if (!isClass && length == 1) { | ||
2836 | 285 | cups_option_t *options = NULL; | ||
2837 | 286 | int numOptions = 0; | ||
2838 | 287 | QString ppdfile; | ||
2839 | 288 | |||
2840 | 289 | numOptions = cupsAddOption(option.toUtf8(), | ||
2841 | 290 | values[0].toUtf8(), | ||
2842 | 291 | numOptions, &options); | ||
2843 | 292 | |||
2844 | 293 | ppdfile = QString(cupsGetPPD(name.toUtf8())); | ||
2845 | 294 | |||
2846 | 295 | newPpdFile = preparePpdForOptions(ppdfile.toUtf8(), | ||
2847 | 296 | options, numOptions).toLatin1().data(); | ||
2848 | 297 | |||
2849 | 298 | unlink(ppdfile.toUtf8()); | ||
2850 | 299 | cupsFreeOptions(numOptions, options); | ||
2851 | 300 | } | ||
2852 | 301 | |||
2853 | 302 | if (isClass) { | ||
2854 | 303 | request = ippNewRequest(CUPS_ADD_MODIFY_CLASS); | ||
2855 | 304 | addClassUri(request, name); | ||
2856 | 305 | } else { | ||
2857 | 306 | request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER); | ||
2858 | 307 | addPrinterUri(request, name); | ||
2859 | 308 | } | ||
2860 | 309 | |||
2861 | 310 | addRequestingUsername(request, NULL); | ||
2862 | 311 | |||
2863 | 312 | if (length == 1) { | ||
2864 | 313 | ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, | ||
2865 | 314 | option.toUtf8(), | ||
2866 | 315 | NULL, | ||
2867 | 316 | values[0].toUtf8()); | ||
2868 | 317 | } else { | ||
2869 | 318 | int i; | ||
2870 | 319 | |||
2871 | 320 | attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_NAME, | ||
2872 | 321 | option.toUtf8(), length, NULL, NULL); | ||
2873 | 322 | |||
2874 | 323 | for (i = 0; i < length; i++) | ||
2875 | 324 | ippSetString(request, &attr, i, values[i].toUtf8()); | ||
2876 | 325 | } | ||
2877 | 326 | |||
2878 | 327 | if (!newPpdFile.isEmpty()) { | ||
2879 | 328 | retval = postRequest(request, newPpdFile, CupsResourceAdmin); | ||
2880 | 329 | |||
2881 | 330 | unlink(newPpdFile.toUtf8()); | ||
2882 | 331 | // TODO: fix leak here. | ||
2883 | 332 | } else { | ||
2884 | 333 | retval = sendRequest(request, CupsResourceAdmin); | ||
2885 | 334 | } | ||
2886 | 335 | |||
2887 | 336 | return retval; | ||
2888 | 337 | } | ||
2889 | 338 | |||
2890 | 339 | QMap<QString, QVariant> IppClient::printerGetJobAttributes(const int jobId) | ||
2891 | 340 | { | ||
2892 | 341 | ipp_t *request; | ||
2893 | 342 | QMap<QString, QVariant> map; | ||
2894 | 343 | |||
2895 | 344 | // Construct request | ||
2896 | 345 | request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES); | ||
2897 | 346 | QString uri = QStringLiteral("ipp://localhost/jobs/") + QString::number(jobId); | ||
2898 | 347 | qDebug() << "URI:" << uri; | ||
2899 | 348 | |||
2900 | 349 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri.toStdString().data()); | ||
2901 | 350 | |||
2902 | 351 | |||
2903 | 352 | // Send request and construct reply | ||
2904 | 353 | ipp_t *reply; | ||
2905 | 354 | const QString resourceChar = getResource(CupsResourceRoot); | ||
2906 | 355 | reply = cupsDoRequest(m_connection, request, | ||
2907 | 356 | resourceChar.toUtf8()); | ||
2908 | 357 | |||
2909 | 358 | // Check if the reply is OK | ||
2910 | 359 | if (isReplyOk(reply, false)) { | ||
2911 | 360 | // Loop through the attributes | ||
2912 | 361 | ipp_attribute_t *attr; | ||
2913 | 362 | |||
2914 | 363 | for (attr = ippFirstAttribute(reply); attr; attr = ippNextAttribute(reply)) { | ||
2915 | 364 | QVariant value = getAttributeValue(attr); | ||
2916 | 365 | map.insert(ippGetName(attr), value); | ||
2917 | 366 | } | ||
2918 | 367 | } else { | ||
2919 | 368 | qWarning() << "Not able to get attributes of job:" << jobId; | ||
2920 | 369 | } | ||
2921 | 370 | |||
2922 | 371 | // Destruct the reply if valid | ||
2923 | 372 | if (reply) { | ||
2924 | 373 | ippDelete(reply); | ||
2925 | 374 | } | ||
2926 | 375 | |||
2927 | 376 | return map; | ||
2928 | 377 | } | ||
2929 | 378 | |||
2930 | 379 | |||
2931 | 380 | /* This function sets given options to specified values in file 'ppdfile'. | ||
2932 | 381 | * This needs to be done because of applications which use content of PPD files | ||
2933 | 382 | * instead of IPP attributes. | ||
2934 | 383 | * CUPS doesn't do this automatically (but hopefully will starting with 1.6) */ | ||
2935 | 384 | QString IppClient::preparePpdForOptions(const QString &ppdfile, | ||
2936 | 385 | cups_option_t *options, int numOptions) | ||
2937 | 386 | { | ||
2938 | 387 | auto ppdfile_c = ppdfile.toUtf8(); | ||
2939 | 388 | ppd_file_t *ppd; | ||
2940 | 389 | bool ppdchanged = false; | ||
2941 | 390 | QString result; | ||
2942 | 391 | QString error; | ||
2943 | 392 | char newppdfile[PATH_MAX]; | ||
2944 | 393 | cups_file_t *in = NULL; | ||
2945 | 394 | cups_file_t *out = NULL; | ||
2946 | 395 | char line[CPH_STR_MAXLEN]; | ||
2947 | 396 | char keyword[CPH_STR_MAXLEN]; | ||
2948 | 397 | char *keyptr; | ||
2949 | 398 | ppd_choice_t *choice; | ||
2950 | 399 | QString value; | ||
2951 | 400 | QLatin1String defaultStr("*Default"); | ||
2952 | 401 | |||
2953 | 402 | ppd = ppdOpenFile(ppdfile_c); | ||
2954 | 403 | if (!ppd) { | ||
2955 | 404 | error = QString("Unable to open PPD file \"%1\": %2") | ||
2956 | 405 | .arg(ppdfile).arg(strerror(errno)); | ||
2957 | 406 | setInternalStatus(error); | ||
2958 | 407 | goto out; | ||
2959 | 408 | } | ||
2960 | 409 | |||
2961 | 410 | in = cupsFileOpen(ppdfile_c, "r"); | ||
2962 | 411 | if (!in) { | ||
2963 | 412 | error = QString("Unable to open PPD file \"%1\": %2") | ||
2964 | 413 | .arg(ppdfile).arg(strerror(errno)); | ||
2965 | 414 | setInternalStatus(error); | ||
2966 | 415 | goto out; | ||
2967 | 416 | } | ||
2968 | 417 | |||
2969 | 418 | out = cupsTempFile2(newppdfile, sizeof(newppdfile)); | ||
2970 | 419 | if (!out) { | ||
2971 | 420 | setInternalStatus("Unable to create temporary file"); | ||
2972 | 421 | goto out; | ||
2973 | 422 | } | ||
2974 | 423 | |||
2975 | 424 | /* Mark default values and values of options we are changing. */ | ||
2976 | 425 | ppdMarkDefaults(ppd); | ||
2977 | 426 | cupsMarkOptions(ppd, numOptions, options); | ||
2978 | 427 | |||
2979 | 428 | while (cupsFileGets(in, line, sizeof(line))) { | ||
2980 | 429 | QString line_qs(line); | ||
2981 | 430 | if (!line_qs.startsWith(defaultStr)) { | ||
2982 | 431 | cupsFilePrintf(out, "%s\n", line); | ||
2983 | 432 | } else { | ||
2984 | 433 | /* This part parses lines with *Default on their | ||
2985 | 434 | * beginning. For instance: | ||
2986 | 435 | * "*DefaultResolution: 1200dpi" becomes: | ||
2987 | 436 | * - keyword: Resolution | ||
2988 | 437 | * - keyptr: 1200dpi | ||
2989 | 438 | */ | ||
2990 | 439 | strncpy(keyword, line + defaultStr.size(), sizeof(keyword)); | ||
2991 | 440 | |||
2992 | 441 | for (keyptr = keyword; *keyptr; keyptr++) | ||
2993 | 442 | if (*keyptr == ':' || isspace (*keyptr & 255)) | ||
2994 | 443 | break; | ||
2995 | 444 | |||
2996 | 445 | *keyptr++ = '\0'; | ||
2997 | 446 | while (isspace (*keyptr & 255)) | ||
2998 | 447 | keyptr++; | ||
2999 | 448 | |||
3000 | 449 | QString keyword_sq(keyword); | ||
3001 | 450 | QString keyptr_qs(keyptr); | ||
3002 | 451 | |||
3003 | 452 | /* We have to change PageSize if any of PageRegion, | ||
3004 | 453 | * PageSize, PaperDimension or ImageableArea changes. | ||
3005 | 454 | * We change PageRegion if PageSize is not available. */ | ||
3006 | 455 | if (keyword_sq == "PageRegion" || | ||
3007 | 456 | keyword_sq == "PageSize" || | ||
3008 | 457 | keyword_sq == "PaperDimension" || | ||
3009 | 458 | keyword_sq == "ImageableArea") { | ||
3010 | 459 | |||
3011 | 460 | choice = ppdFindMarkedChoice(ppd, "PageSize"); | ||
3012 | 461 | if (!choice) | ||
3013 | 462 | choice = ppdFindMarkedChoice(ppd, "PageRegion"); | ||
3014 | 463 | } else { | ||
3015 | 464 | choice = ppdFindMarkedChoice(ppd, keyword); | ||
3016 | 465 | } | ||
3017 | 466 | |||
3018 | 467 | |||
3019 | 468 | QString choice_qs; | ||
3020 | 469 | if (choice) { | ||
3021 | 470 | choice_qs = choice->choice; | ||
3022 | 471 | } | ||
3023 | 472 | |||
3024 | 473 | if (choice && choice_qs != keyptr_qs) { | ||
3025 | 474 | /* We have to set the value in PPD manually if | ||
3026 | 475 | * a custom value was passed in: | ||
3027 | 476 | * cupsMarkOptions() marks the choice as | ||
3028 | 477 | * "Custom". We want to set this value with our | ||
3029 | 478 | * input. */ | ||
3030 | 479 | if (choice_qs != "Custom") { | ||
3031 | 480 | cupsFilePrintf(out, | ||
3032 | 481 | "*Default%s: %s\n", | ||
3033 | 482 | keyword, | ||
3034 | 483 | choice->choice); | ||
3035 | 484 | ppdchanged = true; | ||
3036 | 485 | } else { | ||
3037 | 486 | value = cupsGetOption(keyword, numOptions, options); | ||
3038 | 487 | if (!value.isEmpty()) { | ||
3039 | 488 | cupsFilePrintf(out, | ||
3040 | 489 | "*Default%s: %s\n", | ||
3041 | 490 | keyword, | ||
3042 | 491 | value.toStdString().c_str()); | ||
3043 | 492 | ppdchanged = true; | ||
3044 | 493 | } else { | ||
3045 | 494 | cupsFilePrintf(out, "%s\n", line); | ||
3046 | 495 | } | ||
3047 | 496 | } | ||
3048 | 497 | } else { | ||
3049 | 498 | cupsFilePrintf(out, "%s\n", line); | ||
3050 | 499 | } | ||
3051 | 500 | } | ||
3052 | 501 | } | ||
3053 | 502 | |||
3054 | 503 | if (ppdchanged) | ||
3055 | 504 | result = QString::fromUtf8(newppdfile); | ||
3056 | 505 | else | ||
3057 | 506 | unlink(newppdfile); | ||
3058 | 507 | |||
3059 | 508 | out: | ||
3060 | 509 | if (in) | ||
3061 | 510 | cupsFileClose(in); | ||
3062 | 511 | if (out) | ||
3063 | 512 | cupsFileClose(out); | ||
3064 | 513 | if (ppd) | ||
3065 | 514 | ppdClose(ppd); | ||
3066 | 515 | |||
3067 | 516 | return result; | ||
3068 | 517 | } | ||
3069 | 518 | |||
3070 | 519 | |||
3071 | 520 | bool IppClient::sendNewPrinterClassRequest(const QString &printerName, | ||
3072 | 521 | ipp_tag_t group, ipp_tag_t type, | ||
3073 | 522 | const QString &name, | ||
3074 | 523 | const QString &value) | ||
3075 | 524 | { | ||
3076 | 525 | ipp_t *request; | ||
3077 | 526 | |||
3078 | 527 | request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER); | ||
3079 | 528 | addPrinterUri(request, printerName); | ||
3080 | 529 | addRequestingUsername(request, QString()); | ||
3081 | 530 | ippAddString(request, group, type, name.toUtf8(), NULL, | ||
3082 | 531 | value.toUtf8()); | ||
3083 | 532 | |||
3084 | 533 | if (sendRequest(request, CupsResource::CupsResourceAdmin)) | ||
3085 | 534 | return true; | ||
3086 | 535 | |||
3087 | 536 | // it failed, maybe it was a class? | ||
3088 | 537 | if (m_lastStatus != IPP_NOT_POSSIBLE) { | ||
3089 | 538 | return false; | ||
3090 | 539 | } | ||
3091 | 540 | |||
3092 | 541 | // TODO: implement class modification <here>. | ||
3093 | 542 | return false; | ||
3094 | 543 | } | ||
3095 | 544 | |||
3096 | 545 | void IppClient::addPrinterUri(ipp_t *request, const QString &name) | ||
3097 | 546 | { | ||
3098 | 547 | QUrl uri(QString("ipp://localhost/printers/%1").arg(name)); | ||
3099 | 548 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | ||
3100 | 549 | "printer-uri", NULL, uri.toEncoded().data()); | ||
3101 | 550 | } | ||
3102 | 551 | |||
3103 | 552 | void IppClient::addRequestingUsername(ipp_t *request, const QString &username) | ||
3104 | 553 | { | ||
3105 | 554 | if (!username.isEmpty()) | ||
3106 | 555 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | ||
3107 | 556 | "requesting-user-name", NULL, | ||
3108 | 557 | username.toUtf8()); | ||
3109 | 558 | else | ||
3110 | 559 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | ||
3111 | 560 | "requesting-user-name", NULL, cupsUser()); | ||
3112 | 561 | } | ||
3113 | 562 | |||
3114 | 563 | QString IppClient::getLastError() const | ||
3115 | 564 | { | ||
3116 | 565 | return m_internalStatus; | ||
3117 | 566 | } | ||
3118 | 567 | |||
3119 | 568 | const QString IppClient::getResource(const IppClient::CupsResource &resource) | ||
3120 | 569 | { | ||
3121 | 570 | switch (resource) { | ||
3122 | 571 | case CupsResourceRoot: | ||
3123 | 572 | return "/"; | ||
3124 | 573 | case CupsResourceAdmin: | ||
3125 | 574 | return "/admin/"; | ||
3126 | 575 | case CupsResourceJobs: | ||
3127 | 576 | return "/jobs/"; | ||
3128 | 577 | default: | ||
3129 | 578 | qCritical("Asking for a resource with no match."); | ||
3130 | 579 | return "/"; | ||
3131 | 580 | } | ||
3132 | 581 | } | ||
3133 | 582 | |||
3134 | 583 | bool IppClient::isPrinterNameValid(const QString &name) | ||
3135 | 584 | { | ||
3136 | 585 | int i; | ||
3137 | 586 | int len; | ||
3138 | 587 | |||
3139 | 588 | /* Quoting the lpadmin man page: | ||
3140 | 589 | * CUPS allows printer names to contain any printable character | ||
3141 | 590 | * except SPACE, TAB, "/", or "#". | ||
3142 | 591 | * On top of that, validate_name() in lpadmin.c (from cups) checks that | ||
3143 | 592 | * the string is 127 characters long, or shorter. */ | ||
3144 | 593 | |||
3145 | 594 | /* no empty string */ | ||
3146 | 595 | if (name.isEmpty()) | ||
3147 | 596 | return false; | ||
3148 | 597 | |||
3149 | 598 | len = name.size(); | ||
3150 | 599 | /* no string that is too long; see comment at the beginning of the | ||
3151 | 600 | * validation code block */ | ||
3152 | 601 | if (len > 127) | ||
3153 | 602 | return false; | ||
3154 | 603 | |||
3155 | 604 | /* only printable characters, no space, no /, no # */ | ||
3156 | 605 | for (i = 0; i < len; i++) { | ||
3157 | 606 | const QChar c = name.at(i); | ||
3158 | 607 | if (!c.isPrint()) | ||
3159 | 608 | return false; | ||
3160 | 609 | if (c.isSpace()) | ||
3161 | 610 | return false; | ||
3162 | 611 | if (c == '/' || c == '#') | ||
3163 | 612 | return false; | ||
3164 | 613 | } | ||
3165 | 614 | return true; | ||
3166 | 615 | } | ||
3167 | 616 | |||
3168 | 617 | bool IppClient::isStringValid(const QString &string, const bool checkNull, | ||
3169 | 618 | const int maxLength) | ||
3170 | 619 | { | ||
3171 | 620 | if (isStringPrintable(string, checkNull, maxLength)) | ||
3172 | 621 | return true; | ||
3173 | 622 | return false; | ||
3174 | 623 | } | ||
3175 | 624 | |||
3176 | 625 | bool IppClient::isStringPrintable(const QString &string, const bool checkNull, | ||
3177 | 626 | const int maxLength) | ||
3178 | 627 | { | ||
3179 | 628 | int i; | ||
3180 | 629 | int len; | ||
3181 | 630 | |||
3182 | 631 | /* no null string */ | ||
3183 | 632 | if (string.isNull()) | ||
3184 | 633 | return !checkNull; | ||
3185 | 634 | |||
3186 | 635 | len = string.size(); | ||
3187 | 636 | if (maxLength > 0 && len > maxLength) | ||
3188 | 637 | return false; | ||
3189 | 638 | |||
3190 | 639 | /* only printable characters */ | ||
3191 | 640 | for (i = 0; i < len; i++) { | ||
3192 | 641 | const QChar c = string.at(i); | ||
3193 | 642 | if (!c.isPrint()) | ||
3194 | 643 | return false; | ||
3195 | 644 | } | ||
3196 | 645 | return true; | ||
3197 | 646 | } | ||
3198 | 647 | |||
3199 | 648 | void IppClient::setInternalStatus(const QString &status) | ||
3200 | 649 | { | ||
3201 | 650 | if (!m_internalStatus.isNull()) { | ||
3202 | 651 | m_internalStatus = QString::null; | ||
3203 | 652 | } | ||
3204 | 653 | |||
3205 | 654 | if (status.isNull()) { | ||
3206 | 655 | m_internalStatus = QString::null; | ||
3207 | 656 | } else { | ||
3208 | 657 | m_internalStatus = status; | ||
3209 | 658 | |||
3210 | 659 | // Only used for errors for now. | ||
3211 | 660 | qCritical() << status; | ||
3212 | 661 | } | ||
3213 | 662 | } | ||
3214 | 663 | |||
3215 | 664 | bool IppClient::postRequest(ipp_t *request, const QString &file, | ||
3216 | 665 | const CupsResource &resource) | ||
3217 | 666 | { | ||
3218 | 667 | ipp_t *reply; | ||
3219 | 668 | QString resourceChar; | ||
3220 | 669 | |||
3221 | 670 | resourceChar = getResource(resource); | ||
3222 | 671 | |||
3223 | 672 | if (!file.isEmpty()) | ||
3224 | 673 | reply = cupsDoFileRequest(m_connection, request, resourceChar.toUtf8(), | ||
3225 | 674 | file.toUtf8()); | ||
3226 | 675 | else | ||
3227 | 676 | reply = cupsDoFileRequest(m_connection, request, resourceChar.toUtf8(), | ||
3228 | 677 | NULL); | ||
3229 | 678 | |||
3230 | 679 | return handleReply(reply); | ||
3231 | 680 | } | ||
3232 | 681 | |||
3233 | 682 | |||
3234 | 683 | bool IppClient::sendRequest(ipp_t *request, const CupsResource &resource) | ||
3235 | 684 | { | ||
3236 | 685 | ipp_t *reply; | ||
3237 | 686 | const QString resourceChar = getResource(resource); | ||
3238 | 687 | reply = cupsDoRequest(m_connection, request, | ||
3239 | 688 | resourceChar.toUtf8()); | ||
3240 | 689 | return handleReply(reply); | ||
3241 | 690 | } | ||
3242 | 691 | |||
3243 | 692 | bool IppClient::sendNewSimpleRequest(ipp_op_t op, const QString &printerName, | ||
3244 | 693 | const IppClient::CupsResource &resource) | ||
3245 | 694 | { | ||
3246 | 695 | ipp_t *request; | ||
3247 | 696 | |||
3248 | 697 | if (!isPrinterNameValid(printerName)) | ||
3249 | 698 | return false; | ||
3250 | 699 | |||
3251 | 700 | request = ippNewRequest(op); | ||
3252 | 701 | addPrinterUri(request, printerName); | ||
3253 | 702 | addRequestingUsername(request, NULL); | ||
3254 | 703 | |||
3255 | 704 | return sendRequest(request, resource); | ||
3256 | 705 | } | ||
3257 | 706 | |||
3258 | 707 | bool IppClient::handleReply(ipp_t *reply) | ||
3259 | 708 | { | ||
3260 | 709 | bool retval; | ||
3261 | 710 | retval = isReplyOk(reply, false); | ||
3262 | 711 | if (reply) | ||
3263 | 712 | ippDelete(reply); | ||
3264 | 713 | |||
3265 | 714 | return retval; | ||
3266 | 715 | } | ||
3267 | 716 | |||
3268 | 717 | bool IppClient::isReplyOk(ipp_t *reply, bool deleteIfReplyNotOk) | ||
3269 | 718 | { | ||
3270 | 719 | /* reset the internal status: we'll use the cups status */ | ||
3271 | 720 | m_lastStatus = IPP_STATUS_CUPS_INVALID; | ||
3272 | 721 | |||
3273 | 722 | if (reply && ippGetStatusCode(reply) <= IPP_OK_CONFLICT) { | ||
3274 | 723 | m_lastStatus = IPP_OK; | ||
3275 | 724 | return true; | ||
3276 | 725 | } else { | ||
3277 | 726 | setErrorFromReply(reply); | ||
3278 | 727 | qWarning() << Q_FUNC_INFO << "Cups HTTP error:" << cupsLastErrorString(); | ||
3279 | 728 | |||
3280 | 729 | if (deleteIfReplyNotOk && reply) | ||
3281 | 730 | ippDelete(reply); | ||
3282 | 731 | |||
3283 | 732 | return false; | ||
3284 | 733 | } | ||
3285 | 734 | } | ||
3286 | 735 | |||
3287 | 736 | void IppClient::setErrorFromReply(ipp_t *reply) | ||
3288 | 737 | { | ||
3289 | 738 | if (reply) | ||
3290 | 739 | m_lastStatus = ippGetStatusCode(reply); | ||
3291 | 740 | else | ||
3292 | 741 | m_lastStatus = cupsLastError(); | ||
3293 | 742 | } | ||
3294 | 743 | |||
3295 | 744 | bool IppClient::printerIsClass(const QString &name) | ||
3296 | 745 | { | ||
3297 | 746 | const char * const attrs[1] = { "member-names" }; | ||
3298 | 747 | ipp_t *request; | ||
3299 | 748 | QString resource; | ||
3300 | 749 | ipp_t *reply; | ||
3301 | 750 | bool retval; | ||
3302 | 751 | |||
3303 | 752 | // Class/Printer name validation is equal. | ||
3304 | 753 | if (!isPrinterNameValid(name)) { | ||
3305 | 754 | setInternalStatus(QString("%1 is not a valid printer name.").arg(name)); | ||
3306 | 755 | return false; | ||
3307 | 756 | } | ||
3308 | 757 | |||
3309 | 758 | request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES); | ||
3310 | 759 | addClassUri(request, name); | ||
3311 | 760 | addRequestingUsername(request, QString()); | ||
3312 | 761 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | ||
3313 | 762 | "requested-attributes", 1, NULL, attrs); | ||
3314 | 763 | |||
3315 | 764 | resource = getResource(CupsResource::CupsResourceRoot); | ||
3316 | 765 | reply = cupsDoRequest(m_connection, request, resource.toUtf8()); | ||
3317 | 766 | |||
3318 | 767 | if (!isReplyOk(reply, true)) | ||
3319 | 768 | return true; | ||
3320 | 769 | |||
3321 | 770 | /* Note: we need to look if the attribute is there, since we get a | ||
3322 | 771 | * reply if the name is a printer name and not a class name. The | ||
3323 | 772 | * attribute is the only way to distinguish the two cases. */ | ||
3324 | 773 | retval = ippFindAttribute(reply, attrs[0], IPP_TAG_NAME) != NULL; | ||
3325 | 774 | |||
3326 | 775 | if (reply) | ||
3327 | 776 | ippDelete(reply); | ||
3328 | 777 | |||
3329 | 778 | return retval; | ||
3330 | 779 | } | ||
3331 | 780 | |||
3332 | 781 | void IppClient::addClassUri(ipp_t *request, const QString &name) | ||
3333 | 782 | { | ||
3334 | 783 | QUrl uri(QString("ipp://localhost/printers/%1").arg(name)); | ||
3335 | 784 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, | ||
3336 | 785 | "printer-uri", NULL, uri.toEncoded().data()); | ||
3337 | 786 | } | ||
3338 | 787 | |||
3339 | 788 | ppd_file_t* IppClient::getPpdFile(const QString &name, | ||
3340 | 789 | const QString &instance) const | ||
3341 | 790 | { | ||
3342 | 791 | Q_UNUSED(instance); | ||
3343 | 792 | |||
3344 | 793 | ppd_file_t* file = 0; | ||
3345 | 794 | const char *ppdFile = cupsGetPPD(name.toUtf8()); | ||
3346 | 795 | if (ppdFile) { | ||
3347 | 796 | file = ppdOpenFile(ppdFile); | ||
3348 | 797 | unlink(ppdFile); | ||
3349 | 798 | } | ||
3350 | 799 | if (file) { | ||
3351 | 800 | ppdMarkDefaults(file); | ||
3352 | 801 | } else { | ||
3353 | 802 | file = 0; | ||
3354 | 803 | } | ||
3355 | 804 | |||
3356 | 805 | return file; | ||
3357 | 806 | } | ||
3358 | 807 | |||
3359 | 808 | cups_dest_t* IppClient::getDest(const QString &name, | ||
3360 | 809 | const QString &instance) const | ||
3361 | 810 | { | ||
3362 | 811 | cups_dest_t *dest = 0; | ||
3363 | 812 | |||
3364 | 813 | if (instance.isEmpty()) { | ||
3365 | 814 | dest = cupsGetNamedDest(m_connection, name.toUtf8(), NULL); | ||
3366 | 815 | } else { | ||
3367 | 816 | dest = cupsGetNamedDest(m_connection, name.toUtf8(), instance.toUtf8()); | ||
3368 | 817 | } | ||
3369 | 818 | return dest; | ||
3370 | 819 | } | ||
3371 | 820 | |||
3372 | 821 | ipp_t* IppClient::createPrinterDriversRequest( | ||
3373 | 822 | const QString &deviceId, const QString &language, const QString &makeModel, | ||
3374 | 823 | const QString &product, const QStringList &includeSchemes, | ||
3375 | 824 | const QStringList &excludeSchemes | ||
3376 | 825 | ) | ||
3377 | 826 | { | ||
3378 | 827 | Q_UNUSED(includeSchemes); | ||
3379 | 828 | Q_UNUSED(excludeSchemes); | ||
3380 | 829 | |||
3381 | 830 | ipp_t *request; | ||
3382 | 831 | |||
3383 | 832 | request = ippNewRequest(CUPS_GET_PPDS); | ||
3384 | 833 | |||
3385 | 834 | if (!deviceId.isEmpty()) | ||
3386 | 835 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT, "ppd-device-id", | ||
3387 | 836 | NULL, deviceId.toUtf8()); | ||
3388 | 837 | if (!language.isEmpty()) | ||
3389 | 838 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "ppd-language", | ||
3390 | 839 | NULL, language.toUtf8()); | ||
3391 | 840 | if (!makeModel.isEmpty()) | ||
3392 | 841 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT, "ppd-make-and-model", | ||
3393 | 842 | NULL, makeModel.toUtf8()); | ||
3394 | 843 | if (!product.isEmpty()) | ||
3395 | 844 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT, "ppd-product", | ||
3396 | 845 | NULL, product.toUtf8()); | ||
3397 | 846 | |||
3398 | 847 | // Do the request and get return the response. | ||
3399 | 848 | const QString resourceChar = getResource(CupsResourceRoot); | ||
3400 | 849 | return cupsDoRequest(m_connection, request, | ||
3401 | 850 | resourceChar.toUtf8()); | ||
3402 | 851 | } | ||
3403 | 852 | |||
3404 | 853 | int IppClient::createSubscription() | ||
3405 | 854 | { | ||
3406 | 855 | ipp_t *req; | ||
3407 | 856 | ipp_t *resp; | ||
3408 | 857 | ipp_attribute_t *attr; | ||
3409 | 858 | int subscriptionId = -1; | ||
3410 | 859 | |||
3411 | 860 | req = ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION); | ||
3412 | 861 | ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, | ||
3413 | 862 | "printer-uri", NULL, "/"); | ||
3414 | 863 | ippAddString(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, | ||
3415 | 864 | "notify-events", NULL, "all"); | ||
3416 | 865 | ippAddString(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, | ||
3417 | 866 | "notify-recipient-uri", NULL, "dbus://"); | ||
3418 | 867 | ippAddInteger(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, | ||
3419 | 868 | "notify-lease-duration", 0); | ||
3420 | 869 | |||
3421 | 870 | resp = cupsDoRequest(m_connection, req, | ||
3422 | 871 | getResource(CupsResourceRoot).toUtf8()); | ||
3423 | 872 | if (!isReplyOk(resp, true)) { | ||
3424 | 873 | return subscriptionId; | ||
3425 | 874 | } | ||
3426 | 875 | |||
3427 | 876 | attr = ippFindAttribute(resp, "notify-subscription-id", IPP_TAG_INTEGER); | ||
3428 | 877 | |||
3429 | 878 | if (!attr) { | ||
3430 | 879 | qWarning() << "ipp-create-printer-subscription response doesn't" | ||
3431 | 880 | " contain subscription id."; | ||
3432 | 881 | } else { | ||
3433 | 882 | subscriptionId = ippGetInteger(attr, 0); | ||
3434 | 883 | } | ||
3435 | 884 | |||
3436 | 885 | ippDelete (resp); | ||
3437 | 886 | |||
3438 | 887 | return subscriptionId; | ||
3439 | 888 | } | ||
3440 | 889 | |||
3441 | 890 | void IppClient::cancelSubscription(const int &subscriptionId) | ||
3442 | 891 | { | ||
3443 | 892 | ipp_t *req; | ||
3444 | 893 | ipp_t *resp; | ||
3445 | 894 | |||
3446 | 895 | if (subscriptionId <= 0) { | ||
3447 | 896 | return; | ||
3448 | 897 | } | ||
3449 | 898 | |||
3450 | 899 | req = ippNewRequest(IPP_CANCEL_SUBSCRIPTION); | ||
3451 | 900 | ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, | ||
3452 | 901 | "printer-uri", NULL, "/"); | ||
3453 | 902 | ippAddInteger(req, IPP_TAG_OPERATION, IPP_TAG_INTEGER, | ||
3454 | 903 | "notify-subscription-id", subscriptionId); | ||
3455 | 904 | |||
3456 | 905 | resp = cupsDoRequest(m_connection, req, | ||
3457 | 906 | getResource(CupsResourceRoot).toUtf8()); | ||
3458 | 907 | if (!isReplyOk(resp, true)) { | ||
3459 | 908 | return; | ||
3460 | 909 | } | ||
3461 | 910 | |||
3462 | 911 | ippDelete(resp); | ||
3463 | 912 | } | ||
3464 | 913 | |||
3465 | 914 | QVariant IppClient::getAttributeValue(ipp_attribute_t *attr, int index) const | ||
3466 | 915 | { | ||
3467 | 916 | QVariant var; | ||
3468 | 917 | |||
3469 | 918 | if (ippGetCount(attr) > 1 && index < 0) { | ||
3470 | 919 | QList<QVariant> list; | ||
3471 | 920 | |||
3472 | 921 | for (int i=0; i < ippGetCount(attr); i++) { | ||
3473 | 922 | list.append(getAttributeValue(attr, i)); | ||
3474 | 923 | } | ||
3475 | 924 | |||
3476 | 925 | var = QVariant::fromValue<QList<QVariant>>(list); | ||
3477 | 926 | } else { | ||
3478 | 927 | if (index == -1) { | ||
3479 | 928 | index = 0; | ||
3480 | 929 | } | ||
3481 | 930 | |||
3482 | 931 | switch (ippGetValueTag(attr)) { | ||
3483 | 932 | case IPP_TAG_NAME: | ||
3484 | 933 | case IPP_TAG_TEXT: | ||
3485 | 934 | case IPP_TAG_KEYWORD: | ||
3486 | 935 | case IPP_TAG_URI: | ||
3487 | 936 | case IPP_TAG_CHARSET: | ||
3488 | 937 | case IPP_TAG_MIMETYPE: | ||
3489 | 938 | case IPP_TAG_LANGUAGE: | ||
3490 | 939 | var = QVariant::fromValue<QString>(ippGetString(attr, index, NULL)); | ||
3491 | 940 | break; | ||
3492 | 941 | case IPP_TAG_INTEGER: | ||
3493 | 942 | case IPP_TAG_ENUM: | ||
3494 | 943 | var = QVariant::fromValue<int>(ippGetInteger(attr, index)); | ||
3495 | 944 | break; | ||
3496 | 945 | case IPP_TAG_BOOLEAN: | ||
3497 | 946 | var = QVariant::fromValue<bool>(ippGetBoolean(attr, index)); | ||
3498 | 947 | break; | ||
3499 | 948 | case IPP_TAG_RANGE: { | ||
3500 | 949 | QString range; | ||
3501 | 950 | int upper; | ||
3502 | 951 | int lower = ippGetRange(attr, index, &upper); | ||
3503 | 952 | |||
3504 | 953 | // Build a string similar to "1-3" "5-" "8" "-4" | ||
3505 | 954 | if (lower != INT_MIN) { | ||
3506 | 955 | range += QString::number(lower); | ||
3507 | 956 | } | ||
3508 | 957 | |||
3509 | 958 | if (lower != upper) { | ||
3510 | 959 | range += QStringLiteral("-"); | ||
3511 | 960 | |||
3512 | 961 | if (upper != INT_MAX) { | ||
3513 | 962 | range += QString::number(upper); | ||
3514 | 963 | } | ||
3515 | 964 | } | ||
3516 | 965 | |||
3517 | 966 | var = QVariant(range); | ||
3518 | 967 | break; | ||
3519 | 968 | } | ||
3520 | 969 | case IPP_TAG_NOVALUE: | ||
3521 | 970 | var = QVariant(); | ||
3522 | 971 | break; | ||
3523 | 972 | case IPP_TAG_DATE: { | ||
3524 | 973 | time_t time = ippDateToTime(ippGetDate(attr, index)); | ||
3525 | 974 | QDateTime datetime; | ||
3526 | 975 | datetime.setTimeZone(QTimeZone::systemTimeZone()); | ||
3527 | 976 | datetime.setTime_t(time); | ||
3528 | 977 | |||
3529 | 978 | var = QVariant::fromValue<QDateTime>(datetime); | ||
3530 | 979 | break; | ||
3531 | 980 | } | ||
3532 | 981 | default: | ||
3533 | 982 | qWarning() << "Unknown IPP value tab 0x" << ippGetValueTag(attr); | ||
3534 | 983 | break; | ||
3535 | 984 | } | ||
3536 | 985 | } | ||
3537 | 986 | |||
3538 | 987 | return var; | ||
3539 | 988 | } | ||
3540 | 0 | 989 | ||
3541 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h' | |||
3542 | --- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 1970-01-01 00:00:00 +0000 | |||
3543 | +++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-02-22 12:44:26 +0000 | |||
3544 | @@ -0,0 +1,121 @@ | |||
3545 | 1 | /* | ||
3546 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3547 | 3 | * | ||
3548 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3549 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3550 | 6 | * the Free Software Foundation; version 3. | ||
3551 | 7 | * | ||
3552 | 8 | * This program is distributed in the hope that it will be useful, | ||
3553 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3554 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3555 | 11 | * GNU Lesser General Public License for more details. | ||
3556 | 12 | * | ||
3557 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3558 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3559 | 15 | */ | ||
3560 | 16 | |||
3561 | 17 | #ifndef USC_PRINTERS_CUPS_IPPCLIENT_H | ||
3562 | 18 | #define USC_PRINTERS_CUPS_IPPCLIENT_H | ||
3563 | 19 | |||
3564 | 20 | #include "structs.h" | ||
3565 | 21 | |||
3566 | 22 | #include <cups/cups.h> | ||
3567 | 23 | #include <cups/http.h> | ||
3568 | 24 | #include <cups/ipp.h> | ||
3569 | 25 | #include <cups/ppd.h> | ||
3570 | 26 | |||
3571 | 27 | #include <QString> | ||
3572 | 28 | #include <QStringList> | ||
3573 | 29 | |||
3574 | 30 | /* From https://bugzilla.novell.com/show_bug.cgi?id=447444#c5 | ||
3575 | 31 | * We need to define a maximum length for strings to avoid cups | ||
3576 | 32 | * thinking there are multiple lines. | ||
3577 | 33 | */ | ||
3578 | 34 | #define CPH_STR_MAXLEN 512 | ||
3579 | 35 | |||
3580 | 36 | class IppClient | ||
3581 | 37 | { | ||
3582 | 38 | public: | ||
3583 | 39 | explicit IppClient(); | ||
3584 | 40 | ~IppClient(); | ||
3585 | 41 | |||
3586 | 42 | bool printerDelete(const QString &printerName); | ||
3587 | 43 | bool printerAdd(const QString &printerName, | ||
3588 | 44 | const QString &printerUri, | ||
3589 | 45 | const QString &ppdFile, | ||
3590 | 46 | const QString &info, | ||
3591 | 47 | const QString &location); | ||
3592 | 48 | |||
3593 | 49 | bool printerAddWithPpdFile(const QString &printerName, | ||
3594 | 50 | const QString &printerUri, | ||
3595 | 51 | const QString &ppdFileName, | ||
3596 | 52 | const QString &info, | ||
3597 | 53 | const QString &location); | ||
3598 | 54 | bool printerSetDefault(const QString &printerName); | ||
3599 | 55 | bool printerSetEnabled(const QString &printerName, const bool enabled); | ||
3600 | 56 | bool printerSetAcceptJobs(const QString &printerName, const bool accept, | ||
3601 | 57 | const QString &reason); | ||
3602 | 58 | bool printerClassSetInfo(const QString &name, const QString &info); | ||
3603 | 59 | bool printerClassSetOption(const QString &name, const QString &option, | ||
3604 | 60 | const QStringList &values); | ||
3605 | 61 | ppd_file_t* getPpdFile(const QString &name, const QString &instance) const; | ||
3606 | 62 | cups_dest_t* getDest(const QString &name, const QString &instance) const; | ||
3607 | 63 | |||
3608 | 64 | QMap<QString, QVariant> printerGetJobAttributes(const int jobId); | ||
3609 | 65 | |||
3610 | 66 | QString getLastError() const; | ||
3611 | 67 | |||
3612 | 68 | // Note: This response needs to be free by the caller. | ||
3613 | 69 | ipp_t* createPrinterDriversRequest( | ||
3614 | 70 | const QString &deviceId, const QString &language, | ||
3615 | 71 | const QString &makeModel, const QString &product, | ||
3616 | 72 | const QStringList &includeSchemes, const QStringList &excludeSchemes | ||
3617 | 73 | ); | ||
3618 | 74 | int createSubscription(); | ||
3619 | 75 | void cancelSubscription(const int &subscriptionId); | ||
3620 | 76 | |||
3621 | 77 | private: | ||
3622 | 78 | enum CupsResource | ||
3623 | 79 | { | ||
3624 | 80 | CupsResourceRoot = 0, | ||
3625 | 81 | CupsResourceAdmin, | ||
3626 | 82 | CupsResourceJobs, | ||
3627 | 83 | }; | ||
3628 | 84 | |||
3629 | 85 | bool sendNewPrinterClassRequest(const QString &printerName, | ||
3630 | 86 | ipp_tag_t group, | ||
3631 | 87 | ipp_tag_t type, | ||
3632 | 88 | const QString &name, | ||
3633 | 89 | const QString &value); | ||
3634 | 90 | static void addPrinterUri(ipp_t *request, const QString &name); | ||
3635 | 91 | static void addRequestingUsername(ipp_t *request, const QString &username); | ||
3636 | 92 | static const QString getResource(const CupsResource &resource); | ||
3637 | 93 | static bool isPrinterNameValid(const QString &name); | ||
3638 | 94 | static void addClassUri(ipp_t *request, const QString &name); | ||
3639 | 95 | static bool isStringValid(const QString &string, | ||
3640 | 96 | const bool checkNull = false, | ||
3641 | 97 | const int maxLength = 512); | ||
3642 | 98 | static bool isStringPrintable(const QString &string, const bool checkNull, | ||
3643 | 99 | const int maxLength); | ||
3644 | 100 | QString preparePpdForOptions(const QString &ppdfile, | ||
3645 | 101 | cups_option_t *options, | ||
3646 | 102 | int numOptions); | ||
3647 | 103 | bool printerIsClass(const QString &name); | ||
3648 | 104 | void setInternalStatus(const QString &status); | ||
3649 | 105 | bool postRequest(ipp_t *request, const QString &file, | ||
3650 | 106 | const CupsResource &resource); | ||
3651 | 107 | bool sendRequest(ipp_t *request, const CupsResource &resource); | ||
3652 | 108 | bool sendNewSimpleRequest(ipp_op_t op, const QString &printerName, | ||
3653 | 109 | const CupsResource &resource); | ||
3654 | 110 | bool handleReply(ipp_t *reply); | ||
3655 | 111 | bool isReplyOk(ipp_t *reply, bool deleteIfReplyNotOk); | ||
3656 | 112 | void setErrorFromReply(ipp_t *reply); | ||
3657 | 113 | QVariant getAttributeValue(ipp_attribute_t *attr, int index=-1) const; | ||
3658 | 114 | |||
3659 | 115 | http_t *m_connection; | ||
3660 | 116 | ipp_status_t m_lastStatus = IPP_OK; | ||
3661 | 117 | mutable QString m_internalStatus = QString::null; | ||
3662 | 118 | }; | ||
3663 | 119 | |||
3664 | 120 | |||
3665 | 121 | #endif // USC_PRINTERS_CUPS_IPPCLIENT_H | ||
3666 | 0 | 122 | ||
3667 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.cpp' | |||
3668 | --- modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.cpp 1970-01-01 00:00:00 +0000 | |||
3669 | +++ modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.cpp 2017-02-22 12:44:26 +0000 | |||
3670 | @@ -0,0 +1,128 @@ | |||
3671 | 1 | /* | ||
3672 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3673 | 3 | * | ||
3674 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3675 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3676 | 6 | * the Free Software Foundation; version 3. | ||
3677 | 7 | * | ||
3678 | 8 | * This program is distributed in the hope that it will be useful, | ||
3679 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3680 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3681 | 11 | * GNU Lesser General Public License for more details. | ||
3682 | 12 | * | ||
3683 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3684 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3685 | 15 | */ | ||
3686 | 16 | |||
3687 | 17 | #include "printerdriverloader.h" | ||
3688 | 18 | |||
3689 | 19 | PrinterDriverLoader::PrinterDriverLoader( | ||
3690 | 20 | const QString &deviceId, const QString &language, | ||
3691 | 21 | const QString &makeModel, const QString &product, | ||
3692 | 22 | const QStringList &includeSchemes, const QStringList &excludeSchemes) | ||
3693 | 23 | : m_deviceId(deviceId) | ||
3694 | 24 | , m_language(language) | ||
3695 | 25 | , m_makeModel(makeModel) | ||
3696 | 26 | , m_product(product) | ||
3697 | 27 | , m_includeSchemes(includeSchemes) | ||
3698 | 28 | , m_excludeSchemes(excludeSchemes) | ||
3699 | 29 | { | ||
3700 | 30 | } | ||
3701 | 31 | |||
3702 | 32 | PrinterDriverLoader::~PrinterDriverLoader() | ||
3703 | 33 | { | ||
3704 | 34 | } | ||
3705 | 35 | |||
3706 | 36 | void PrinterDriverLoader::process() | ||
3707 | 37 | { | ||
3708 | 38 | m_running = true; | ||
3709 | 39 | |||
3710 | 40 | ipp_t* response = client.createPrinterDriversRequest( | ||
3711 | 41 | m_deviceId, m_language, m_makeModel, m_product, m_includeSchemes, | ||
3712 | 42 | m_excludeSchemes | ||
3713 | 43 | ); | ||
3714 | 44 | |||
3715 | 45 | // Note: if the response somehow fails, we return. | ||
3716 | 46 | if (!response || ippGetStatusCode(response) > IPP_OK_CONFLICT) { | ||
3717 | 47 | QString err(cupsLastErrorString()); | ||
3718 | 48 | qWarning() << Q_FUNC_INFO << "Cups HTTP error:" << err; | ||
3719 | 49 | |||
3720 | 50 | if (response) | ||
3721 | 51 | ippDelete(response); | ||
3722 | 52 | |||
3723 | 53 | Q_EMIT error(err); | ||
3724 | 54 | Q_EMIT finished(); | ||
3725 | 55 | return; | ||
3726 | 56 | } | ||
3727 | 57 | |||
3728 | 58 | ipp_attribute_t *attr; | ||
3729 | 59 | QByteArray ppdDeviceId; | ||
3730 | 60 | QByteArray ppdLanguage; | ||
3731 | 61 | QByteArray ppdMakeModel; | ||
3732 | 62 | QByteArray ppdName; | ||
3733 | 63 | |||
3734 | 64 | // cups_option_t option; | ||
3735 | 65 | QList<PrinterDriver> drivers; | ||
3736 | 66 | |||
3737 | 67 | for (attr = ippFirstAttribute(response); attr != NULL && m_running; attr = ippNextAttribute(response)) { | ||
3738 | 68 | |||
3739 | 69 | while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER) | ||
3740 | 70 | attr = ippNextAttribute(response); | ||
3741 | 71 | |||
3742 | 72 | if (attr == NULL) | ||
3743 | 73 | break; | ||
3744 | 74 | |||
3745 | 75 | // Pull the needed attributes from this PPD... | ||
3746 | 76 | ppdDeviceId = "NONE"; | ||
3747 | 77 | ppdLanguage.clear(); | ||
3748 | 78 | ppdMakeModel.clear(); | ||
3749 | 79 | ppdName.clear(); | ||
3750 | 80 | |||
3751 | 81 | while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) { | ||
3752 | 82 | if (!strcmp(ippGetName(attr), "ppd-device-id") && | ||
3753 | 83 | ippGetValueTag(attr) == IPP_TAG_TEXT) { | ||
3754 | 84 | ppdDeviceId = ippGetString(attr, 0, NULL); | ||
3755 | 85 | } else if (!strcmp(ippGetName(attr), "ppd-natural-language") && | ||
3756 | 86 | ippGetValueTag(attr) == IPP_TAG_LANGUAGE) { | ||
3757 | 87 | ppdLanguage = ippGetString(attr, 0, NULL); | ||
3758 | 88 | |||
3759 | 89 | } else if (!strcmp(ippGetName(attr), "ppd-make-and-model") && | ||
3760 | 90 | ippGetValueTag(attr) == IPP_TAG_TEXT) { | ||
3761 | 91 | ppdMakeModel = ippGetString(attr, 0, NULL); | ||
3762 | 92 | } else if (!strcmp(ippGetName(attr), "ppd-name") && | ||
3763 | 93 | ippGetValueTag(attr) == IPP_TAG_NAME) { | ||
3764 | 94 | |||
3765 | 95 | ppdName = ippGetString(attr, 0, NULL); | ||
3766 | 96 | } | ||
3767 | 97 | |||
3768 | 98 | attr = ippNextAttribute(response); | ||
3769 | 99 | } | ||
3770 | 100 | |||
3771 | 101 | // See if we have everything needed... | ||
3772 | 102 | if (ppdLanguage.isEmpty() || ppdMakeModel.isEmpty() || | ||
3773 | 103 | ppdName.isEmpty()) { | ||
3774 | 104 | if (attr == NULL) | ||
3775 | 105 | break; | ||
3776 | 106 | else | ||
3777 | 107 | continue; | ||
3778 | 108 | } | ||
3779 | 109 | |||
3780 | 110 | PrinterDriver m; | ||
3781 | 111 | m.name = ppdName; | ||
3782 | 112 | m.deviceId = ppdDeviceId; | ||
3783 | 113 | m.makeModel = ppdMakeModel; | ||
3784 | 114 | m.language = ppdLanguage; | ||
3785 | 115 | |||
3786 | 116 | drivers.append(m); | ||
3787 | 117 | } | ||
3788 | 118 | |||
3789 | 119 | ippDelete(response); | ||
3790 | 120 | |||
3791 | 121 | Q_EMIT loaded(drivers); | ||
3792 | 122 | Q_EMIT finished(); | ||
3793 | 123 | } | ||
3794 | 124 | |||
3795 | 125 | void PrinterDriverLoader::cancel() | ||
3796 | 126 | { | ||
3797 | 127 | m_running = false; | ||
3798 | 128 | } | ||
3799 | 0 | 129 | ||
3800 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.h' | |||
3801 | --- modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.h 1970-01-01 00:00:00 +0000 | |||
3802 | +++ modules/Ubuntu/Components/Extras/Printers/cups/printerdriverloader.h 2017-02-22 12:44:26 +0000 | |||
3803 | @@ -0,0 +1,61 @@ | |||
3804 | 1 | /* | ||
3805 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3806 | 3 | * | ||
3807 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3808 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3809 | 6 | * the Free Software Foundation; version 3. | ||
3810 | 7 | * | ||
3811 | 8 | * This program is distributed in the hope that it will be useful, | ||
3812 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3813 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3814 | 11 | * GNU Lesser General Public License for more details. | ||
3815 | 12 | * | ||
3816 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3817 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3818 | 15 | */ | ||
3819 | 16 | |||
3820 | 17 | #ifndef USC_PRINTERS_CUPS_DRIVERLOADER_H | ||
3821 | 18 | #define USC_PRINTERS_CUPS_DRIVERLOADER_H | ||
3822 | 19 | |||
3823 | 20 | #include "ippclient.h" | ||
3824 | 21 | #include "structs.h" | ||
3825 | 22 | |||
3826 | 23 | #include <QObject> | ||
3827 | 24 | #include <QString> | ||
3828 | 25 | #include <QStringList> | ||
3829 | 26 | |||
3830 | 27 | class PrinterDriverLoader : public QObject | ||
3831 | 28 | { | ||
3832 | 29 | Q_OBJECT | ||
3833 | 30 | public: | ||
3834 | 31 | PrinterDriverLoader( | ||
3835 | 32 | const QString &deviceId = "", | ||
3836 | 33 | const QString &language = "", | ||
3837 | 34 | const QString &makeModel = "", | ||
3838 | 35 | const QString &product = "", | ||
3839 | 36 | const QStringList &includeSchemes = QStringList(), | ||
3840 | 37 | const QStringList &excludeSchemes = QStringList()); | ||
3841 | 38 | ~PrinterDriverLoader(); | ||
3842 | 39 | |||
3843 | 40 | public Q_SLOTS: | ||
3844 | 41 | void process(); | ||
3845 | 42 | void cancel(); | ||
3846 | 43 | |||
3847 | 44 | Q_SIGNALS: | ||
3848 | 45 | void finished(); | ||
3849 | 46 | void loaded(const QList<PrinterDriver> &drivers); | ||
3850 | 47 | void error(const QString &error); | ||
3851 | 48 | |||
3852 | 49 | private: | ||
3853 | 50 | QString m_deviceId = QString::null; | ||
3854 | 51 | QString m_language = QString::null; | ||
3855 | 52 | QString m_makeModel = QString::null; | ||
3856 | 53 | QString m_product = QString::null; | ||
3857 | 54 | QStringList m_includeSchemes; | ||
3858 | 55 | QStringList m_excludeSchemes; | ||
3859 | 56 | |||
3860 | 57 | bool m_running = false; | ||
3861 | 58 | IppClient client; | ||
3862 | 59 | }; | ||
3863 | 60 | |||
3864 | 61 | #endif // USC_PRINTERS_CUPS_DRIVERLOADER_H | ||
3865 | 0 | 62 | ||
3866 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp' | |||
3867 | --- modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp 1970-01-01 00:00:00 +0000 | |||
3868 | +++ modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp 2017-02-22 12:44:26 +0000 | |||
3869 | @@ -0,0 +1,53 @@ | |||
3870 | 1 | /* | ||
3871 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3872 | 3 | * | ||
3873 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3874 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3875 | 6 | * the Free Software Foundation; version 3. | ||
3876 | 7 | * | ||
3877 | 8 | * This program is distributed in the hope that it will be useful, | ||
3878 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3879 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3880 | 11 | * GNU Lesser General Public License for more details. | ||
3881 | 12 | * | ||
3882 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3883 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3884 | 15 | */ | ||
3885 | 16 | |||
3886 | 17 | #include "backend/backend_pdf.h" | ||
3887 | 18 | #include "backend/backend_cups.h" | ||
3888 | 19 | #include "printerloader.h" | ||
3889 | 20 | |||
3890 | 21 | #include <QPrinterInfo> | ||
3891 | 22 | |||
3892 | 23 | class PrinterCupsBackend; | ||
3893 | 24 | PrinterLoader::PrinterLoader(const QString &printerName, | ||
3894 | 25 | IppClient *client, | ||
3895 | 26 | OrgCupsCupsdNotifierInterface* notifier, | ||
3896 | 27 | QObject *parent) | ||
3897 | 28 | : QObject(parent) | ||
3898 | 29 | , m_printerName(printerName) | ||
3899 | 30 | , m_client(client) | ||
3900 | 31 | , m_notifier(notifier) | ||
3901 | 32 | { | ||
3902 | 33 | } | ||
3903 | 34 | |||
3904 | 35 | PrinterLoader::~PrinterLoader() | ||
3905 | 36 | { | ||
3906 | 37 | } | ||
3907 | 38 | |||
3908 | 39 | void PrinterLoader::load() | ||
3909 | 40 | { | ||
3910 | 41 | QPrinterInfo info = QPrinterInfo::printerInfo(m_printerName); | ||
3911 | 42 | auto backend = new PrinterCupsBackend(m_client, info, m_notifier); | ||
3912 | 43 | |||
3913 | 44 | // Dest or PPD was null, but we know it's name so we will use it. | ||
3914 | 45 | if (info.printerName().isEmpty()) { | ||
3915 | 46 | backend->setPrinterNameInternal(m_printerName); | ||
3916 | 47 | } | ||
3917 | 48 | |||
3918 | 49 | auto p = QSharedPointer<Printer>(new Printer(backend)); | ||
3919 | 50 | |||
3920 | 51 | Q_EMIT loaded(p); | ||
3921 | 52 | Q_EMIT finished(); | ||
3922 | 53 | } | ||
3923 | 0 | 54 | ||
3924 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/printerloader.h' | |||
3925 | --- modules/Ubuntu/Components/Extras/Printers/cups/printerloader.h 1970-01-01 00:00:00 +0000 | |||
3926 | +++ modules/Ubuntu/Components/Extras/Printers/cups/printerloader.h 2017-02-22 12:44:26 +0000 | |||
3927 | @@ -0,0 +1,49 @@ | |||
3928 | 1 | /* | ||
3929 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3930 | 3 | * | ||
3931 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3932 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3933 | 6 | * the Free Software Foundation; version 3. | ||
3934 | 7 | * | ||
3935 | 8 | * This program is distributed in the hope that it will be useful, | ||
3936 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3937 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3938 | 11 | * GNU Lesser General Public License for more details. | ||
3939 | 12 | * | ||
3940 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3941 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3942 | 15 | */ | ||
3943 | 16 | |||
3944 | 17 | #ifndef USC_PRINTERS_CUPS_PRINTERLOADER_H | ||
3945 | 18 | #define USC_PRINTERS_CUPS_PRINTERLOADER_H | ||
3946 | 19 | |||
3947 | 20 | #include "cups/ippclient.h" | ||
3948 | 21 | #include "cupsdnotifier.h" // Note: this file was generated. | ||
3949 | 22 | #include "printer/printer.h" | ||
3950 | 23 | |||
3951 | 24 | #include <QList> | ||
3952 | 25 | #include <QObject> | ||
3953 | 26 | #include <QSharedPointer> | ||
3954 | 27 | |||
3955 | 28 | class PrinterLoader : public QObject | ||
3956 | 29 | { | ||
3957 | 30 | Q_OBJECT | ||
3958 | 31 | const QString m_printerName; | ||
3959 | 32 | IppClient *m_client; | ||
3960 | 33 | OrgCupsCupsdNotifierInterface *m_notifier; | ||
3961 | 34 | public: | ||
3962 | 35 | explicit PrinterLoader(const QString &printerName, | ||
3963 | 36 | IppClient *client, | ||
3964 | 37 | OrgCupsCupsdNotifierInterface* notifier, | ||
3965 | 38 | QObject *parent = Q_NULLPTR); | ||
3966 | 39 | ~PrinterLoader(); | ||
3967 | 40 | |||
3968 | 41 | public Q_SLOTS: | ||
3969 | 42 | void load(); | ||
3970 | 43 | |||
3971 | 44 | Q_SIGNALS: | ||
3972 | 45 | void finished(); | ||
3973 | 46 | void loaded(QSharedPointer<Printer> printer); | ||
3974 | 47 | }; | ||
3975 | 48 | |||
3976 | 49 | #endif // USC_PRINTERS_CUPS_PRINTERLOADER_H | ||
3977 | 0 | 50 | ||
3978 | === added file 'modules/Ubuntu/Components/Extras/Printers/enums.h' | |||
3979 | --- modules/Ubuntu/Components/Extras/Printers/enums.h 1970-01-01 00:00:00 +0000 | |||
3980 | +++ modules/Ubuntu/Components/Extras/Printers/enums.h 2017-02-22 12:44:26 +0000 | |||
3981 | @@ -0,0 +1,141 @@ | |||
3982 | 1 | /* | ||
3983 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3984 | 3 | * | ||
3985 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3986 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
3987 | 6 | * the Free Software Foundation; version 3. | ||
3988 | 7 | * | ||
3989 | 8 | * This program is distributed in the hope that it will be useful, | ||
3990 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3991 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3992 | 11 | * GNU Lesser General Public License for more details. | ||
3993 | 12 | * | ||
3994 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3995 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3996 | 15 | */ | ||
3997 | 16 | |||
3998 | 17 | #ifndef USC_PRINTERS_ENUMS_H | ||
3999 | 18 | #define USC_PRINTERS_ENUMS_H | ||
4000 | 19 | |||
4001 | 20 | #include "printers_global.h" | ||
4002 | 21 | |||
4003 | 22 | #include <QtCore/QObject> | ||
4004 | 23 | |||
4005 | 24 | class PRINTERS_DECL_EXPORT PrinterEnum | ||
4006 | 25 | { | ||
4007 | 26 | Q_GADGET | ||
4008 | 27 | |||
4009 | 28 | public: | ||
4010 | 29 | enum class AccessControl | ||
4011 | 30 | { | ||
4012 | 31 | AccessAllow = 0, | ||
4013 | 32 | AccessDeny, | ||
4014 | 33 | }; | ||
4015 | 34 | Q_ENUM(AccessControl) | ||
4016 | 35 | |||
4017 | 36 | enum class ColorModelType | ||
4018 | 37 | { | ||
4019 | 38 | GrayType = 0, | ||
4020 | 39 | ColorType, | ||
4021 | 40 | UnknownType, | ||
4022 | 41 | }; | ||
4023 | 42 | Q_ENUM(ColorModelType) | ||
4024 | 43 | |||
4025 | 44 | enum class ColorSpace | ||
4026 | 45 | { | ||
4027 | 46 | NSpace = 0, | ||
4028 | 47 | RGBSpace, | ||
4029 | 48 | RGBKSpace, | ||
4030 | 49 | GraySpace, | ||
4031 | 50 | CMYSpace, | ||
4032 | 51 | CMYKSpace, | ||
4033 | 52 | UnknownSpace, | ||
4034 | 53 | }; | ||
4035 | 54 | Q_ENUM(ColorSpace) | ||
4036 | 55 | |||
4037 | 56 | enum class ColorOrganization | ||
4038 | 57 | { | ||
4039 | 58 | ChunkyOrganization = 0, | ||
4040 | 59 | BandedOrganization, | ||
4041 | 60 | PlanarOrganization, | ||
4042 | 61 | UnknownOrganization, | ||
4043 | 62 | }; | ||
4044 | 63 | Q_ENUM(ColorOrganization) | ||
4045 | 64 | |||
4046 | 65 | enum class CartridgeType | ||
4047 | 66 | { | ||
4048 | 67 | BlackCartridge = 0, | ||
4049 | 68 | CyanCartridge, | ||
4050 | 69 | MagentaCartridge, | ||
4051 | 70 | YellowCartridge, | ||
4052 | 71 | RedCartridge, | ||
4053 | 72 | GreenCartridge, | ||
4054 | 73 | BlueCartridge, | ||
4055 | 74 | UnknownCartridge, | ||
4056 | 75 | WhiteCartridge, | ||
4057 | 76 | }; | ||
4058 | 77 | Q_ENUM(CartridgeType) | ||
4059 | 78 | |||
4060 | 79 | enum class DuplexMode | ||
4061 | 80 | { | ||
4062 | 81 | DuplexNone = 0, | ||
4063 | 82 | DuplexLongSide, | ||
4064 | 83 | DuplexShortSide, | ||
4065 | 84 | }; | ||
4066 | 85 | Q_ENUM(DuplexMode) | ||
4067 | 86 | |||
4068 | 87 | enum class ErrorPolicy | ||
4069 | 88 | { | ||
4070 | 89 | RetryOnError = 0, | ||
4071 | 90 | AbortOnError, | ||
4072 | 91 | StopPrinterOnError, | ||
4073 | 92 | RetryCurrentOnError, | ||
4074 | 93 | }; | ||
4075 | 94 | Q_ENUM(ErrorPolicy) | ||
4076 | 95 | |||
4077 | 96 | // Match enums from ipp_jstate_t | ||
4078 | 97 | enum class JobState | ||
4079 | 98 | { | ||
4080 | 99 | Pending = 3, | ||
4081 | 100 | Held, | ||
4082 | 101 | Processing, | ||
4083 | 102 | Stopped, | ||
4084 | 103 | Canceled, | ||
4085 | 104 | Aborted, | ||
4086 | 105 | Complete, | ||
4087 | 106 | }; | ||
4088 | 107 | Q_ENUM(JobState) | ||
4089 | 108 | |||
4090 | 109 | enum class OperationPolicy | ||
4091 | 110 | { | ||
4092 | 111 | DefaultOperation = 0, | ||
4093 | 112 | AuthenticatedOperation, | ||
4094 | 113 | }; | ||
4095 | 114 | Q_ENUM(OperationPolicy) | ||
4096 | 115 | |||
4097 | 116 | enum class PrintRange | ||
4098 | 117 | { | ||
4099 | 118 | AllPages = 0, | ||
4100 | 119 | PageRange, | ||
4101 | 120 | }; | ||
4102 | 121 | Q_ENUM(PrintRange) | ||
4103 | 122 | |||
4104 | 123 | enum class State | ||
4105 | 124 | { | ||
4106 | 125 | IdleState = 0, | ||
4107 | 126 | ActiveState, | ||
4108 | 127 | AbortedState, | ||
4109 | 128 | ErrorState, | ||
4110 | 129 | }; | ||
4111 | 130 | Q_ENUM(State) | ||
4112 | 131 | |||
4113 | 132 | enum class PrinterType | ||
4114 | 133 | { | ||
4115 | 134 | ProxyType = 0, // Represents a printer not yet loaded. | ||
4116 | 135 | CupsType, | ||
4117 | 136 | PdfType, | ||
4118 | 137 | }; | ||
4119 | 138 | Q_ENUM(PrinterType) | ||
4120 | 139 | }; | ||
4121 | 140 | |||
4122 | 141 | #endif // USC_PRINTERS_ENUMS_H | ||
4123 | 0 | 142 | ||
4124 | === added file 'modules/Ubuntu/Components/Extras/Printers/i18n.cpp' | |||
4125 | --- modules/Ubuntu/Components/Extras/Printers/i18n.cpp 1970-01-01 00:00:00 +0000 | |||
4126 | +++ modules/Ubuntu/Components/Extras/Printers/i18n.cpp 2017-02-22 12:44:26 +0000 | |||
4127 | @@ -0,0 +1,44 @@ | |||
4128 | 1 | /* | ||
4129 | 2 | * Copyright (C) 2014, 2017 Canonical, Ltd. | ||
4130 | 3 | * | ||
4131 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4132 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4133 | 6 | * the Free Software Foundation; version 3. | ||
4134 | 7 | * | ||
4135 | 8 | * This program is distributed in the hope that it will be useful, | ||
4136 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4137 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4138 | 11 | * GNU Lesser General Public License for more details. | ||
4139 | 12 | * | ||
4140 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4141 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4142 | 15 | * | ||
4143 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
4144 | 17 | * Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4145 | 18 | */ | ||
4146 | 19 | |||
4147 | 20 | #define NO_TR_OVERRIDE | ||
4148 | 21 | #include "i18n.h" | ||
4149 | 22 | |||
4150 | 23 | #include <libintl.h> | ||
4151 | 24 | |||
4152 | 25 | const char *thisDomain = ""; | ||
4153 | 26 | |||
4154 | 27 | void initTr(const char *domain, const char *localeDir) | ||
4155 | 28 | { | ||
4156 | 29 | // Don't bind the domain or set textdomain as it changes the Apps domain | ||
4157 | 30 | // as well. Instead store the domain and use it in the lookups | ||
4158 | 31 | // bindtextdomain(domain, localeDir); | ||
4159 | 32 | // textdomain(domain); | ||
4160 | 33 | Q_UNUSED(localeDir); | ||
4161 | 34 | |||
4162 | 35 | thisDomain = domain; | ||
4163 | 36 | } | ||
4164 | 37 | |||
4165 | 38 | QString __(const char *text, const char *domain) | ||
4166 | 39 | { | ||
4167 | 40 | Q_UNUSED(domain); | ||
4168 | 41 | |||
4169 | 42 | // Use the stored domain | ||
4170 | 43 | return QString::fromUtf8(dgettext(thisDomain, text)); | ||
4171 | 44 | } | ||
4172 | 0 | 45 | ||
4173 | === added file 'modules/Ubuntu/Components/Extras/Printers/i18n.h' | |||
4174 | --- modules/Ubuntu/Components/Extras/Printers/i18n.h 1970-01-01 00:00:00 +0000 | |||
4175 | +++ modules/Ubuntu/Components/Extras/Printers/i18n.h 2017-02-22 12:44:26 +0000 | |||
4176 | @@ -0,0 +1,29 @@ | |||
4177 | 1 | /* | ||
4178 | 2 | * Copyright (C) 2014, 2017 Canonical, Ltd. | ||
4179 | 3 | * | ||
4180 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4181 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4182 | 6 | * the Free Software Foundation; version 3. | ||
4183 | 7 | * | ||
4184 | 8 | * This program is distributed in the hope that it will be useful, | ||
4185 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4186 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4187 | 11 | * GNU Lesser General Public License for more details. | ||
4188 | 12 | * | ||
4189 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4190 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4191 | 15 | * | ||
4192 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
4193 | 17 | * Andrew Hayzen <andrew.hayzen@canonical.com> | ||
4194 | 18 | */ | ||
4195 | 19 | |||
4196 | 20 | #ifndef I18N_H | ||
4197 | 21 | #define I18N_H | ||
4198 | 22 | |||
4199 | 23 | #include <QtCore/QString> | ||
4200 | 24 | |||
4201 | 25 | void initTr(const char *domain, const char *localeDir); | ||
4202 | 26 | QString __(const char *text, const char *domain = 0); | ||
4203 | 27 | |||
4204 | 28 | #endif // I18N_H | ||
4205 | 29 | |||
4206 | 0 | 30 | ||
4207 | === added directory 'modules/Ubuntu/Components/Extras/Printers/models' | |||
4208 | === added file 'modules/Ubuntu/Components/Extras/Printers/models/drivermodel.cpp' | |||
4209 | --- modules/Ubuntu/Components/Extras/Printers/models/drivermodel.cpp 1970-01-01 00:00:00 +0000 | |||
4210 | +++ modules/Ubuntu/Components/Extras/Printers/models/drivermodel.cpp 2017-02-22 12:44:26 +0000 | |||
4211 | @@ -0,0 +1,175 @@ | |||
4212 | 1 | /* | ||
4213 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
4214 | 3 | * | ||
4215 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4216 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4217 | 6 | * the Free Software Foundation; version 3. | ||
4218 | 7 | * | ||
4219 | 8 | * This program is distributed in the hope that it will be useful, | ||
4220 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4221 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4222 | 11 | * GNU Lesser General Public License for more details. | ||
4223 | 12 | * | ||
4224 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4225 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4226 | 15 | */ | ||
4227 | 16 | |||
4228 | 17 | #include "backend/backend_cups.h" | ||
4229 | 18 | #include "models/drivermodel.h" | ||
4230 | 19 | |||
4231 | 20 | #include <QDebug> | ||
4232 | 21 | #include <QtConcurrent> | ||
4233 | 22 | |||
4234 | 23 | DriverModel::DriverModel(PrinterBackend *backend, QObject *parent) | ||
4235 | 24 | : QAbstractListModel(parent) | ||
4236 | 25 | , m_backend(backend) | ||
4237 | 26 | { | ||
4238 | 27 | connect(m_backend, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&)), | ||
4239 | 28 | this, SLOT(printerDriversLoaded(const QList<PrinterDriver>&))); | ||
4240 | 29 | |||
4241 | 30 | QObject::connect(&m_watcher, | ||
4242 | 31 | &QFutureWatcher<PrinterDriver>::finished, | ||
4243 | 32 | this, | ||
4244 | 33 | &DriverModel::filterFinished); | ||
4245 | 34 | |||
4246 | 35 | } | ||
4247 | 36 | |||
4248 | 37 | DriverModel::~DriverModel() | ||
4249 | 38 | { | ||
4250 | 39 | cancel(); | ||
4251 | 40 | } | ||
4252 | 41 | |||
4253 | 42 | int DriverModel::rowCount(const QModelIndex &parent) const | ||
4254 | 43 | { | ||
4255 | 44 | Q_UNUSED(parent); | ||
4256 | 45 | return m_drivers.size(); | ||
4257 | 46 | } | ||
4258 | 47 | |||
4259 | 48 | int DriverModel::count() const | ||
4260 | 49 | { | ||
4261 | 50 | return rowCount(); | ||
4262 | 51 | } | ||
4263 | 52 | |||
4264 | 53 | QVariant DriverModel::data(const QModelIndex &index, int role) const | ||
4265 | 54 | { | ||
4266 | 55 | QVariant ret; | ||
4267 | 56 | |||
4268 | 57 | if ((0 <= index.row()) && (index.row() < m_drivers.size())) { | ||
4269 | 58 | |||
4270 | 59 | auto driver = m_drivers[index.row()]; | ||
4271 | 60 | |||
4272 | 61 | switch (role) { | ||
4273 | 62 | case Qt::DisplayRole: | ||
4274 | 63 | ret = driver.toString(); | ||
4275 | 64 | break; | ||
4276 | 65 | case NameRole: | ||
4277 | 66 | ret = driver.name; | ||
4278 | 67 | break; | ||
4279 | 68 | case DeviceIdRole: | ||
4280 | 69 | ret = driver.deviceId; | ||
4281 | 70 | break; | ||
4282 | 71 | case LanguageRole: | ||
4283 | 72 | ret = driver.language; | ||
4284 | 73 | break; | ||
4285 | 74 | case MakeModelRole: | ||
4286 | 75 | ret = driver.makeModel; | ||
4287 | 76 | break; | ||
4288 | 77 | } | ||
4289 | 78 | } | ||
4290 | 79 | |||
4291 | 80 | return ret; | ||
4292 | 81 | } | ||
4293 | 82 | |||
4294 | 83 | QHash<int, QByteArray> DriverModel::roleNames() const | ||
4295 | 84 | { | ||
4296 | 85 | static QHash<int,QByteArray> names; | ||
4297 | 86 | |||
4298 | 87 | if (Q_UNLIKELY(names.empty())) { | ||
4299 | 88 | names[Qt::DisplayRole] = "displayName"; | ||
4300 | 89 | names[NameRole] = "name"; | ||
4301 | 90 | names[DeviceIdRole] = "deviceId"; | ||
4302 | 91 | names[LanguageRole] = "language"; | ||
4303 | 92 | names[MakeModelRole] = "makeModel"; | ||
4304 | 93 | } | ||
4305 | 94 | |||
4306 | 95 | return names; | ||
4307 | 96 | } | ||
4308 | 97 | |||
4309 | 98 | void DriverModel::setFilter(const QString& pattern) | ||
4310 | 99 | { | ||
4311 | 100 | QList<QByteArray> needles; | ||
4312 | 101 | Q_FOREACH(const QString patternPart, pattern.toLower().split(" ")) { | ||
4313 | 102 | needles.append(patternPart.toUtf8()); | ||
4314 | 103 | } | ||
4315 | 104 | QList<PrinterDriver> list; | ||
4316 | 105 | |||
4317 | 106 | if (m_watcher.isRunning()) | ||
4318 | 107 | m_watcher.cancel(); | ||
4319 | 108 | |||
4320 | 109 | if (pattern.isEmpty()) { | ||
4321 | 110 | setModel(m_originalDrivers); | ||
4322 | 111 | m_filter = pattern; | ||
4323 | 112 | return; | ||
4324 | 113 | } | ||
4325 | 114 | |||
4326 | 115 | if (!m_filter.isEmpty() && !m_drivers.isEmpty() && | ||
4327 | 116 | pattern.startsWith(m_filter)) | ||
4328 | 117 | list = m_drivers; // search in the smaller list | ||
4329 | 118 | else | ||
4330 | 119 | list = m_originalDrivers; //search in the whole list | ||
4331 | 120 | |||
4332 | 121 | m_filter = pattern; | ||
4333 | 122 | |||
4334 | 123 | QFuture<PrinterDriver> future(QtConcurrent::filtered(list, | ||
4335 | 124 | [needles] (const PrinterDriver &driver) { | ||
4336 | 125 | QByteArray haystack = driver.makeModel.toLower(); | ||
4337 | 126 | Q_FOREACH(const QByteArray needle, needles) { | ||
4338 | 127 | if (!haystack.contains(needle)) { | ||
4339 | 128 | return false; | ||
4340 | 129 | } | ||
4341 | 130 | } | ||
4342 | 131 | return true; | ||
4343 | 132 | } | ||
4344 | 133 | ) | ||
4345 | 134 | ); | ||
4346 | 135 | |||
4347 | 136 | Q_EMIT filterBegin(); | ||
4348 | 137 | |||
4349 | 138 | m_watcher.setFuture(future); | ||
4350 | 139 | } | ||
4351 | 140 | |||
4352 | 141 | QString DriverModel::filter() const | ||
4353 | 142 | { | ||
4354 | 143 | return m_filter; | ||
4355 | 144 | } | ||
4356 | 145 | |||
4357 | 146 | void DriverModel::filterFinished() | ||
4358 | 147 | { | ||
4359 | 148 | setModel(m_watcher.future().results()); | ||
4360 | 149 | } | ||
4361 | 150 | |||
4362 | 151 | void DriverModel::load() | ||
4363 | 152 | { | ||
4364 | 153 | m_backend->requestPrinterDrivers(); | ||
4365 | 154 | } | ||
4366 | 155 | |||
4367 | 156 | void DriverModel::cancel() | ||
4368 | 157 | { | ||
4369 | 158 | if (m_watcher.isRunning()) | ||
4370 | 159 | m_watcher.cancel(); | ||
4371 | 160 | } | ||
4372 | 161 | |||
4373 | 162 | void DriverModel::printerDriversLoaded(const QList<PrinterDriver> &drivers) | ||
4374 | 163 | { | ||
4375 | 164 | m_originalDrivers = drivers; | ||
4376 | 165 | setModel(m_originalDrivers); | ||
4377 | 166 | } | ||
4378 | 167 | |||
4379 | 168 | void DriverModel::setModel(const QList<PrinterDriver> &drivers) | ||
4380 | 169 | { | ||
4381 | 170 | beginResetModel(); | ||
4382 | 171 | m_drivers = drivers; | ||
4383 | 172 | endResetModel(); | ||
4384 | 173 | |||
4385 | 174 | Q_EMIT filterComplete(); | ||
4386 | 175 | } | ||
4387 | 0 | 176 | ||
4388 | === added file 'modules/Ubuntu/Components/Extras/Printers/models/drivermodel.h' | |||
4389 | --- modules/Ubuntu/Components/Extras/Printers/models/drivermodel.h 1970-01-01 00:00:00 +0000 | |||
4390 | +++ modules/Ubuntu/Components/Extras/Printers/models/drivermodel.h 2017-02-22 12:44:26 +0000 | |||
4391 | @@ -0,0 +1,82 @@ | |||
4392 | 1 | /* | ||
4393 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
4394 | 3 | * | ||
4395 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4396 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4397 | 6 | * the Free Software Foundation; version 3. | ||
4398 | 7 | * | ||
4399 | 8 | * This program is distributed in the hope that it will be useful, | ||
4400 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4401 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4402 | 11 | * GNU Lesser General Public License for more details. | ||
4403 | 12 | * | ||
4404 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4405 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4406 | 15 | */ | ||
4407 | 16 | |||
4408 | 17 | #ifndef USC_PRINTER_DRIVERMODEL_H | ||
4409 | 18 | #define USC_PRINTER_DRIVERMODEL_H | ||
4410 | 19 | |||
4411 | 20 | #include "printers_global.h" | ||
4412 | 21 | |||
4413 | 22 | #include "structs.h" | ||
4414 | 23 | |||
4415 | 24 | #include <QAbstractListModel> | ||
4416 | 25 | #include <QFutureWatcher> | ||
4417 | 26 | #include <QModelIndex> | ||
4418 | 27 | #include <QObject> | ||
4419 | 28 | #include <QVariant> | ||
4420 | 29 | |||
4421 | 30 | class PRINTERS_DECL_EXPORT DriverModel : public QAbstractListModel | ||
4422 | 31 | { | ||
4423 | 32 | Q_OBJECT | ||
4424 | 33 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
4425 | 34 | public: | ||
4426 | 35 | explicit DriverModel(PrinterBackend *backend, QObject *parent = Q_NULLPTR); | ||
4427 | 36 | ~DriverModel(); | ||
4428 | 37 | |||
4429 | 38 | enum Roles | ||
4430 | 39 | { | ||
4431 | 40 | // Qt::DisplayRole holds driver name | ||
4432 | 41 | NameRole = Qt::UserRole, | ||
4433 | 42 | DeviceIdRole, | ||
4434 | 43 | LanguageRole, | ||
4435 | 44 | MakeModelRole, | ||
4436 | 45 | LastRole = MakeModelRole, | ||
4437 | 46 | }; | ||
4438 | 47 | |||
4439 | 48 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
4440 | 49 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
4441 | 50 | virtual QHash<int, QByteArray> roleNames() const override; | ||
4442 | 51 | |||
4443 | 52 | int count() const; | ||
4444 | 53 | |||
4445 | 54 | QString filter() const; | ||
4446 | 55 | void setFilter(const QString& pattern); | ||
4447 | 56 | |||
4448 | 57 | public Q_SLOTS: | ||
4449 | 58 | // Start loading the model. | ||
4450 | 59 | void load(); | ||
4451 | 60 | |||
4452 | 61 | // Cancel loading of the model. | ||
4453 | 62 | void cancel(); | ||
4454 | 63 | |||
4455 | 64 | private Q_SLOTS: | ||
4456 | 65 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); | ||
4457 | 66 | void filterFinished(); | ||
4458 | 67 | |||
4459 | 68 | Q_SIGNALS: | ||
4460 | 69 | void countChanged(); | ||
4461 | 70 | void filterBegin(); | ||
4462 | 71 | void filterComplete(); | ||
4463 | 72 | |||
4464 | 73 | private: | ||
4465 | 74 | void setModel(const QList<PrinterDriver> &drivers); | ||
4466 | 75 | PrinterBackend *m_backend; | ||
4467 | 76 | QList<PrinterDriver> m_drivers; | ||
4468 | 77 | QList<PrinterDriver> m_originalDrivers; | ||
4469 | 78 | QString m_filter; | ||
4470 | 79 | QFutureWatcher<PrinterDriver> m_watcher; | ||
4471 | 80 | }; | ||
4472 | 81 | |||
4473 | 82 | #endif // USC_PRINTER_DRIVERMODEL_H | ||
4474 | 0 | 83 | ||
4475 | === added file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp' | |||
4476 | --- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 1970-01-01 00:00:00 +0000 | |||
4477 | +++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 2017-02-22 12:44:26 +0000 | |||
4478 | @@ -0,0 +1,391 @@ | |||
4479 | 1 | /* | ||
4480 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
4481 | 3 | * | ||
4482 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4483 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4484 | 6 | * the Free Software Foundation; version 3. | ||
4485 | 7 | * | ||
4486 | 8 | * This program is distributed in the hope that it will be useful, | ||
4487 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4488 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4489 | 11 | * GNU Lesser General Public License for more details. | ||
4490 | 12 | * | ||
4491 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4492 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4493 | 15 | */ | ||
4494 | 16 | |||
4495 | 17 | #include "utils.h" | ||
4496 | 18 | |||
4497 | 19 | #include "backend/backend_cups.h" | ||
4498 | 20 | |||
4499 | 21 | #include "models/jobmodel.h" | ||
4500 | 22 | |||
4501 | 23 | #include <QDebug> | ||
4502 | 24 | |||
4503 | 25 | JobModel::JobModel(QObject *parent) : QAbstractListModel(parent) | ||
4504 | 26 | { | ||
4505 | 27 | } | ||
4506 | 28 | |||
4507 | 29 | JobModel::JobModel(PrinterBackend *backend, | ||
4508 | 30 | QObject *parent) | ||
4509 | 31 | : QAbstractListModel(parent) | ||
4510 | 32 | , m_backend(backend) | ||
4511 | 33 | { | ||
4512 | 34 | update(); | ||
4513 | 35 | |||
4514 | 36 | QObject::connect(m_backend, &PrinterBackend::jobCreated, | ||
4515 | 37 | this, &JobModel::jobSignalCatchAll); | ||
4516 | 38 | QObject::connect(m_backend, &PrinterBackend::jobState, | ||
4517 | 39 | this, &JobModel::jobSignalCatchAll); | ||
4518 | 40 | QObject::connect(m_backend, &PrinterBackend::jobCompleted, | ||
4519 | 41 | this, &JobModel::jobSignalCatchAll); | ||
4520 | 42 | } | ||
4521 | 43 | |||
4522 | 44 | JobModel::~JobModel() | ||
4523 | 45 | { | ||
4524 | 46 | } | ||
4525 | 47 | |||
4526 | 48 | void JobModel::jobSignalCatchAll( | ||
4527 | 49 | const QString &text, const QString &printer_uri, | ||
4528 | 50 | const QString &printer_name, uint printer_state, | ||
4529 | 51 | const QString &printer_state_reasons, bool printer_is_accepting_jobs, | ||
4530 | 52 | uint job_id, uint job_state, const QString &job_state_reasons, | ||
4531 | 53 | const QString &job_name, uint job_impressions_completed) | ||
4532 | 54 | { | ||
4533 | 55 | Q_UNUSED(text); | ||
4534 | 56 | Q_UNUSED(printer_uri); | ||
4535 | 57 | Q_UNUSED(printer_name); | ||
4536 | 58 | Q_UNUSED(printer_state); | ||
4537 | 59 | Q_UNUSED(printer_state_reasons); | ||
4538 | 60 | Q_UNUSED(printer_is_accepting_jobs); | ||
4539 | 61 | Q_UNUSED(job_id); | ||
4540 | 62 | Q_UNUSED(job_state); | ||
4541 | 63 | Q_UNUSED(job_state_reasons); | ||
4542 | 64 | Q_UNUSED(job_name); | ||
4543 | 65 | Q_UNUSED(job_impressions_completed); | ||
4544 | 66 | |||
4545 | 67 | auto job = getJobById(job_id); | ||
4546 | 68 | if (job) | ||
4547 | 69 | job->setImpressionsCompleted(job_impressions_completed); | ||
4548 | 70 | |||
4549 | 71 | update(); | ||
4550 | 72 | } | ||
4551 | 73 | |||
4552 | 74 | void JobModel::update() | ||
4553 | 75 | { | ||
4554 | 76 | // Store the old count and get the new printers | ||
4555 | 77 | int oldCount = m_jobs.size(); | ||
4556 | 78 | QList<QSharedPointer<PrinterJob>> newJobs = m_backend->printerGetJobs(); | ||
4557 | 79 | |||
4558 | 80 | // Go through the old model | ||
4559 | 81 | for (int i=0; i < m_jobs.count(); i++) { | ||
4560 | 82 | // Determine if the old printer exists in the new model | ||
4561 | 83 | bool exists = false; | ||
4562 | 84 | |||
4563 | 85 | Q_FOREACH(QSharedPointer<PrinterJob> p, newJobs) { | ||
4564 | 86 | if (p->jobId() == m_jobs.at(i)->jobId()) { | ||
4565 | 87 | exists = true; | ||
4566 | 88 | |||
4567 | 89 | // Ensure the other properties of the job are up to date | ||
4568 | 90 | if (!m_jobs.at(i)->deepCompare(p)) { | ||
4569 | 91 | m_jobs.at(i)->updateFrom(p); | ||
4570 | 92 | |||
4571 | 93 | Q_EMIT dataChanged(index(i), index(i)); | ||
4572 | 94 | } | ||
4573 | 95 | |||
4574 | 96 | break; | ||
4575 | 97 | } | ||
4576 | 98 | } | ||
4577 | 99 | |||
4578 | 100 | // If it doesn't exist then remove it from the old model | ||
4579 | 101 | if (!exists) { | ||
4580 | 102 | beginRemoveRows(QModelIndex(), i, i); | ||
4581 | 103 | QSharedPointer<PrinterJob> p = m_jobs.takeAt(i); | ||
4582 | 104 | endRemoveRows(); | ||
4583 | 105 | |||
4584 | 106 | i--; // as we have removed an item decrement | ||
4585 | 107 | } | ||
4586 | 108 | } | ||
4587 | 109 | |||
4588 | 110 | // Go through the new model | ||
4589 | 111 | for (int i=0; i < newJobs.count(); i++) { | ||
4590 | 112 | // Determine if the new printer exists in the old model | ||
4591 | 113 | bool exists = false; | ||
4592 | 114 | int j; | ||
4593 | 115 | |||
4594 | 116 | for (j=0; j < m_jobs.count(); j++) { | ||
4595 | 117 | if (m_jobs.at(j)->jobId() == newJobs.at(i)->jobId()) { | ||
4596 | 118 | exists = true; | ||
4597 | 119 | break; | ||
4598 | 120 | } | ||
4599 | 121 | } | ||
4600 | 122 | |||
4601 | 123 | if (exists) { | ||
4602 | 124 | if (j == i) { // New printer exists and in correct position | ||
4603 | 125 | continue; | ||
4604 | 126 | } else { | ||
4605 | 127 | // New printer does exist but needs to be moved in old model | ||
4606 | 128 | beginMoveRows(QModelIndex(), j, 1, QModelIndex(), i); | ||
4607 | 129 | m_jobs.move(j, i); | ||
4608 | 130 | endMoveRows(); | ||
4609 | 131 | } | ||
4610 | 132 | } else { | ||
4611 | 133 | // New printer does not exist insert into model | ||
4612 | 134 | beginInsertRows(QModelIndex(), i, i); | ||
4613 | 135 | m_jobs.insert(i, newJobs.at(i)); | ||
4614 | 136 | endInsertRows(); | ||
4615 | 137 | } | ||
4616 | 138 | } | ||
4617 | 139 | |||
4618 | 140 | if (oldCount != m_jobs.size()) { | ||
4619 | 141 | Q_EMIT countChanged(); | ||
4620 | 142 | } | ||
4621 | 143 | } | ||
4622 | 144 | |||
4623 | 145 | int JobModel::rowCount(const QModelIndex &parent) const | ||
4624 | 146 | { | ||
4625 | 147 | Q_UNUSED(parent); | ||
4626 | 148 | return m_jobs.size(); | ||
4627 | 149 | } | ||
4628 | 150 | |||
4629 | 151 | int JobModel::count() const | ||
4630 | 152 | { | ||
4631 | 153 | return rowCount(); | ||
4632 | 154 | } | ||
4633 | 155 | |||
4634 | 156 | QVariant JobModel::data(const QModelIndex &index, int role) const | ||
4635 | 157 | { | ||
4636 | 158 | QVariant ret; | ||
4637 | 159 | |||
4638 | 160 | if ((0<=index.row()) && (index.row()<m_jobs.size())) { | ||
4639 | 161 | |||
4640 | 162 | auto job = m_jobs[index.row()]; | ||
4641 | 163 | |||
4642 | 164 | switch (role) { | ||
4643 | 165 | case CollateRole: | ||
4644 | 166 | ret = job->collate(); | ||
4645 | 167 | break; | ||
4646 | 168 | case ColorModelRole: { | ||
4647 | 169 | if (job->printer()) { | ||
4648 | 170 | ret = job->printer()->supportedColorModels().at(job->colorModel()).text; | ||
4649 | 171 | } else { | ||
4650 | 172 | qWarning() << "Printer is undefined, no colorModel"; | ||
4651 | 173 | ret = ""; | ||
4652 | 174 | } | ||
4653 | 175 | break; | ||
4654 | 176 | } | ||
4655 | 177 | case CompletedTimeRole: | ||
4656 | 178 | ret = job->completedTime().toString(QLocale::system().dateTimeFormat()); | ||
4657 | 179 | break; | ||
4658 | 180 | case CopiesRole: | ||
4659 | 181 | ret = job->copies(); | ||
4660 | 182 | break; | ||
4661 | 183 | case CreationTimeRole: | ||
4662 | 184 | ret = job->creationTime().toString(QLocale::system().dateTimeFormat()); | ||
4663 | 185 | break; | ||
4664 | 186 | case DuplexRole: { | ||
4665 | 187 | if (job->printer()) { | ||
4666 | 188 | ret = job->printer()->supportedDuplexStrings().at(job->duplexMode()); | ||
4667 | 189 | } else { | ||
4668 | 190 | qWarning() << "Printer is undefined, no duplexMode"; | ||
4669 | 191 | ret = ""; | ||
4670 | 192 | } | ||
4671 | 193 | break; | ||
4672 | 194 | } | ||
4673 | 195 | case IdRole: | ||
4674 | 196 | ret = job->jobId(); | ||
4675 | 197 | break; | ||
4676 | 198 | case ImpressionsCompletedRole: | ||
4677 | 199 | ret = job->impressionsCompleted(); | ||
4678 | 200 | break; | ||
4679 | 201 | case LandscapeRole: | ||
4680 | 202 | ret = job->landscape(); | ||
4681 | 203 | break; | ||
4682 | 204 | case MessagesRole: | ||
4683 | 205 | ret = job->messages(); | ||
4684 | 206 | break; | ||
4685 | 207 | case PrinterNameRole: | ||
4686 | 208 | ret = job->printerName(); | ||
4687 | 209 | break; | ||
4688 | 210 | case PrintRangeRole: | ||
4689 | 211 | ret = job->printRange(); | ||
4690 | 212 | break; | ||
4691 | 213 | case PrintRangeModeRole: | ||
4692 | 214 | ret = QVariant::fromValue<PrinterEnum::PrintRange>(job->printRangeMode()); | ||
4693 | 215 | break; | ||
4694 | 216 | case ProcessingTimeRole: | ||
4695 | 217 | ret = job->processingTime().toString(QLocale::system().dateTimeFormat()); | ||
4696 | 218 | break; | ||
4697 | 219 | case QualityRole: { | ||
4698 | 220 | if (job->printer()) { | ||
4699 | 221 | ret = job->printer()->supportedPrintQualities().at(job->quality()).text; | ||
4700 | 222 | } else { | ||
4701 | 223 | qWarning() << "Printer is undefined, no quality"; | ||
4702 | 224 | ret = ""; | ||
4703 | 225 | } | ||
4704 | 226 | break; | ||
4705 | 227 | } | ||
4706 | 228 | case ReverseRole: | ||
4707 | 229 | ret = job->reverse(); | ||
4708 | 230 | break; | ||
4709 | 231 | case SizeRole: | ||
4710 | 232 | ret = job->size(); | ||
4711 | 233 | break; | ||
4712 | 234 | case StateRole: | ||
4713 | 235 | // TODO: improve, for now have a switch | ||
4714 | 236 | switch (job->state()) { | ||
4715 | 237 | case PrinterEnum::JobState::Aborted: | ||
4716 | 238 | ret = "Aborted"; | ||
4717 | 239 | break; | ||
4718 | 240 | case PrinterEnum::JobState::Canceled: | ||
4719 | 241 | ret = "Canceled"; | ||
4720 | 242 | break; | ||
4721 | 243 | case PrinterEnum::JobState::Complete: | ||
4722 | 244 | ret = "Compelete"; | ||
4723 | 245 | break; | ||
4724 | 246 | case PrinterEnum::JobState::Held: | ||
4725 | 247 | ret = "Held"; | ||
4726 | 248 | break; | ||
4727 | 249 | case PrinterEnum::JobState::Pending: | ||
4728 | 250 | ret = "Pending"; | ||
4729 | 251 | break; | ||
4730 | 252 | case PrinterEnum::JobState::Processing: | ||
4731 | 253 | ret = "Processing"; | ||
4732 | 254 | break; | ||
4733 | 255 | case PrinterEnum::JobState::Stopped: | ||
4734 | 256 | ret = "Stopped"; | ||
4735 | 257 | break; | ||
4736 | 258 | } | ||
4737 | 259 | break; | ||
4738 | 260 | case Qt::DisplayRole: | ||
4739 | 261 | case TitleRole: | ||
4740 | 262 | ret = job->title(); | ||
4741 | 263 | break; | ||
4742 | 264 | case UserRole: | ||
4743 | 265 | ret = job->user(); | ||
4744 | 266 | break; | ||
4745 | 267 | } | ||
4746 | 268 | } | ||
4747 | 269 | |||
4748 | 270 | return ret; | ||
4749 | 271 | } | ||
4750 | 272 | |||
4751 | 273 | QHash<int, QByteArray> JobModel::roleNames() const | ||
4752 | 274 | { | ||
4753 | 275 | static QHash<int,QByteArray> names; | ||
4754 | 276 | |||
4755 | 277 | if (Q_UNLIKELY(names.empty())) { | ||
4756 | 278 | names[Qt::DisplayRole] = "displayName"; | ||
4757 | 279 | names[IdRole] = "id"; | ||
4758 | 280 | names[CollateRole] = "collate"; | ||
4759 | 281 | names[ColorModelRole] = "colorModel"; | ||
4760 | 282 | names[CompletedTimeRole] = "completedTime"; | ||
4761 | 283 | names[CopiesRole] = "copies"; | ||
4762 | 284 | names[CreationTimeRole] = "creationTime"; | ||
4763 | 285 | names[DuplexRole] = "duplexMode"; | ||
4764 | 286 | names[ImpressionsCompletedRole] = "impressionsCompleted"; | ||
4765 | 287 | names[LandscapeRole] = "landscape"; | ||
4766 | 288 | names[MessagesRole] = "messages"; | ||
4767 | 289 | names[PrinterNameRole] = "printerName"; | ||
4768 | 290 | names[PrintRangeRole] = "printRange"; | ||
4769 | 291 | names[PrintRangeModeRole] = "printRangeMode"; | ||
4770 | 292 | names[ProcessingTimeRole] = "processingTime"; | ||
4771 | 293 | names[QualityRole] = "quality"; | ||
4772 | 294 | names[ReverseRole] = "reverse"; | ||
4773 | 295 | names[SizeRole] = "size"; | ||
4774 | 296 | names[StateRole] = "state"; | ||
4775 | 297 | names[TitleRole] = "title"; | ||
4776 | 298 | names[UserRole] = "user"; | ||
4777 | 299 | names[LastStateMessageRole] = "lastStateMessage"; | ||
4778 | 300 | } | ||
4779 | 301 | |||
4780 | 302 | return names; | ||
4781 | 303 | } | ||
4782 | 304 | |||
4783 | 305 | QVariantMap JobModel::get(const int row) const | ||
4784 | 306 | { | ||
4785 | 307 | QHashIterator<int, QByteArray> iterator(roleNames()); | ||
4786 | 308 | QVariantMap result; | ||
4787 | 309 | QModelIndex modelIndex = index(row, 0); | ||
4788 | 310 | |||
4789 | 311 | while (iterator.hasNext()) { | ||
4790 | 312 | iterator.next(); | ||
4791 | 313 | result[iterator.value()] = modelIndex.data(iterator.key()); | ||
4792 | 314 | } | ||
4793 | 315 | |||
4794 | 316 | return result; | ||
4795 | 317 | } | ||
4796 | 318 | |||
4797 | 319 | QSharedPointer<PrinterJob> JobModel::getJobById(const int &id) | ||
4798 | 320 | { | ||
4799 | 321 | Q_FOREACH(auto job, m_jobs) { | ||
4800 | 322 | if (job->jobId() == id) { | ||
4801 | 323 | return job; | ||
4802 | 324 | } | ||
4803 | 325 | } | ||
4804 | 326 | return QSharedPointer<PrinterJob>(Q_NULLPTR); | ||
4805 | 327 | } | ||
4806 | 328 | |||
4807 | 329 | |||
4808 | 330 | JobFilter::JobFilter(QObject *parent) : QSortFilterProxyModel(parent) | ||
4809 | 331 | { | ||
4810 | 332 | connect(this, SIGNAL(sourceModelChanged()), SLOT(onSourceModelChanged())); | ||
4811 | 333 | } | ||
4812 | 334 | |||
4813 | 335 | JobFilter::~JobFilter() | ||
4814 | 336 | { | ||
4815 | 337 | } | ||
4816 | 338 | |||
4817 | 339 | QVariantMap JobFilter::get(const int row) const | ||
4818 | 340 | { | ||
4819 | 341 | QHashIterator<int, QByteArray> iterator(roleNames()); | ||
4820 | 342 | QVariantMap result; | ||
4821 | 343 | QModelIndex modelIndex = index(row, 0); | ||
4822 | 344 | |||
4823 | 345 | while (iterator.hasNext()) { | ||
4824 | 346 | iterator.next(); | ||
4825 | 347 | result[iterator.value()] = modelIndex.data(iterator.key()); | ||
4826 | 348 | } | ||
4827 | 349 | |||
4828 | 350 | return result; | ||
4829 | 351 | } | ||
4830 | 352 | |||
4831 | 353 | void JobFilter::onSourceModelChanged() | ||
4832 | 354 | { | ||
4833 | 355 | connect((JobModel*) sourceModel(), | ||
4834 | 356 | SIGNAL(countChanged()), | ||
4835 | 357 | this, | ||
4836 | 358 | SIGNAL(countChanged())); | ||
4837 | 359 | } | ||
4838 | 360 | |||
4839 | 361 | void JobFilter::onSourceModelCountChanged() | ||
4840 | 362 | { | ||
4841 | 363 | Q_EMIT countChanged(); | ||
4842 | 364 | } | ||
4843 | 365 | |||
4844 | 366 | int JobFilter::count() const | ||
4845 | 367 | { | ||
4846 | 368 | return rowCount(); | ||
4847 | 369 | } | ||
4848 | 370 | |||
4849 | 371 | void JobFilter::filterOnPrinterName(const QString &name) | ||
4850 | 372 | { | ||
4851 | 373 | m_printerName = name; | ||
4852 | 374 | m_printerNameFilterEnabled = true; | ||
4853 | 375 | invalidate(); | ||
4854 | 376 | } | ||
4855 | 377 | |||
4856 | 378 | bool JobFilter::filterAcceptsRow(int sourceRow, | ||
4857 | 379 | const QModelIndex &sourceParent) const | ||
4858 | 380 | { | ||
4859 | 381 | bool accepts = true; | ||
4860 | 382 | QModelIndex childIndex = sourceModel()->index(sourceRow, 0, sourceParent); | ||
4861 | 383 | |||
4862 | 384 | if (accepts && m_printerNameFilterEnabled) { | ||
4863 | 385 | QString printerName = childIndex.model()->data( | ||
4864 | 386 | childIndex, JobModel::PrinterNameRole).toString(); | ||
4865 | 387 | accepts = m_printerName == printerName; | ||
4866 | 388 | } | ||
4867 | 389 | |||
4868 | 390 | return accepts; | ||
4869 | 391 | } | ||
4870 | 0 | 392 | ||
4871 | === added file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h' | |||
4872 | --- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 1970-01-01 00:00:00 +0000 | |||
4873 | +++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 2017-02-22 12:44:26 +0000 | |||
4874 | @@ -0,0 +1,125 @@ | |||
4875 | 1 | /* | ||
4876 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
4877 | 3 | * | ||
4878 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4879 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
4880 | 6 | * the Free Software Foundation; version 3. | ||
4881 | 7 | * | ||
4882 | 8 | * This program is distributed in the hope that it will be useful, | ||
4883 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4884 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4885 | 11 | * GNU Lesser General Public License for more details. | ||
4886 | 12 | * | ||
4887 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
4888 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4889 | 15 | */ | ||
4890 | 16 | |||
4891 | 17 | #ifndef USC_JOB_MODEL_H | ||
4892 | 18 | #define USC_JOB_MODEL_H | ||
4893 | 19 | |||
4894 | 20 | #include "printers_global.h" | ||
4895 | 21 | #include "backend/backend.h" | ||
4896 | 22 | #include "printer/printerjob.h" | ||
4897 | 23 | |||
4898 | 24 | #include <QAbstractListModel> | ||
4899 | 25 | #include <QByteArray> | ||
4900 | 26 | #include <QModelIndex> | ||
4901 | 27 | #include <QObject> | ||
4902 | 28 | #include <QSharedPointer> | ||
4903 | 29 | #include <QSortFilterProxyModel> | ||
4904 | 30 | #include <QTimer> | ||
4905 | 31 | #include <QVariant> | ||
4906 | 32 | |||
4907 | 33 | class PRINTERS_DECL_EXPORT JobModel : public QAbstractListModel | ||
4908 | 34 | { | ||
4909 | 35 | Q_OBJECT | ||
4910 | 36 | |||
4911 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
4912 | 38 | public: | ||
4913 | 39 | explicit JobModel(QObject *parent = Q_NULLPTR); | ||
4914 | 40 | explicit JobModel(PrinterBackend *backend, | ||
4915 | 41 | QObject *parent = Q_NULLPTR); | ||
4916 | 42 | ~JobModel(); | ||
4917 | 43 | |||
4918 | 44 | enum Roles | ||
4919 | 45 | { | ||
4920 | 46 | // Qt::DisplayRole holds job title | ||
4921 | 47 | IdRole = Qt::UserRole, | ||
4922 | 48 | CollateRole, | ||
4923 | 49 | ColorModelRole, | ||
4924 | 50 | CompletedTimeRole, | ||
4925 | 51 | CopiesRole, | ||
4926 | 52 | CreationTimeRole, | ||
4927 | 53 | DuplexRole, | ||
4928 | 54 | ImpressionsCompletedRole, | ||
4929 | 55 | LandscapeRole, | ||
4930 | 56 | MessagesRole, | ||
4931 | 57 | PrinterNameRole, | ||
4932 | 58 | PrintRangeRole, | ||
4933 | 59 | PrintRangeModeRole, | ||
4934 | 60 | ProcessingTimeRole, | ||
4935 | 61 | QualityRole, | ||
4936 | 62 | ReverseRole, | ||
4937 | 63 | SizeRole, | ||
4938 | 64 | StateRole, | ||
4939 | 65 | TitleRole, | ||
4940 | 66 | UserRole, | ||
4941 | 67 | LastStateMessageRole, | ||
4942 | 68 | LastRole = LastStateMessageRole, | ||
4943 | 69 | }; | ||
4944 | 70 | |||
4945 | 71 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
4946 | 72 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
4947 | 73 | virtual QHash<int, QByteArray> roleNames() const override; | ||
4948 | 74 | |||
4949 | 75 | int count() const; | ||
4950 | 76 | |||
4951 | 77 | Q_INVOKABLE QVariantMap get(const int row) const; | ||
4952 | 78 | QSharedPointer<PrinterJob> getJobById(const int &id); | ||
4953 | 79 | private: | ||
4954 | 80 | PrinterBackend *m_backend; | ||
4955 | 81 | |||
4956 | 82 | QList<QSharedPointer<PrinterJob>> m_jobs; | ||
4957 | 83 | private Q_SLOTS: | ||
4958 | 84 | void update(); | ||
4959 | 85 | void jobSignalCatchAll(const QString &text, const QString &printer_uri, | ||
4960 | 86 | const QString &printer_name, uint printer_state, | ||
4961 | 87 | const QString &printer_state_reasons, | ||
4962 | 88 | bool printer_is_accepting_jobs, uint job_id, | ||
4963 | 89 | uint job_state, const QString &job_state_reasons, | ||
4964 | 90 | const QString &job_name, | ||
4965 | 91 | uint job_impressions_completed); | ||
4966 | 92 | |||
4967 | 93 | Q_SIGNALS: | ||
4968 | 94 | void countChanged(); | ||
4969 | 95 | }; | ||
4970 | 96 | |||
4971 | 97 | class PRINTERS_DECL_EXPORT JobFilter : public QSortFilterProxyModel | ||
4972 | 98 | { | ||
4973 | 99 | Q_OBJECT | ||
4974 | 100 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
4975 | 101 | public: | ||
4976 | 102 | explicit JobFilter(QObject *parent = Q_NULLPTR); | ||
4977 | 103 | ~JobFilter(); | ||
4978 | 104 | |||
4979 | 105 | Q_INVOKABLE QVariantMap get(const int row) const; | ||
4980 | 106 | |||
4981 | 107 | void filterOnPrinterName(const QString &name); | ||
4982 | 108 | int count() const; | ||
4983 | 109 | protected: | ||
4984 | 110 | virtual bool filterAcceptsRow( | ||
4985 | 111 | int sourceRow, const QModelIndex &sourceParent) const override; | ||
4986 | 112 | |||
4987 | 113 | Q_SIGNALS: | ||
4988 | 114 | void countChanged(); | ||
4989 | 115 | |||
4990 | 116 | private Q_SLOTS: | ||
4991 | 117 | void onSourceModelChanged(); | ||
4992 | 118 | void onSourceModelCountChanged(); | ||
4993 | 119 | |||
4994 | 120 | private: | ||
4995 | 121 | QString m_printerName = QString::null; | ||
4996 | 122 | bool m_printerNameFilterEnabled = false; | ||
4997 | 123 | }; | ||
4998 | 124 | |||
4999 | 125 | #endif // USC_JOB_MODEL_H | ||
5000 | 0 | 126 |
The diff has been truncated for viewing.