Merge lp:~ahayzen/ubuntu-settings-components/add-job-model into lp:~phablet-team/ubuntu-settings-components/printer-components
- add-job-model
- Merge into printer-components
Proposed by
Andrew Hayzen
Status: | Merged |
---|---|
Approved by: | Jonas G. Drange |
Approved revision: | 227 |
Merged at revision: | 224 |
Proposed branch: | lp:~ahayzen/ubuntu-settings-components/add-job-model |
Merge into: | lp:~phablet-team/ubuntu-settings-components/printer-components |
Prerequisite: | lp:~ahayzen/ubuntu-settings-components/add-cancel-method |
Diff against target: |
823 lines (+527/-12) 16 files modified
examples/PrinterQueue.qml (+113/-0) plugins/Ubuntu/Settings/Printers/CMakeLists.txt (+1/-0) plugins/Ubuntu/Settings/Printers/backend/backend.cpp (+7/-0) plugins/Ubuntu/Settings/Printers/backend/backend.h (+1/-0) plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp (+17/-0) plugins/Ubuntu/Settings/Printers/backend/backend_cups.h (+1/-0) plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp (+18/-0) plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h (+1/-0) plugins/Ubuntu/Settings/Printers/enums.h (+13/-0) plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp (+222/-0) plugins/Ubuntu/Settings/Printers/models/jobmodel.h (+75/-0) plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+17/-0) plugins/Ubuntu/Settings/Printers/models/printermodel.h (+3/-0) plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+24/-8) plugins/Ubuntu/Settings/Printers/printer/printerjob.h (+9/-4) tests/unittests/Printers/mockbackend.h (+5/-0) |
To merge this branch: | bzr merge lp:~ahayzen/ubuntu-settings-components/add-job-model |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonas G. Drange (community) | Approve | ||
Review via email: mp+316242@code.launchpad.net |
Commit message
* Add JobModel which lists the jobs for a certain printer
* Add JobRole to PrinterModel to access jobs
* Add JobState enum to track enums from cups
* Add example Queue which lists jobs for a printer with their name, id, status and allows you to cancel the job by clicking
Description of the change
* Add JobModel which lists the jobs for a certain printer
* Add JobRole to PrinterModel to access jobs
* Add JobState enum to track enums from cups
* Add example Queue which lists jobs for a printer with their name, id, status and allows you to cancel the job by clicking
To post a comment you must log in.
- 226. By Andrew Hayzen
-
* Remove some tracing
- 227. By Andrew Hayzen
-
* Use QSharedPointer instead of raw pointers for PrinterJob
* Renamed Queue.qml to PrinterQueue.qml
Revision history for this message
Jonas G. Drange (jonas-drange) wrote : | # |
THX! LGTM
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'examples/PrinterQueue.qml' | |||
2 | --- examples/PrinterQueue.qml 1970-01-01 00:00:00 +0000 | |||
3 | +++ examples/PrinterQueue.qml 2017-02-02 17:23:30 +0000 | |||
4 | @@ -0,0 +1,113 @@ | |||
5 | 1 | /* | ||
6 | 2 | * Copyright 2017 Canonical Ltd. | ||
7 | 3 | * | ||
8 | 4 | * This program is free software; you can redistribute it and/or modify | ||
9 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
10 | 6 | * the Free Software Foundation; version 3. | ||
11 | 7 | * | ||
12 | 8 | * This program is distributed in the hope that it will be useful, | ||
13 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | 11 | * GNU Lesser General Public License for more details. | ||
16 | 12 | * | ||
17 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
18 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | 15 | * | ||
20 | 16 | * Authored by Jonas G. Drange <jonas.drange@canonical.com> | ||
21 | 17 | * Andrew Hayzen <andrew.hayzen@canonical.com> | ||
22 | 18 | */ | ||
23 | 19 | |||
24 | 20 | import QtQuick 2.4 | ||
25 | 21 | import QtQuick.Layouts 1.1 | ||
26 | 22 | import Ubuntu.Components 1.3 | ||
27 | 23 | import Ubuntu.Components.ListItems 1.3 as ListItems | ||
28 | 24 | import Ubuntu.Settings.Components 0.1 | ||
29 | 25 | import Ubuntu.Settings.Printers 0.1 | ||
30 | 26 | |||
31 | 27 | MainView { | ||
32 | 28 | width: units.gu(50) | ||
33 | 29 | height: units.gu(90) | ||
34 | 30 | |||
35 | 31 | Component { | ||
36 | 32 | id: queuePage | ||
37 | 33 | |||
38 | 34 | Page { | ||
39 | 35 | header: PageHeader { | ||
40 | 36 | title: "Queue: " + printer.name | ||
41 | 37 | flickable: queueView | ||
42 | 38 | } | ||
43 | 39 | visible: false | ||
44 | 40 | |||
45 | 41 | property var printer | ||
46 | 42 | |||
47 | 43 | ListView { | ||
48 | 44 | id: queueView | ||
49 | 45 | anchors { | ||
50 | 46 | fill: parent | ||
51 | 47 | } | ||
52 | 48 | delegate: ListItem { | ||
53 | 49 | height: modelLayout.height + (divider.visible ? divider.height : 0) | ||
54 | 50 | ListItemLayout { | ||
55 | 51 | id: modelLayout | ||
56 | 52 | title.text: displayName | ||
57 | 53 | subtitle.text: "Job: " + model.id + " State: " + model.state | ||
58 | 54 | } | ||
59 | 55 | onClicked: { | ||
60 | 56 | console.debug("Cancel:", printer.name, model.id); | ||
61 | 57 | Printers.cancelJob(printer.name, model.id); | ||
62 | 58 | } | ||
63 | 59 | } | ||
64 | 60 | model: printer.jobs | ||
65 | 61 | |||
66 | 62 | Label { | ||
67 | 63 | anchors { | ||
68 | 64 | centerIn: parent | ||
69 | 65 | } | ||
70 | 66 | text: "Empty queue" | ||
71 | 67 | visible: queueView.count === 0 | ||
72 | 68 | } | ||
73 | 69 | } | ||
74 | 70 | } | ||
75 | 71 | } | ||
76 | 72 | |||
77 | 73 | PageStack { | ||
78 | 74 | id: pageStack | ||
79 | 75 | |||
80 | 76 | Page { | ||
81 | 77 | id: printersPage | ||
82 | 78 | header: PageHeader { | ||
83 | 79 | title: "Printers" | ||
84 | 80 | flickable: printerList | ||
85 | 81 | } | ||
86 | 82 | visible: false | ||
87 | 83 | |||
88 | 84 | ListView { | ||
89 | 85 | id: printerList | ||
90 | 86 | anchors { fill: parent } | ||
91 | 87 | model: Printers.allPrintersWithPdf | ||
92 | 88 | delegate: ListItem { | ||
93 | 89 | height: modelLayout.height + (divider.visible ? divider.height : 0) | ||
94 | 90 | ListItemLayout { | ||
95 | 91 | id: modelLayout | ||
96 | 92 | title.text: displayName | ||
97 | 93 | title.font.bold: model.default | ||
98 | 94 | subtitle.text: description | ||
99 | 95 | |||
100 | 96 | Icon { | ||
101 | 97 | id: icon | ||
102 | 98 | width: height | ||
103 | 99 | height: units.gu(2.5) | ||
104 | 100 | name: "printer-symbolic" | ||
105 | 101 | SlotsLayout.position: SlotsLayout.First | ||
106 | 102 | } | ||
107 | 103 | |||
108 | 104 | ProgressionSlot {} | ||
109 | 105 | } | ||
110 | 106 | onClicked: pageStack.push(queuePage, { printer: model }) | ||
111 | 107 | } | ||
112 | 108 | } | ||
113 | 109 | } | ||
114 | 110 | |||
115 | 111 | Component.onCompleted: push(printersPage) | ||
116 | 112 | } | ||
117 | 113 | } | ||
118 | 0 | 114 | ||
119 | === modified file 'plugins/Ubuntu/Settings/Printers/CMakeLists.txt' | |||
120 | --- plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-01-26 21:47:06 +0000 | |||
121 | +++ plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-02-02 17:23:30 +0000 | |||
122 | @@ -18,6 +18,7 @@ | |||
123 | 18 | enums.h | 18 | enums.h |
124 | 19 | i18n.cpp | 19 | i18n.cpp |
125 | 20 | models/drivermodel.cpp | 20 | models/drivermodel.cpp |
126 | 21 | models/jobmodel.cpp | ||
127 | 21 | models/printermodel.cpp | 22 | models/printermodel.cpp |
128 | 22 | printer/printer.cpp | 23 | printer/printer.cpp |
129 | 23 | printer/printerjob.cpp | 24 | printer/printerjob.cpp |
130 | 24 | 25 | ||
131 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend.cpp' | |||
132 | --- plugins/Ubuntu/Settings/Printers/backend/backend.cpp 2017-02-02 17:23:30 +0000 | |||
133 | +++ plugins/Ubuntu/Settings/Printers/backend/backend.cpp 2017-02-02 17:23:30 +0000 | |||
134 | @@ -202,6 +202,13 @@ | |||
135 | 202 | return -1; | 202 | return -1; |
136 | 203 | } | 203 | } |
137 | 204 | 204 | ||
138 | 205 | QList<QSharedPointer<PrinterJob>> PrinterBackend::printerGetJobs(const QString &name) | ||
139 | 206 | { | ||
140 | 207 | Q_UNUSED(name); | ||
141 | 208 | |||
142 | 209 | return QList<QSharedPointer<PrinterJob>>{}; | ||
143 | 210 | } | ||
144 | 211 | |||
145 | 205 | QString PrinterBackend::printerName() const | 212 | QString PrinterBackend::printerName() const |
146 | 206 | { | 213 | { |
147 | 207 | return QString(); | 214 | return QString(); |
148 | 208 | 215 | ||
149 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend.h' | |||
150 | --- plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-02 17:23:30 +0000 | |||
151 | +++ plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-02 17:23:30 +0000 | |||
152 | @@ -118,6 +118,7 @@ | |||
153 | 118 | virtual int printFileToDest(const QString &filepath, | 118 | virtual int printFileToDest(const QString &filepath, |
154 | 119 | const QString &title, | 119 | const QString &title, |
155 | 120 | const cups_dest_t *dest); | 120 | const cups_dest_t *dest); |
156 | 121 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(const QString &name); | ||
157 | 121 | 122 | ||
158 | 122 | virtual QString printerName() const; | 123 | virtual QString printerName() const; |
159 | 123 | virtual QString description() const; | 124 | virtual QString description() const; |
160 | 124 | 125 | ||
161 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp' | |||
162 | --- plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-02 17:23:30 +0000 | |||
163 | +++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-02 17:23:30 +0000 | |||
164 | @@ -210,6 +210,23 @@ | |||
165 | 210 | return m_cups->printFileToDest(filepath, title, dest); | 210 | return m_cups->printFileToDest(filepath, title, dest); |
166 | 211 | } | 211 | } |
167 | 212 | 212 | ||
168 | 213 | QList<QSharedPointer<PrinterJob>> PrinterCupsBackend::printerGetJobs(const QString &name) | ||
169 | 214 | { | ||
170 | 215 | auto jobs = m_cups->printerGetJobs(name); | ||
171 | 216 | QList<QSharedPointer<PrinterJob>> list; | ||
172 | 217 | |||
173 | 218 | Q_FOREACH(auto job, jobs) { | ||
174 | 219 | auto newJob = QSharedPointer<PrinterJob>(new PrinterJob(name, this, job->id)); | ||
175 | 220 | |||
176 | 221 | newJob->setState(static_cast<PrinterEnum::JobState>(job->state)); | ||
177 | 222 | newJob->setTitle(QString::fromLocal8Bit(job->title)); | ||
178 | 223 | |||
179 | 224 | list.append(newJob); | ||
180 | 225 | } | ||
181 | 226 | |||
182 | 227 | return list; | ||
183 | 228 | } | ||
184 | 229 | |||
185 | 213 | QString PrinterCupsBackend::printerName() const | 230 | QString PrinterCupsBackend::printerName() const |
186 | 214 | { | 231 | { |
187 | 215 | return m_info.printerName(); | 232 | return m_info.printerName(); |
188 | 216 | 233 | ||
189 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.h' | |||
190 | --- plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 2017-02-02 17:23:30 +0000 | |||
191 | +++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 2017-02-02 17:23:30 +0000 | |||
192 | @@ -97,6 +97,7 @@ | |||
193 | 97 | virtual int printFileToDest(const QString &filepath, | 97 | virtual int printFileToDest(const QString &filepath, |
194 | 98 | const QString &title, | 98 | const QString &title, |
195 | 99 | const cups_dest_t *dest) override; | 99 | const cups_dest_t *dest) override; |
196 | 100 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(const QString &name) override; | ||
197 | 100 | 101 | ||
198 | 101 | virtual QString printerName() const override; | 102 | virtual QString printerName() const override; |
199 | 102 | virtual QString description() const override; | 103 | virtual QString description() const override; |
200 | 103 | 104 | ||
201 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp' | |||
202 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-02 17:23:30 +0000 | |||
203 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-02 17:23:30 +0000 | |||
204 | @@ -376,6 +376,24 @@ | |||
205 | 376 | } | 376 | } |
206 | 377 | } | 377 | } |
207 | 378 | 378 | ||
208 | 379 | QList<cups_job_t *> CupsFacade::printerGetJobs(const QString &name) | ||
209 | 380 | { | ||
210 | 381 | QList<cups_job_t *> list; | ||
211 | 382 | cups_job_t *jobs; | ||
212 | 383 | |||
213 | 384 | // Get a list of the jobs that are 'mine' and only active ones | ||
214 | 385 | // https://www.cups.org/doc/api-cups.html#cupsGetJobs | ||
215 | 386 | int count = cupsGetJobs(&jobs, name.toLocal8Bit(), 1, CUPS_WHICHJOBS_ACTIVE); | ||
216 | 387 | |||
217 | 388 | for (int i=0; i < count; i++) { | ||
218 | 389 | list.append(&jobs[i]); | ||
219 | 390 | } | ||
220 | 391 | |||
221 | 392 | // FIXME: needs to run cupsFreeJobs(); | ||
222 | 393 | |||
223 | 394 | return list; | ||
224 | 395 | } | ||
225 | 396 | |||
226 | 379 | int CupsFacade::printFileToDest(const QString &filepath, const QString &title, | 397 | int CupsFacade::printFileToDest(const QString &filepath, const QString &title, |
227 | 380 | const cups_dest_t *dest) | 398 | const cups_dest_t *dest) |
228 | 381 | { | 399 | { |
229 | 382 | 400 | ||
230 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h' | |||
231 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-02 17:23:30 +0000 | |||
232 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-02 17:23:30 +0000 | |||
233 | @@ -89,6 +89,7 @@ | |||
234 | 89 | QList<PrintQuality> printerGetSupportedQualities(const QString &name) const; | 89 | QList<PrintQuality> printerGetSupportedQualities(const QString &name) const; |
235 | 90 | 90 | ||
236 | 91 | void cancelJob(const QString &name, const int jobId); | 91 | void cancelJob(const QString &name, const int jobId); |
237 | 92 | QList<cups_job_t *> printerGetJobs(const QString &name); | ||
238 | 92 | int printFileToDest(const QString &filepath, const QString &title, | 93 | int printFileToDest(const QString &filepath, const QString &title, |
239 | 93 | const cups_dest_t *dest); | 94 | const cups_dest_t *dest); |
240 | 94 | 95 | ||
241 | 95 | 96 | ||
242 | === modified file 'plugins/Ubuntu/Settings/Printers/enums.h' | |||
243 | --- plugins/Ubuntu/Settings/Printers/enums.h 2017-01-19 21:00:28 +0000 | |||
244 | +++ plugins/Ubuntu/Settings/Printers/enums.h 2017-02-02 17:23:30 +0000 | |||
245 | @@ -93,6 +93,19 @@ | |||
246 | 93 | }; | 93 | }; |
247 | 94 | Q_ENUM(ErrorPolicy) | 94 | Q_ENUM(ErrorPolicy) |
248 | 95 | 95 | ||
249 | 96 | // Match enums from ipp_jstate_t | ||
250 | 97 | enum class JobState | ||
251 | 98 | { | ||
252 | 99 | Pending = 3, | ||
253 | 100 | Held, | ||
254 | 101 | Processing, | ||
255 | 102 | Stopped, | ||
256 | 103 | Canceled, | ||
257 | 104 | Aborted, | ||
258 | 105 | Complete, | ||
259 | 106 | }; | ||
260 | 107 | Q_ENUM(JobState) | ||
261 | 108 | |||
262 | 96 | enum class OperationPolicy | 109 | enum class OperationPolicy |
263 | 97 | { | 110 | { |
264 | 98 | DefaultOperation = 0, | 111 | DefaultOperation = 0, |
265 | 99 | 112 | ||
266 | === added file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp' | |||
267 | --- plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 1970-01-01 00:00:00 +0000 | |||
268 | +++ plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 2017-02-02 17:23:30 +0000 | |||
269 | @@ -0,0 +1,222 @@ | |||
270 | 1 | /* | ||
271 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
272 | 3 | * | ||
273 | 4 | * This program is free software; you can redistribute it and/or modify | ||
274 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
275 | 6 | * the Free Software Foundation; version 3. | ||
276 | 7 | * | ||
277 | 8 | * This program is distributed in the hope that it will be useful, | ||
278 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
279 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
280 | 11 | * GNU Lesser General Public License for more details. | ||
281 | 12 | * | ||
282 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
283 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
284 | 15 | */ | ||
285 | 16 | |||
286 | 17 | #include "utils.h" | ||
287 | 18 | |||
288 | 19 | #include "backend/backend_cups.h" | ||
289 | 20 | #include "cups/cupsfacade.h" | ||
290 | 21 | |||
291 | 22 | #include "models/jobmodel.h" | ||
292 | 23 | |||
293 | 24 | #include <QDebug> | ||
294 | 25 | |||
295 | 26 | JobModel::JobModel(const int updateIntervalMSecs, QObject *parent) | ||
296 | 27 | : JobModel(QStringLiteral(""), new PrinterCupsBackend, updateIntervalMSecs, parent) | ||
297 | 28 | { | ||
298 | 29 | } | ||
299 | 30 | |||
300 | 31 | JobModel::JobModel(const QString &printerName, PrinterBackend *backend, | ||
301 | 32 | const int updateIntervalMSecs, | ||
302 | 33 | QObject *parent) | ||
303 | 34 | : QAbstractListModel(parent) | ||
304 | 35 | , m_backend(backend) | ||
305 | 36 | , m_printer_name(printerName) | ||
306 | 37 | { | ||
307 | 38 | update(); | ||
308 | 39 | startUpdateTimer(updateIntervalMSecs); | ||
309 | 40 | } | ||
310 | 41 | |||
311 | 42 | JobModel::~JobModel() | ||
312 | 43 | { | ||
313 | 44 | } | ||
314 | 45 | |||
315 | 46 | void JobModel::startUpdateTimer(const int &msecs) | ||
316 | 47 | { | ||
317 | 48 | // Start a timer to poll for changes in the printers | ||
318 | 49 | m_update_timer.setParent(this); | ||
319 | 50 | connect(&m_update_timer, SIGNAL(timeout()), this, SLOT(update())); | ||
320 | 51 | m_update_timer.start(msecs); | ||
321 | 52 | } | ||
322 | 53 | |||
323 | 54 | void JobModel::update() | ||
324 | 55 | { | ||
325 | 56 | // Store the old count and get the new printers | ||
326 | 57 | int oldCount = m_jobs.size(); | ||
327 | 58 | QList<QSharedPointer<PrinterJob>> newJobs = m_backend->printerGetJobs(m_printer_name); | ||
328 | 59 | |||
329 | 60 | /* If any printers returned from the backend are irrelevant, we delete | ||
330 | 61 | them. This a list of indices that corresponds to printers scheduled for | ||
331 | 62 | deletion in newPrinters. */ | ||
332 | 63 | QList<uint> forDeletion; | ||
333 | 64 | |||
334 | 65 | // Go through the old model | ||
335 | 66 | for (int i=0; i < m_jobs.count(); i++) { | ||
336 | 67 | // Determine if the old printer exists in the new model | ||
337 | 68 | bool exists = false; | ||
338 | 69 | |||
339 | 70 | Q_FOREACH(QSharedPointer<PrinterJob> p, newJobs) { | ||
340 | 71 | // TODO: update status here | ||
341 | 72 | if (p->jobId() == m_jobs.at(i)->jobId()) { | ||
342 | 73 | exists = true; | ||
343 | 74 | break; | ||
344 | 75 | } | ||
345 | 76 | } | ||
346 | 77 | |||
347 | 78 | // If it doesn't exist then remove it from the old model | ||
348 | 79 | if (!exists) { | ||
349 | 80 | beginRemoveRows(QModelIndex(), i, i); | ||
350 | 81 | QSharedPointer<PrinterJob> p = m_jobs.takeAt(i); | ||
351 | 82 | p->deleteLater(); | ||
352 | 83 | endRemoveRows(); | ||
353 | 84 | |||
354 | 85 | i--; // as we have removed an item decrement | ||
355 | 86 | } | ||
356 | 87 | } | ||
357 | 88 | |||
358 | 89 | // Go through the new model | ||
359 | 90 | for (int i=0; i < newJobs.count(); i++) { | ||
360 | 91 | // Determine if the new printer exists in the old model | ||
361 | 92 | bool exists = false; | ||
362 | 93 | int j; | ||
363 | 94 | |||
364 | 95 | for (j=0; j < m_jobs.count(); j++) { | ||
365 | 96 | if (m_jobs.at(j)->jobId() == newJobs.at(i)->jobId()) { | ||
366 | 97 | exists = true; | ||
367 | 98 | forDeletion << i; | ||
368 | 99 | break; | ||
369 | 100 | } | ||
370 | 101 | } | ||
371 | 102 | |||
372 | 103 | if (exists) { | ||
373 | 104 | if (j == i) { // New printer exists and in correct position | ||
374 | 105 | continue; | ||
375 | 106 | } else { | ||
376 | 107 | // New printer does exist but needs to be moved in old model | ||
377 | 108 | beginMoveRows(QModelIndex(), j, 1, QModelIndex(), i); | ||
378 | 109 | m_jobs.move(j, i); | ||
379 | 110 | endMoveRows(); | ||
380 | 111 | } | ||
381 | 112 | |||
382 | 113 | // We can safely delete the newPrinter as it already exists. | ||
383 | 114 | forDeletion << i; | ||
384 | 115 | } else { | ||
385 | 116 | // New printer does not exist insert into model | ||
386 | 117 | beginInsertRows(QModelIndex(), i, i); | ||
387 | 118 | m_jobs.insert(i, newJobs.at(i)); | ||
388 | 119 | endInsertRows(); | ||
389 | 120 | } | ||
390 | 121 | } | ||
391 | 122 | |||
392 | 123 | Q_FOREACH(const int &index, forDeletion) { | ||
393 | 124 | newJobs.at(index)->deleteLater(); | ||
394 | 125 | } | ||
395 | 126 | |||
396 | 127 | if (oldCount != m_jobs.size()) { | ||
397 | 128 | Q_EMIT countChanged(); | ||
398 | 129 | } | ||
399 | 130 | } | ||
400 | 131 | |||
401 | 132 | int JobModel::rowCount(const QModelIndex &parent) const | ||
402 | 133 | { | ||
403 | 134 | Q_UNUSED(parent); | ||
404 | 135 | return m_jobs.size(); | ||
405 | 136 | } | ||
406 | 137 | |||
407 | 138 | int JobModel::count() const | ||
408 | 139 | { | ||
409 | 140 | return rowCount(); | ||
410 | 141 | } | ||
411 | 142 | |||
412 | 143 | QVariant JobModel::data(const QModelIndex &index, int role) const | ||
413 | 144 | { | ||
414 | 145 | QVariant ret; | ||
415 | 146 | |||
416 | 147 | if ((0<=index.row()) && (index.row()<m_jobs.size())) { | ||
417 | 148 | |||
418 | 149 | auto job = m_jobs[index.row()]; | ||
419 | 150 | |||
420 | 151 | switch (role) { | ||
421 | 152 | case IdRole: | ||
422 | 153 | ret = job->jobId(); | ||
423 | 154 | break; | ||
424 | 155 | case OwnerRole: | ||
425 | 156 | ret = m_printer_name; | ||
426 | 157 | break; | ||
427 | 158 | case StateRole: | ||
428 | 159 | // TODO: improve, for now have a switch | ||
429 | 160 | switch (job->state()) { | ||
430 | 161 | case PrinterEnum::JobState::Aborted: | ||
431 | 162 | ret = "Aborted"; | ||
432 | 163 | break; | ||
433 | 164 | case PrinterEnum::JobState::Canceled: | ||
434 | 165 | ret = "Canceled"; | ||
435 | 166 | break; | ||
436 | 167 | case PrinterEnum::JobState::Complete: | ||
437 | 168 | ret = "Compelete"; | ||
438 | 169 | break; | ||
439 | 170 | case PrinterEnum::JobState::Held: | ||
440 | 171 | ret = "Held"; | ||
441 | 172 | break; | ||
442 | 173 | case PrinterEnum::JobState::Pending: | ||
443 | 174 | ret = "Pending"; | ||
444 | 175 | break; | ||
445 | 176 | case PrinterEnum::JobState::Processing: | ||
446 | 177 | ret = "Processing"; | ||
447 | 178 | break; | ||
448 | 179 | case PrinterEnum::JobState::Stopped: | ||
449 | 180 | ret = "Stopped"; | ||
450 | 181 | break; | ||
451 | 182 | } | ||
452 | 183 | break; | ||
453 | 184 | case Qt::DisplayRole: | ||
454 | 185 | case TitleRole: | ||
455 | 186 | ret = job->title(); | ||
456 | 187 | break; | ||
457 | 188 | } | ||
458 | 189 | } | ||
459 | 190 | |||
460 | 191 | return ret; | ||
461 | 192 | } | ||
462 | 193 | |||
463 | 194 | QHash<int, QByteArray> JobModel::roleNames() const | ||
464 | 195 | { | ||
465 | 196 | static QHash<int,QByteArray> names; | ||
466 | 197 | |||
467 | 198 | if (Q_UNLIKELY(names.empty())) { | ||
468 | 199 | names[Qt::DisplayRole] = "displayName"; | ||
469 | 200 | names[IdRole] = "id"; | ||
470 | 201 | names[OwnerRole] = "owner"; | ||
471 | 202 | names[StateRole] = "state"; | ||
472 | 203 | names[TitleRole] = "title"; | ||
473 | 204 | names[LastStateMessageRole] = "lastStateMessage"; | ||
474 | 205 | } | ||
475 | 206 | |||
476 | 207 | return names; | ||
477 | 208 | } | ||
478 | 209 | |||
479 | 210 | QVariantMap JobModel::get(const int row) const | ||
480 | 211 | { | ||
481 | 212 | QHashIterator<int, QByteArray> iterator(roleNames()); | ||
482 | 213 | QVariantMap result; | ||
483 | 214 | QModelIndex modelIndex = index(row, 0); | ||
484 | 215 | |||
485 | 216 | while (iterator.hasNext()) { | ||
486 | 217 | iterator.next(); | ||
487 | 218 | result[iterator.value()] = modelIndex.data(iterator.key()); | ||
488 | 219 | } | ||
489 | 220 | |||
490 | 221 | return result; | ||
491 | 222 | } | ||
492 | 0 | 223 | ||
493 | === added file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.h' | |||
494 | --- plugins/Ubuntu/Settings/Printers/models/jobmodel.h 1970-01-01 00:00:00 +0000 | |||
495 | +++ plugins/Ubuntu/Settings/Printers/models/jobmodel.h 2017-02-02 17:23:30 +0000 | |||
496 | @@ -0,0 +1,75 @@ | |||
497 | 1 | /* | ||
498 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
499 | 3 | * | ||
500 | 4 | * This program is free software; you can redistribute it and/or modify | ||
501 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
502 | 6 | * the Free Software Foundation; version 3. | ||
503 | 7 | * | ||
504 | 8 | * This program is distributed in the hope that it will be useful, | ||
505 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
506 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
507 | 11 | * GNU Lesser General Public License for more details. | ||
508 | 12 | * | ||
509 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
510 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
511 | 15 | */ | ||
512 | 16 | |||
513 | 17 | #ifndef USC_JOB_MODEL_H | ||
514 | 18 | #define USC_JOB_MODEL_H | ||
515 | 19 | |||
516 | 20 | #include "printers_global.h" | ||
517 | 21 | |||
518 | 22 | #include "printer/printer.h" | ||
519 | 23 | |||
520 | 24 | #include <QAbstractListModel> | ||
521 | 25 | #include <QByteArray> | ||
522 | 26 | #include <QModelIndex> | ||
523 | 27 | #include <QObject> | ||
524 | 28 | #include <QSortFilterProxyModel> | ||
525 | 29 | #include <QTimer> | ||
526 | 30 | #include <QVariant> | ||
527 | 31 | |||
528 | 32 | class PRINTERS_DECL_EXPORT JobModel : public QAbstractListModel | ||
529 | 33 | { | ||
530 | 34 | Q_OBJECT | ||
531 | 35 | |||
532 | 36 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
533 | 37 | public: | ||
534 | 38 | explicit JobModel(const int updateIntervalMSecs=5000, QObject *parent = Q_NULLPTR); | ||
535 | 39 | explicit JobModel(const QString &printerName, PrinterBackend *backend, const int updateIntervalMSecs=5000, | ||
536 | 40 | QObject *parent = Q_NULLPTR); | ||
537 | 41 | ~JobModel(); | ||
538 | 42 | |||
539 | 43 | enum Roles | ||
540 | 44 | { | ||
541 | 45 | // Qt::DisplayRole holds job title | ||
542 | 46 | IdRole = Qt::UserRole, | ||
543 | 47 | OwnerRole, | ||
544 | 48 | StateRole, | ||
545 | 49 | TitleRole, | ||
546 | 50 | LastStateMessageRole, | ||
547 | 51 | LastRole = LastStateMessageRole, | ||
548 | 52 | }; | ||
549 | 53 | |||
550 | 54 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
551 | 55 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
552 | 56 | virtual QHash<int, QByteArray> roleNames() const override; | ||
553 | 57 | |||
554 | 58 | int count() const; | ||
555 | 59 | |||
556 | 60 | Q_INVOKABLE QVariantMap get(const int row) const; | ||
557 | 61 | private: | ||
558 | 62 | QTimer m_update_timer; | ||
559 | 63 | PrinterBackend *m_backend; | ||
560 | 64 | QString m_printer_name; | ||
561 | 65 | |||
562 | 66 | QList<QSharedPointer<PrinterJob>> m_jobs; | ||
563 | 67 | private Q_SLOTS: | ||
564 | 68 | void startUpdateTimer(const int &msecs); | ||
565 | 69 | void update(); | ||
566 | 70 | |||
567 | 71 | Q_SIGNALS: | ||
568 | 72 | void countChanged(); | ||
569 | 73 | }; | ||
570 | 74 | |||
571 | 75 | #endif // USC_JOB_MODEL_H | ||
572 | 0 | 76 | ||
573 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp' | |||
574 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-22 19:31:39 +0000 | |||
575 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-02-02 17:23:30 +0000 | |||
576 | @@ -18,9 +18,11 @@ | |||
577 | 18 | 18 | ||
578 | 19 | #include "backend/backend_cups.h" | 19 | #include "backend/backend_cups.h" |
579 | 20 | #include "cups/cupsfacade.h" | 20 | #include "cups/cupsfacade.h" |
580 | 21 | #include "models/jobmodel.h" | ||
581 | 21 | #include "models/printermodel.h" | 22 | #include "models/printermodel.h" |
582 | 22 | 23 | ||
583 | 23 | #include <QDebug> | 24 | #include <QDebug> |
584 | 25 | #include <QQmlEngine> | ||
585 | 24 | 26 | ||
586 | 25 | PrinterModel::PrinterModel(const int updateIntervalMSecs, QObject *parent) | 27 | PrinterModel::PrinterModel(const int updateIntervalMSecs, QObject *parent) |
587 | 26 | : PrinterModel(new PrinterCupsBackend, updateIntervalMSecs, parent) | 28 | : PrinterModel(new PrinterCupsBackend, updateIntervalMSecs, parent) |
588 | @@ -76,7 +78,11 @@ | |||
589 | 76 | if (!exists) { | 78 | if (!exists) { |
590 | 77 | beginRemoveRows(QModelIndex(), i, i); | 79 | beginRemoveRows(QModelIndex(), i, i); |
591 | 78 | Printer *p = m_printers.takeAt(i); | 80 | Printer *p = m_printers.takeAt(i); |
592 | 81 | JobModel *jobModel = m_job_models.take(p->name()); | ||
593 | 82 | |||
594 | 79 | p->deleteLater(); | 83 | p->deleteLater(); |
595 | 84 | jobModel->deleteLater(); | ||
596 | 85 | |||
597 | 80 | endRemoveRows(); | 86 | endRemoveRows(); |
598 | 81 | 87 | ||
599 | 82 | i--; // as we have removed an item decrement | 88 | i--; // as we have removed an item decrement |
600 | @@ -112,7 +118,13 @@ | |||
601 | 112 | } else { | 118 | } else { |
602 | 113 | // New printer does not exist insert into model | 119 | // New printer does not exist insert into model |
603 | 114 | beginInsertRows(QModelIndex(), i, i); | 120 | beginInsertRows(QModelIndex(), i, i); |
604 | 121 | |||
605 | 115 | m_printers.insert(i, newPrinters.at(i)); | 122 | m_printers.insert(i, newPrinters.at(i)); |
606 | 123 | |||
607 | 124 | JobModel *model = new JobModel(newPrinters.at(i)->name(), m_backend, 5000, this); | ||
608 | 125 | QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership); | ||
609 | 126 | m_job_models.insert(newPrinters.at(i)->name(), model); | ||
610 | 127 | |||
611 | 116 | endInsertRows(); | 128 | endInsertRows(); |
612 | 117 | } | 129 | } |
613 | 118 | } | 130 | } |
614 | @@ -226,6 +238,10 @@ | |||
615 | 226 | case IsPdfRole: | 238 | case IsPdfRole: |
616 | 227 | ret = printer->isPdf(); | 239 | ret = printer->isPdf(); |
617 | 228 | break; | 240 | break; |
618 | 241 | case JobRole: { | ||
619 | 242 | ret = QVariant::fromValue(m_job_models.value(printer->name())); | ||
620 | 243 | break; | ||
621 | 244 | } | ||
622 | 229 | // case LastStateMessageRole: | 245 | // case LastStateMessageRole: |
623 | 230 | // ret = printer->lastStateMessage(); | 246 | // ret = printer->lastStateMessage(); |
624 | 231 | // break; | 247 | // break; |
625 | @@ -311,6 +327,7 @@ | |||
626 | 311 | names[StateRole] = "state"; | 327 | names[StateRole] = "state"; |
627 | 312 | names[PrinterRole] = "printer"; | 328 | names[PrinterRole] = "printer"; |
628 | 313 | names[IsPdfRole] = "isPdf"; | 329 | names[IsPdfRole] = "isPdf"; |
629 | 330 | names[JobRole] = "jobs"; | ||
630 | 314 | names[LastStateMessageRole] = "lastStateMessage"; | 331 | names[LastStateMessageRole] = "lastStateMessage"; |
631 | 315 | } | 332 | } |
632 | 316 | 333 | ||
633 | 317 | 334 | ||
634 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.h' | |||
635 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-22 14:21:11 +0000 | |||
636 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-02-02 17:23:30 +0000 | |||
637 | @@ -19,6 +19,7 @@ | |||
638 | 19 | 19 | ||
639 | 20 | #include "printers_global.h" | 20 | #include "printers_global.h" |
640 | 21 | 21 | ||
641 | 22 | #include "models/jobmodel.h" | ||
642 | 22 | #include "printer/printer.h" | 23 | #include "printer/printer.h" |
643 | 23 | 24 | ||
644 | 24 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> |
645 | @@ -64,6 +65,7 @@ | |||
646 | 64 | PrinterRole, | 65 | PrinterRole, |
647 | 65 | LastStateMessageRole, | 66 | LastStateMessageRole, |
648 | 66 | IsPdfRole, | 67 | IsPdfRole, |
649 | 68 | JobRole, | ||
650 | 67 | LastRole = LastStateMessageRole, | 69 | LastRole = LastStateMessageRole, |
651 | 68 | }; | 70 | }; |
652 | 69 | 71 | ||
653 | @@ -84,6 +86,7 @@ | |||
654 | 84 | /* FIXME: there's currently no need to share the Printer obj with QML, so | 86 | /* FIXME: there's currently no need to share the Printer obj with QML, so |
655 | 85 | this should be normal pointers that are deletedLater. */ | 87 | this should be normal pointers that are deletedLater. */ |
656 | 86 | QList<Printer*> m_printers; | 88 | QList<Printer*> m_printers; |
657 | 89 | QMap<QString, JobModel *> m_job_models; | ||
658 | 87 | 90 | ||
659 | 88 | private Q_SLOTS: | 91 | private Q_SLOTS: |
660 | 89 | void startUpdateTimer(const int &msecs); | 92 | void startUpdateTimer(const int &msecs); |
661 | 90 | 93 | ||
662 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp' | |||
663 | --- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-02 17:23:30 +0000 | |||
664 | +++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-02 17:23:30 +0000 | |||
665 | @@ -40,18 +40,33 @@ | |||
666 | 40 | , m_backend(backend) | 40 | , m_backend(backend) |
667 | 41 | , m_duplex_mode(0) | 41 | , m_duplex_mode(0) |
668 | 42 | , m_is_two_sided(false) | 42 | , m_is_two_sided(false) |
669 | 43 | , m_job_id(-1) | ||
670 | 43 | , m_printer(printer) | 44 | , m_printer(printer) |
671 | 44 | , m_printer_name(QStringLiteral("")) | 45 | , m_printer_name(QStringLiteral("")) |
672 | 45 | , m_print_range(QStringLiteral("")) | 46 | , m_print_range(QStringLiteral("")) |
673 | 46 | , m_print_range_mode(PrinterEnum::PrintRange::AllPages) | 47 | , m_print_range_mode(PrinterEnum::PrintRange::AllPages) |
674 | 47 | , m_quality(0) | 48 | , m_quality(0) |
676 | 48 | , m_state(PrinterEnum::State::IdleState) | 49 | , m_state(PrinterEnum::JobState::Pending) |
677 | 49 | , m_reverse(false) | 50 | , m_reverse(false) |
678 | 50 | , m_title(QStringLiteral("")) | 51 | , m_title(QStringLiteral("")) |
679 | 51 | { | 52 | { |
680 | 53 | if (m_printer) { | ||
681 | 54 | m_printer_name = printer->name(); | ||
682 | 55 | } | ||
683 | 56 | |||
684 | 52 | loadDefaults(); | 57 | loadDefaults(); |
685 | 53 | } | 58 | } |
686 | 54 | 59 | ||
687 | 60 | PrinterJob::PrinterJob(const QString &name, PrinterBackend *backend, int jobId, QObject *parent) | ||
688 | 61 | : QObject(parent) | ||
689 | 62 | , m_backend(backend) | ||
690 | 63 | , m_job_id(jobId) | ||
691 | 64 | { | ||
692 | 65 | setPrinterName(name); | ||
693 | 66 | |||
694 | 67 | // TODO: load other options from job | ||
695 | 68 | } | ||
696 | 69 | |||
697 | 55 | 70 | ||
698 | 56 | PrinterJob::~PrinterJob() | 71 | PrinterJob::~PrinterJob() |
699 | 57 | { | 72 | { |
700 | @@ -115,6 +130,11 @@ | |||
701 | 115 | return m_is_two_sided; | 130 | return m_is_two_sided; |
702 | 116 | } | 131 | } |
703 | 117 | 132 | ||
704 | 133 | int PrinterJob::jobId() const | ||
705 | 134 | { | ||
706 | 135 | return m_job_id; | ||
707 | 136 | } | ||
708 | 137 | |||
709 | 118 | bool PrinterJob::landscape() const | 138 | bool PrinterJob::landscape() const |
710 | 119 | { | 139 | { |
711 | 120 | return m_landscape; | 140 | return m_landscape; |
712 | @@ -143,11 +163,7 @@ | |||
713 | 143 | void PrinterJob::printFile(const QUrl &url) | 163 | void PrinterJob::printFile(const QUrl &url) |
714 | 144 | { | 164 | { |
715 | 145 | if (m_printer) { | 165 | if (m_printer) { |
721 | 146 | int jobId = m_printer->printFile(url.toLocalFile(), this); | 166 | m_job_id = m_printer->printFile(url.toLocalFile(), this); |
717 | 147 | |||
718 | 148 | // TODO: should we track the job and state of it here? | ||
719 | 149 | // so then we can do cancel() and show in the UI when the job is done? | ||
720 | 150 | Q_UNUSED(jobId); | ||
722 | 151 | } else { | 167 | } else { |
723 | 152 | qWarning() << "No valid printer in PrinterJob"; | 168 | qWarning() << "No valid printer in PrinterJob"; |
724 | 153 | } | 169 | } |
725 | @@ -173,7 +189,7 @@ | |||
726 | 173 | return m_reverse; | 189 | return m_reverse; |
727 | 174 | } | 190 | } |
728 | 175 | 191 | ||
730 | 176 | PrinterEnum::State PrinterJob::state() const | 192 | PrinterEnum::JobState PrinterJob::state() const |
731 | 177 | { | 193 | { |
732 | 178 | return m_state; | 194 | return m_state; |
733 | 179 | } | 195 | } |
734 | @@ -311,7 +327,7 @@ | |||
735 | 311 | } | 327 | } |
736 | 312 | } | 328 | } |
737 | 313 | 329 | ||
739 | 314 | void PrinterJob::setState(const PrinterEnum::State &state) | 330 | void PrinterJob::setState(const PrinterEnum::JobState &state) |
740 | 315 | { | 331 | { |
741 | 316 | if (m_state != state) { | 332 | if (m_state != state) { |
742 | 317 | m_state = state; | 333 | m_state = state; |
743 | 318 | 334 | ||
744 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.h' | |||
745 | --- plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-02-02 17:23:30 +0000 | |||
746 | +++ plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-02-02 17:23:30 +0000 | |||
747 | @@ -47,13 +47,16 @@ | |||
748 | 47 | Q_PROPERTY(PrinterEnum::PrintRange printRangeMode READ printRangeMode WRITE setPrintRangeMode NOTIFY printRangeModeChanged) | 47 | Q_PROPERTY(PrinterEnum::PrintRange printRangeMode READ printRangeMode WRITE setPrintRangeMode NOTIFY printRangeModeChanged) |
749 | 48 | Q_PROPERTY(int quality READ quality WRITE setQuality NOTIFY qualityChanged) | 48 | Q_PROPERTY(int quality READ quality WRITE setQuality NOTIFY qualityChanged) |
750 | 49 | Q_PROPERTY(bool reverse READ reverse WRITE setReverse NOTIFY reverseChanged) | 49 | Q_PROPERTY(bool reverse READ reverse WRITE setReverse NOTIFY reverseChanged) |
752 | 50 | Q_PROPERTY(PrinterEnum::State state READ state NOTIFY stateChanged) | 50 | Q_PROPERTY(PrinterEnum::JobState state READ state NOTIFY stateChanged) |
753 | 51 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | 51 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
754 | 52 | |||
755 | 53 | friend class PrinterCupsBackend; | ||
756 | 52 | public: | 54 | public: |
757 | 53 | explicit PrinterJob(QObject *parent=Q_NULLPTR); | 55 | explicit PrinterJob(QObject *parent=Q_NULLPTR); |
758 | 54 | explicit PrinterJob(Printer *printer, QObject *parent=Q_NULLPTR); | 56 | explicit PrinterJob(Printer *printer, QObject *parent=Q_NULLPTR); |
759 | 55 | explicit PrinterJob(Printer *printer, PrinterBackend *backend, | 57 | explicit PrinterJob(Printer *printer, PrinterBackend *backend, |
760 | 56 | QObject *parent=Q_NULLPTR); | 58 | QObject *parent=Q_NULLPTR); |
761 | 59 | explicit PrinterJob(const QString &name, PrinterBackend *backend, int jobId, QObject *parent=Q_NULLPTR); | ||
762 | 57 | ~PrinterJob(); | 60 | ~PrinterJob(); |
763 | 58 | 61 | ||
764 | 59 | bool collate() const; | 62 | bool collate() const; |
765 | @@ -62,6 +65,7 @@ | |||
766 | 62 | int copies() const; | 65 | int copies() const; |
767 | 63 | int duplexMode() const; | 66 | int duplexMode() const; |
768 | 64 | bool isTwoSided() const; | 67 | bool isTwoSided() const; |
769 | 68 | int jobId() const; // TODO: implement | ||
770 | 65 | bool landscape() const; | 69 | bool landscape() const; |
771 | 66 | // Printer *printer() const; | 70 | // Printer *printer() const; |
772 | 67 | QString printerName() const; | 71 | QString printerName() const; |
773 | @@ -69,7 +73,7 @@ | |||
774 | 69 | PrinterEnum::PrintRange printRangeMode() const; | 73 | PrinterEnum::PrintRange printRangeMode() const; |
775 | 70 | int quality() const; | 74 | int quality() const; |
776 | 71 | bool reverse() const; | 75 | bool reverse() const; |
778 | 72 | PrinterEnum::State state() const; | 76 | PrinterEnum::JobState state() const; |
779 | 73 | QString title() const; | 77 | QString title() const; |
780 | 74 | public Q_SLOTS: | 78 | public Q_SLOTS: |
781 | 75 | PrinterEnum::DuplexMode getDuplexMode() const; | 79 | PrinterEnum::DuplexMode getDuplexMode() const; |
782 | @@ -91,7 +95,7 @@ | |||
783 | 91 | private Q_SLOTS: | 95 | private Q_SLOTS: |
784 | 92 | void loadDefaults(); | 96 | void loadDefaults(); |
785 | 93 | void setIsTwoSided(const bool isTwoSided); | 97 | void setIsTwoSided(const bool isTwoSided); |
787 | 94 | void setState(const PrinterEnum::State &state); | 98 | void setState(const PrinterEnum::JobState &state); |
788 | 95 | Q_SIGNALS: | 99 | Q_SIGNALS: |
789 | 96 | void collateChanged(); | 100 | void collateChanged(); |
790 | 97 | void colorModelChanged(); | 101 | void colorModelChanged(); |
791 | @@ -115,6 +119,7 @@ | |||
792 | 115 | PrinterBackend *m_backend; // TODO: Maybe use the printer's backend? | 119 | PrinterBackend *m_backend; // TODO: Maybe use the printer's backend? |
793 | 116 | int m_duplex_mode; | 120 | int m_duplex_mode; |
794 | 117 | bool m_is_two_sided; | 121 | bool m_is_two_sided; |
795 | 122 | int m_job_id; | ||
796 | 118 | bool m_landscape; | 123 | bool m_landscape; |
797 | 119 | Printer *m_printer; | 124 | Printer *m_printer; |
798 | 120 | QString m_printer_name; | 125 | QString m_printer_name; |
799 | @@ -122,7 +127,7 @@ | |||
800 | 122 | PrinterEnum::PrintRange m_print_range_mode; | 127 | PrinterEnum::PrintRange m_print_range_mode; |
801 | 123 | int m_quality; | 128 | int m_quality; |
802 | 124 | bool m_reverse; | 129 | bool m_reverse; |
804 | 125 | PrinterEnum::State m_state; | 130 | PrinterEnum::JobState m_state; |
805 | 126 | QString m_title; | 131 | QString m_title; |
806 | 127 | }; | 132 | }; |
807 | 128 | 133 | ||
808 | 129 | 134 | ||
809 | === modified file 'tests/unittests/Printers/mockbackend.h' | |||
810 | --- tests/unittests/Printers/mockbackend.h 2017-02-02 17:23:30 +0000 | |||
811 | +++ tests/unittests/Printers/mockbackend.h 2017-02-02 17:23:30 +0000 | |||
812 | @@ -222,6 +222,11 @@ | |||
813 | 222 | 222 | ||
814 | 223 | } | 223 | } |
815 | 224 | 224 | ||
816 | 225 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(const QString &name) override | ||
817 | 226 | { | ||
818 | 227 | |||
819 | 228 | } | ||
820 | 229 | |||
821 | 225 | 230 | ||
822 | 226 | virtual QString printerName() const override | 231 | virtual QString printerName() const override |
823 | 227 | { | 232 | { |
Added a couple of comments.