Merge lp:~ahayzen/ubuntu-ui-extras/job-impressions-update into lp:~phablet-team/ubuntu-ui-extras/printer-staging
- job-impressions-update
- Merge into printer-staging
Status: | Superseded |
---|---|
Proposed branch: | lp:~ahayzen/ubuntu-ui-extras/job-impressions-update |
Merge into: | lp:~phablet-team/ubuntu-ui-extras/printer-staging |
Diff against target: |
1428 lines (+640/-196) 22 files modified
modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml (+1/-4) modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt (+2/-1) modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp (+15/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend.h (+6/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+113/-21) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h (+9/-0) modules/Ubuntu/Components/Extras/Printers/cups/jobloader.cpp (+90/-0) modules/Ubuntu/Components/Extras/Printers/cups/jobloader.h (+50/-0) modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp (+168/-97) modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h (+35/-9) modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+2/-18) modules/Ubuntu/Components/Extras/Printers/models/printermodel.h (+2/-3) modules/Ubuntu/Components/Extras/Printers/plugin.cpp (+1/-0) modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+12/-2) modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp (+32/-9) modules/Ubuntu/Components/Extras/Printers/printer/printerjob.h (+1/-2) modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp (+28/-6) modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h (+8/-6) modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+34/-7) po/ubuntu-ui-extras.pot (+2/-2) tests/unittests/Printers/CMakeLists.txt (+3/-3) tests/unittests/Printers/tst_signalratelimiter.cpp (+26/-6) |
To merge this branch: | bzr merge lp:~ahayzen/ubuntu-ui-extras/job-impressions-update |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonas G. Drange (community) | Needs Fixing | ||
Andrew Hayzen (community) | Needs Information | ||
Review via email: mp+319450@code.launchpad.net |
This proposal has been superseded by a proposal from 2017-03-13.
Commit message
* Connect job-impressions
* In the job model listen to printerStateChanged as changes t job-impressions
* Improve the PrinterSignalHa
* Add unit test for SignalRateLimiter to check it does perform a flush
* Rename PrinterSignalHa
Description of the change
* Connect job-impressions
* In the job model listen to printerStateChanged as changes t job-impressions
* Improve the PrinterSignalHa
* Add unit test for SignalRateLimiter to check it does perform a flush
* Rename PrinterSignalHa
- 148. By Andrew Hayzen
-
* Show impressions in the PrinterQueue.qml
Andrew Hayzen (ahayzen) wrote : | # |
Andrew Hayzen (ahayzen) wrote : | # |
Should job-media-
Jonas G. Drange (jonas-drange) wrote : | # |
ack on the rate limiter! good stuff
Jonas G. Drange (jonas-drange) wrote : | # |
Re: job-media-*, I'd have to read the IPP spec to be sure. Maybe mimic SCP here?
- 149. By Andrew Hayzen
-
* Merge of upstream
Jonas G. Drange (jonas-drange) wrote : | # |
Got this one:
void PrinterJob:
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaTy
Introduced by this branch?
Jonas G. Drange (jonas-drange) wrote : | # |
The window only freezes, no queues are displayed. I think we need to fix that.
And the freezing is introduced by this branch, because using printer-staging trunk, going to Printers.qml -> <printer> -> Jobs enumerates the jobs without the lag.
- 150. By Andrew Hayzen
-
* Rebase ontop of lp:~ahayzen/ubuntu-ui-extras/job-model-split-update
- 151. By Andrew Hayzen
-
* Pull of upstream
- 152. By Andrew Hayzen
-
* Use job-state from extendedJobAttr
ibutes so that when there is a signal flood the state is correct - 153. By Andrew Hayzen
-
* Pull of upstream
- 154. By Andrew Hayzen
-
* Try to use job-media-
sheets- completed first - 155. By Andrew Hayzen
-
* Pull of upstream
* Fix tests (emulation in MockBackend::printerGetJobA ttributes) - 156. By Andrew Hayzen
-
* Pull of upstream
Unmerged revisions
Preview Diff
1 | === modified file 'modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml' | |||
2 | --- modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 2017-03-01 13:45:14 +0000 | |||
3 | +++ modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 2017-03-13 12:51:30 +0000 | |||
4 | @@ -72,10 +72,7 @@ | |||
5 | 72 | ListItemLayout { | 72 | ListItemLayout { |
6 | 73 | id: modelLayout | 73 | id: modelLayout |
7 | 74 | title.text: displayName | 74 | title.text: displayName |
12 | 75 | subtitle.text: model.title + " (" + model.id + ") State: " + model.state | 75 | subtitle.text: model.title + " (" + model.id + ")\nPrinting " + model.impressionsCompleted + " pages" |
9 | 76 | + " Color: " + model.colorModel + " CreationTime: " | ||
10 | 77 | + model.creationTime + " PageRange: " | ||
11 | 78 | + model.printRange + " Messages: " + model.messages; | ||
13 | 79 | subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 76 | subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
14 | 80 | subtitle.maximumLineCount: 3 | 77 | subtitle.maximumLineCount: 3 |
15 | 81 | } | 78 | } |
16 | 82 | 79 | ||
17 | === modified file 'modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt' | |||
18 | --- modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 2017-03-08 14:47:16 +0000 | |||
19 | +++ modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 2017-03-13 12:51:30 +0000 | |||
20 | @@ -31,6 +31,7 @@ | |||
21 | 31 | 31 | ||
22 | 32 | cups/devicesearcher.cpp | 32 | cups/devicesearcher.cpp |
23 | 33 | cups/ippclient.cpp | 33 | cups/ippclient.cpp |
24 | 34 | cups/jobloader.cpp | ||
25 | 34 | cups/printerdriverloader.cpp | 35 | cups/printerdriverloader.cpp |
26 | 35 | cups/printerloader.cpp | 36 | cups/printerloader.cpp |
27 | 36 | 37 | ||
28 | @@ -41,7 +42,7 @@ | |||
29 | 41 | 42 | ||
30 | 42 | printer/printer.cpp | 43 | printer/printer.cpp |
31 | 43 | printer/printerjob.cpp | 44 | printer/printerjob.cpp |
33 | 44 | printer/printersignalhandler.cpp | 45 | printer/signalratelimiter.cpp |
34 | 45 | printers/printers.cpp | 46 | printers/printers.cpp |
35 | 46 | 47 | ||
36 | 47 | enums.h | 48 | enums.h |
37 | 48 | 49 | ||
38 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp' | |||
39 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-06 15:29:04 +0000 | |||
40 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-13 12:51:30 +0000 | |||
41 | @@ -174,6 +174,14 @@ | |||
42 | 174 | return QList<QSharedPointer<PrinterJob>>{}; | 174 | return QList<QSharedPointer<PrinterJob>>{}; |
43 | 175 | } | 175 | } |
44 | 176 | 176 | ||
45 | 177 | QSharedPointer<PrinterJob> PrinterBackend::printerGetJob( | ||
46 | 178 | const QString &printerName, const int jobId) | ||
47 | 179 | { | ||
48 | 180 | Q_UNUSED(printerName); | ||
49 | 181 | Q_UNUSED(jobId); | ||
50 | 182 | return QSharedPointer<PrinterJob>(Q_NULLPTR); | ||
51 | 183 | } | ||
52 | 184 | |||
53 | 177 | QMap<QString, QVariant> PrinterBackend::printerGetJobAttributes( | 185 | QMap<QString, QVariant> PrinterBackend::printerGetJobAttributes( |
54 | 178 | const QString &name, const int jobId) | 186 | const QString &name, const int jobId) |
55 | 179 | { | 187 | { |
56 | @@ -273,6 +281,13 @@ | |||
57 | 273 | return QString(); | 281 | return QString(); |
58 | 274 | } | 282 | } |
59 | 275 | 283 | ||
60 | 284 | void PrinterBackend::requestJobExtendedAttributes( | ||
61 | 285 | QSharedPointer<Printer> printer, QSharedPointer<PrinterJob> job) | ||
62 | 286 | { | ||
63 | 287 | Q_UNUSED(printer); | ||
64 | 288 | Q_UNUSED(job); | ||
65 | 289 | } | ||
66 | 290 | |||
67 | 276 | void PrinterBackend::requestPrinterDrivers() | 291 | void PrinterBackend::requestPrinterDrivers() |
68 | 277 | { | 292 | { |
69 | 278 | } | 293 | } |
70 | 279 | 294 | ||
71 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.h' | |||
72 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-09 14:34:05 +0000 | |||
73 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-13 12:51:30 +0000 | |||
74 | @@ -85,6 +85,8 @@ | |||
75 | 85 | const QString &title, | 85 | const QString &title, |
76 | 86 | const cups_dest_t *dest); | 86 | const cups_dest_t *dest); |
77 | 87 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(); | 87 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(); |
78 | 88 | virtual QSharedPointer<PrinterJob> printerGetJob(const QString &printerName, | ||
79 | 89 | const int jobId); | ||
80 | 88 | virtual QMap<QString, QVariant> printerGetJobAttributes( | 90 | virtual QMap<QString, QVariant> printerGetJobAttributes( |
81 | 89 | const QString &name, const int jobId); | 91 | const QString &name, const int jobId); |
82 | 90 | 92 | ||
83 | @@ -110,6 +112,8 @@ | |||
84 | 110 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName); | 112 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName); |
85 | 111 | virtual QString defaultPrinterName(); | 113 | virtual QString defaultPrinterName(); |
86 | 112 | 114 | ||
87 | 115 | virtual void requestJobExtendedAttributes(QSharedPointer<Printer> printer, | ||
88 | 116 | QSharedPointer<PrinterJob> job); | ||
89 | 113 | virtual void requestPrinterDrivers(); | 117 | virtual void requestPrinterDrivers(); |
90 | 114 | virtual void requestPrinter(const QString &printerName); | 118 | virtual void requestPrinter(const QString &printerName); |
91 | 115 | 119 | ||
92 | @@ -124,6 +128,8 @@ | |||
93 | 124 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); | 128 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); |
94 | 125 | void printerDriversFailedToLoad(const QString &errorMessage); | 129 | void printerDriversFailedToLoad(const QString &errorMessage); |
95 | 126 | 130 | ||
96 | 131 | void jobLoaded(QSharedPointer<PrinterJob> oldJob, | ||
97 | 132 | QSharedPointer<PrinterJob> newJob); | ||
98 | 127 | void printerLoaded(QSharedPointer<Printer> printers); | 133 | void printerLoaded(QSharedPointer<Printer> printers); |
99 | 128 | void deviceFound(const Device &device); | 134 | void deviceFound(const Device &device); |
100 | 129 | void deviceSearchFinished(); | 135 | void deviceSearchFinished(); |
101 | 130 | 136 | ||
102 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp' | |||
103 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-09 14:34:05 +0000 | |||
104 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-13 12:51:30 +0000 | |||
105 | @@ -16,6 +16,7 @@ | |||
106 | 16 | 16 | ||
107 | 17 | #include "backend/backend_cups.h" | 17 | #include "backend/backend_cups.h" |
108 | 18 | #include "cups/devicesearcher.h" | 18 | #include "cups/devicesearcher.h" |
109 | 19 | #include "cups/jobloader.h" | ||
110 | 19 | #include "cups/printerdriverloader.h" | 20 | #include "cups/printerdriverloader.h" |
111 | 20 | #include "cups/printerloader.h" | 21 | #include "cups/printerloader.h" |
112 | 21 | #include "utils.h" | 22 | #include "utils.h" |
113 | @@ -455,12 +456,30 @@ | |||
114 | 455 | map.insert("ColorModel", QVariant("")); | 456 | map.insert("ColorModel", QVariant("")); |
115 | 456 | } | 457 | } |
116 | 457 | 458 | ||
117 | 459 | if (__CUPS_ATTR_EXISTS(rawMap, "date-time-at-completed", QDateTime)) { | ||
118 | 460 | map.insert("CompletedTime", rawMap.value("date-time-at-completed")); | ||
119 | 461 | } else { | ||
120 | 462 | map.insert("CompletedTime", QVariant(QDateTime())); | ||
121 | 463 | } | ||
122 | 464 | |||
123 | 465 | if (__CUPS_ATTR_EXISTS(rawMap, "date-time-at-creation", QDateTime)) { | ||
124 | 466 | map.insert("CreationTime", rawMap.value("date-time-at-creation")); | ||
125 | 467 | } else { | ||
126 | 468 | map.insert("CreationTime", QVariant(QDateTime())); | ||
127 | 469 | } | ||
128 | 470 | |||
129 | 458 | if (__CUPS_ATTR_EXISTS(rawMap, "Duplex", QString)) { | 471 | if (__CUPS_ATTR_EXISTS(rawMap, "Duplex", QString)) { |
130 | 459 | map.insert("Duplex", rawMap.value("Duplex")); | 472 | map.insert("Duplex", rawMap.value("Duplex")); |
131 | 460 | } else { | 473 | } else { |
132 | 461 | map.insert("Duplex", QVariant("")); | 474 | map.insert("Duplex", QVariant("")); |
133 | 462 | } | 475 | } |
134 | 463 | 476 | ||
135 | 477 | if (__CUPS_ATTR_EXISTS(rawMap, "job-impressions-completed", int)) { | ||
136 | 478 | map.insert("impressionsCompleted", rawMap.value("job-impressions-completed")); | ||
137 | 479 | } else { | ||
138 | 480 | map.insert("impressionsCompleted", QVariant(0)); | ||
139 | 481 | } | ||
140 | 482 | |||
141 | 464 | if (__CUPS_ATTR_EXISTS(rawMap, "landscape", bool)) { | 483 | if (__CUPS_ATTR_EXISTS(rawMap, "landscape", bool)) { |
142 | 465 | map.insert("landscape", rawMap.value("landscape")); | 484 | map.insert("landscape", rawMap.value("landscape")); |
143 | 466 | } else { | 485 | } else { |
144 | @@ -480,6 +499,12 @@ | |||
145 | 480 | map.insert("page-ranges", QVariant(QStringList())); | 499 | map.insert("page-ranges", QVariant(QStringList())); |
146 | 481 | } | 500 | } |
147 | 482 | 501 | ||
148 | 502 | if (__CUPS_ATTR_EXISTS(rawMap, "date-time-at-processing", QDateTime)) { | ||
149 | 503 | map.insert("ProcessingTime", rawMap.value("date-time-at-processing")); | ||
150 | 504 | } else { | ||
151 | 505 | map.insert("ProcessingTime", QVariant(QDateTime())); | ||
152 | 506 | } | ||
153 | 507 | |||
154 | 483 | Q_FOREACH(QString qualityOption, m_knownQualityOptions) { | 508 | Q_FOREACH(QString qualityOption, m_knownQualityOptions) { |
155 | 484 | if (rawMap.contains(qualityOption) | 509 | if (rawMap.contains(qualityOption) |
156 | 485 | && rawMap.value(qualityOption).canConvert<QString>()) { | 510 | && rawMap.value(qualityOption).canConvert<QString>()) { |
157 | @@ -497,6 +522,18 @@ | |||
158 | 497 | map.insert("OutputOrder", "Normal"); | 522 | map.insert("OutputOrder", "Normal"); |
159 | 498 | } | 523 | } |
160 | 499 | 524 | ||
161 | 525 | if (__CUPS_ATTR_EXISTS(rawMap, "job-k-octets", int)) { | ||
162 | 526 | map.insert("Size", rawMap.value("job-k-octets")); | ||
163 | 527 | } else { | ||
164 | 528 | map.insert("Size", QVariant(0)); | ||
165 | 529 | } | ||
166 | 530 | |||
167 | 531 | if (__CUPS_ATTR_EXISTS(rawMap, "job-originating-user-name", QString)) { | ||
168 | 532 | map.insert("User", rawMap.value("job-originating-user-name")); | ||
169 | 533 | } else { | ||
170 | 534 | map.insert("User", QVariant("")); | ||
171 | 535 | } | ||
172 | 536 | |||
173 | 500 | // Generate a list of messages | 537 | // Generate a list of messages |
174 | 501 | // TODO: for now just using job-printer-state-message, are there others? | 538 | // TODO: for now just using job-printer-state-message, are there others? |
175 | 502 | QStringList messages; | 539 | QStringList messages; |
176 | @@ -516,32 +553,16 @@ | |||
177 | 516 | auto jobs = getCupsJobs(); | 553 | auto jobs = getCupsJobs(); |
178 | 517 | QList<QSharedPointer<PrinterJob>> list; | 554 | QList<QSharedPointer<PrinterJob>> list; |
179 | 518 | 555 | ||
180 | 556 | // TODO: once printerGetJob() only gets a single job | ||
181 | 557 | // use that to build PrinterJob | ||
182 | 519 | Q_FOREACH(auto job, jobs) { | 558 | Q_FOREACH(auto job, jobs) { |
183 | 559 | // Note: extended attributes are not loaded here | ||
184 | 560 | // they are loaded in JobLoader | ||
185 | 520 | auto newJob = QSharedPointer<PrinterJob>( | 561 | auto newJob = QSharedPointer<PrinterJob>( |
186 | 521 | new PrinterJob(QString::fromUtf8(job->dest), this, job->id) | 562 | new PrinterJob(QString::fromUtf8(job->dest), this, job->id) |
187 | 522 | ); | 563 | ); |
188 | 523 | |||
189 | 524 | // Extract the times | ||
190 | 525 | QDateTime completedTime; | ||
191 | 526 | completedTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
192 | 527 | completedTime.setTime_t(job->completed_time); | ||
193 | 528 | |||
194 | 529 | QDateTime creationTime; | ||
195 | 530 | creationTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
196 | 531 | creationTime.setTime_t(job->creation_time); | ||
197 | 532 | |||
198 | 533 | QDateTime processingTime; | ||
199 | 534 | processingTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
200 | 535 | processingTime.setTime_t(job->processing_time); | ||
201 | 536 | |||
202 | 537 | // Load the information from the cups struct | ||
203 | 538 | newJob->setCompletedTime(completedTime); | ||
204 | 539 | newJob->setCreationTime(creationTime); | ||
205 | 540 | newJob->setProcessingTime(processingTime); | ||
206 | 541 | newJob->setSize(job->size); | ||
207 | 542 | newJob->setState(static_cast<PrinterEnum::JobState>(job->state)); | 564 | newJob->setState(static_cast<PrinterEnum::JobState>(job->state)); |
208 | 543 | newJob->setTitle(QString::fromLocal8Bit(job->title)); | 565 | newJob->setTitle(QString::fromLocal8Bit(job->title)); |
209 | 544 | newJob->setUser(QString::fromLocal8Bit(job->user)); | ||
210 | 545 | 566 | ||
211 | 546 | list.append(newJob); | 567 | list.append(newJob); |
212 | 547 | } | 568 | } |
213 | @@ -551,6 +572,38 @@ | |||
214 | 551 | return list; | 572 | return list; |
215 | 552 | } | 573 | } |
216 | 553 | 574 | ||
217 | 575 | QSharedPointer<PrinterJob> PrinterCupsBackend::printerGetJob( | ||
218 | 576 | const QString &printerName, const int jobId) | ||
219 | 577 | { | ||
220 | 578 | // FIXME: this gets all the jobs for the printer | ||
221 | 579 | // can we get a single one? | ||
222 | 580 | // instead can we ask via IPP? | ||
223 | 581 | auto jobs = getCupsJobs(printerName); | ||
224 | 582 | cups_job_t *cupsJob = Q_NULLPTR; | ||
225 | 583 | QSharedPointer<PrinterJob> job(Q_NULLPTR); | ||
226 | 584 | |||
227 | 585 | for (int i=0; i < jobs.size(); i++) { | ||
228 | 586 | if (jobs.at(i)->id == jobId) { | ||
229 | 587 | cupsJob = jobs.at(i); | ||
230 | 588 | break; | ||
231 | 589 | } | ||
232 | 590 | } | ||
233 | 591 | |||
234 | 592 | if (cupsJob) { | ||
235 | 593 | job = QSharedPointer<PrinterJob>( | ||
236 | 594 | new PrinterJob(QString::fromUtf8(cupsJob->dest), this, cupsJob->id) | ||
237 | 595 | ); | ||
238 | 596 | |||
239 | 597 | job->setState(static_cast<PrinterEnum::JobState>(cupsJob->state)); | ||
240 | 598 | job->setTitle(QString::fromLocal8Bit(cupsJob->title)); | ||
241 | 599 | } | ||
242 | 600 | |||
243 | 601 | if (!jobs.size()) | ||
244 | 602 | cupsFreeJobs(jobs.size(), jobs.first()); | ||
245 | 603 | |||
246 | 604 | return job; | ||
247 | 605 | } | ||
248 | 606 | |||
249 | 554 | QString PrinterCupsBackend::printerName() const | 607 | QString PrinterCupsBackend::printerName() const |
250 | 555 | { | 608 | { |
251 | 556 | return m_printerName; | 609 | return m_printerName; |
252 | @@ -662,6 +715,34 @@ | |||
253 | 662 | return QPrinterInfo::defaultPrinterName(); | 715 | return QPrinterInfo::defaultPrinterName(); |
254 | 663 | } | 716 | } |
255 | 664 | 717 | ||
256 | 718 | void PrinterCupsBackend::requestJobExtendedAttributes( | ||
257 | 719 | QSharedPointer<Printer> printer, QSharedPointer<PrinterJob> job) | ||
258 | 720 | { | ||
259 | 721 | QPair<QString, int> pair(printer->name(), job->jobId()); | ||
260 | 722 | |||
261 | 723 | if (m_activeJobRequests.contains(pair)) { | ||
262 | 724 | return; | ||
263 | 725 | } | ||
264 | 726 | |||
265 | 727 | auto thread = new QThread; | ||
266 | 728 | auto loader = new JobLoader(printer, job, this); | ||
267 | 729 | loader->moveToThread(thread); | ||
268 | 730 | connect(thread, SIGNAL(started()), loader, SLOT(load())); | ||
269 | 731 | connect(loader, SIGNAL(finished()), thread, SLOT(quit())); | ||
270 | 732 | connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater())); | ||
271 | 733 | connect(loader, SIGNAL(loaded(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>)), | ||
272 | 734 | this, SIGNAL(jobLoaded(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>))); | ||
273 | 735 | connect(loader, SIGNAL(printerLoaded(QSharedPointer<Printer>)), | ||
274 | 736 | this, SIGNAL(printerLoaded(QSharedPointer<Printer>))); | ||
275 | 737 | connect(loader, SIGNAL(loaded(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>)), | ||
276 | 738 | this, SLOT(onJobLoaded(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>))); | ||
277 | 739 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | ||
278 | 740 | |||
279 | 741 | m_activeJobRequests << pair; | ||
280 | 742 | |||
281 | 743 | thread->start(); | ||
282 | 744 | } | ||
283 | 745 | |||
284 | 665 | void PrinterCupsBackend::requestPrinter(const QString &printerName) | 746 | void PrinterCupsBackend::requestPrinter(const QString &printerName) |
285 | 666 | { | 747 | { |
286 | 667 | if (m_activeRequests.contains(printerName)) { | 748 | if (m_activeRequests.contains(printerName)) { |
287 | @@ -679,9 +760,10 @@ | |||
288 | 679 | connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)), | 760 | connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)), |
289 | 680 | this, SLOT(onPrinterLoaded(QSharedPointer<Printer>))); | 761 | this, SLOT(onPrinterLoaded(QSharedPointer<Printer>))); |
290 | 681 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | 762 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); |
291 | 682 | thread->start(); | ||
292 | 683 | 763 | ||
293 | 684 | m_activeRequests << printerName; | 764 | m_activeRequests << printerName; |
294 | 765 | |||
295 | 766 | thread->start(); | ||
296 | 685 | } | 767 | } |
297 | 686 | 768 | ||
298 | 687 | void PrinterCupsBackend::requestPrinterDrivers() | 769 | void PrinterCupsBackend::requestPrinterDrivers() |
299 | @@ -698,6 +780,7 @@ | |||
300 | 698 | connect(loader, SIGNAL(loaded(const QList<PrinterDriver>&)), | 780 | connect(loader, SIGNAL(loaded(const QList<PrinterDriver>&)), |
301 | 699 | this, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&))); | 781 | this, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&))); |
302 | 700 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | 782 | connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); |
303 | 783 | |||
304 | 701 | thread->start(); | 784 | thread->start(); |
305 | 702 | } | 785 | } |
306 | 703 | 786 | ||
307 | @@ -788,6 +871,15 @@ | |||
308 | 788 | return m_extendedAttributeNames.contains(attributeName); | 871 | return m_extendedAttributeNames.contains(attributeName); |
309 | 789 | } | 872 | } |
310 | 790 | 873 | ||
311 | 874 | void PrinterCupsBackend::onJobLoaded(QSharedPointer<PrinterJob> oldJob, | ||
312 | 875 | QSharedPointer<PrinterJob> newJob) | ||
313 | 876 | { | ||
314 | 877 | Q_UNUSED(newJob); | ||
315 | 878 | |||
316 | 879 | QPair<QString, int> pair(oldJob->printerName(), oldJob->jobId()); | ||
317 | 880 | m_activeJobRequests.remove(pair); | ||
318 | 881 | } | ||
319 | 882 | |||
320 | 791 | void PrinterCupsBackend::onPrinterLoaded(QSharedPointer<Printer> printer) | 883 | void PrinterCupsBackend::onPrinterLoaded(QSharedPointer<Printer> printer) |
321 | 792 | { | 884 | { |
322 | 793 | m_activeRequests.remove(printer->name()); | 885 | m_activeRequests.remove(printer->name()); |
323 | 794 | 886 | ||
324 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h' | |||
325 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-08 11:30:48 +0000 | |||
326 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-13 12:51:30 +0000 | |||
327 | @@ -79,6 +79,8 @@ | |||
328 | 79 | const QString &title, | 79 | const QString &title, |
329 | 80 | const cups_dest_t *dest) override; | 80 | const cups_dest_t *dest) override; |
330 | 81 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs() override; | 81 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs() override; |
331 | 82 | virtual QSharedPointer<PrinterJob> printerGetJob( | ||
332 | 83 | const QString &printerName, const int jobId) override; | ||
333 | 82 | 84 | ||
334 | 83 | virtual QString printerName() const override; | 85 | virtual QString printerName() const override; |
335 | 84 | virtual QString description() const override; | 86 | virtual QString description() const override; |
336 | @@ -101,6 +103,10 @@ | |||
337 | 101 | virtual QStringList availablePrinterNames() override; | 103 | virtual QStringList availablePrinterNames() override; |
338 | 102 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName) override; | 104 | virtual QSharedPointer<Printer> getPrinter(const QString &printerName) override; |
339 | 103 | virtual QString defaultPrinterName() override; | 105 | virtual QString defaultPrinterName() override; |
340 | 106 | |||
341 | 107 | virtual void requestJobExtendedAttributes( | ||
342 | 108 | QSharedPointer<Printer> printer, | ||
343 | 109 | QSharedPointer<PrinterJob> job) override; | ||
344 | 104 | virtual void requestPrinterDrivers() override; | 110 | virtual void requestPrinterDrivers() override; |
345 | 105 | virtual void requestPrinter(const QString &printerName) override; | 111 | virtual void requestPrinter(const QString &printerName) override; |
346 | 106 | virtual QMap<QString, QVariant> printerGetJobAttributes( | 112 | virtual QMap<QString, QVariant> printerGetJobAttributes( |
347 | @@ -141,8 +147,11 @@ | |||
348 | 141 | mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest. | 147 | mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest. |
349 | 142 | mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd. | 148 | mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd. |
350 | 143 | QSet<QString> m_activeRequests; | 149 | QSet<QString> m_activeRequests; |
351 | 150 | QSet<QPair<QString, int>> m_activeJobRequests; | ||
352 | 144 | 151 | ||
353 | 145 | private Q_SLOTS: | 152 | private Q_SLOTS: |
354 | 153 | void onJobLoaded(QSharedPointer<PrinterJob> oldJob, | ||
355 | 154 | QSharedPointer<PrinterJob> newJob); | ||
356 | 146 | void onPrinterLoaded(QSharedPointer<Printer> printer); | 155 | void onPrinterLoaded(QSharedPointer<Printer> printer); |
357 | 147 | }; | 156 | }; |
358 | 148 | 157 | ||
359 | 149 | 158 | ||
360 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/jobloader.cpp' | |||
361 | --- modules/Ubuntu/Components/Extras/Printers/cups/jobloader.cpp 1970-01-01 00:00:00 +0000 | |||
362 | +++ modules/Ubuntu/Components/Extras/Printers/cups/jobloader.cpp 2017-03-13 12:51:30 +0000 | |||
363 | @@ -0,0 +1,90 @@ | |||
364 | 1 | /* | ||
365 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
366 | 3 | * | ||
367 | 4 | * This program is free software; you can redistribute it and/or modify | ||
368 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
369 | 6 | * the Free Software Foundation; version 3. | ||
370 | 7 | * | ||
371 | 8 | * This program is distributed in the hope that it will be useful, | ||
372 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
373 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
374 | 11 | * GNU Lesser General Public License for more details. | ||
375 | 12 | * | ||
376 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
377 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
378 | 15 | */ | ||
379 | 16 | |||
380 | 17 | #include "jobloader.h" | ||
381 | 18 | |||
382 | 19 | #include "backend/backend_cups.h" | ||
383 | 20 | |||
384 | 21 | #include "cups/ippclient.h" | ||
385 | 22 | #include "cupsdnotifier.h" // Note: this file was generated. | ||
386 | 23 | |||
387 | 24 | #include "printers/printers.h" | ||
388 | 25 | |||
389 | 26 | #include <QDBusConnection> | ||
390 | 27 | #include <QPrinterInfo> | ||
391 | 28 | |||
392 | 29 | class PrinterCupsBackend; | ||
393 | 30 | JobLoader::JobLoader(QSharedPointer<Printer> printer, | ||
394 | 31 | QSharedPointer<PrinterJob> printerJob, | ||
395 | 32 | PrinterBackend *backend, | ||
396 | 33 | QObject *parent) | ||
397 | 34 | : QObject(parent) | ||
398 | 35 | , m_backend(backend) | ||
399 | 36 | , m_job(printerJob) | ||
400 | 37 | , m_printer(printer) | ||
401 | 38 | { | ||
402 | 39 | } | ||
403 | 40 | |||
404 | 41 | JobLoader::~JobLoader() | ||
405 | 42 | { | ||
406 | 43 | } | ||
407 | 44 | |||
408 | 45 | void JobLoader::load() | ||
409 | 46 | { | ||
410 | 47 | QSharedPointer<Printer> printer; | ||
411 | 48 | PrinterBackend *backend; | ||
412 | 49 | |||
413 | 50 | // FIXME: always build a new Printer and IppClient as it isn't thread safe | ||
414 | 51 | if (true || m_printer->type() == PrinterEnum::PrinterType::ProxyType) { | ||
415 | 52 | IppClient *client = new IppClient(); | ||
416 | 53 | OrgCupsCupsdNotifierInterface* notifier = new OrgCupsCupsdNotifierInterface( | ||
417 | 54 | "", CUPSD_NOTIFIER_DBUS_PATH, QDBusConnection::systemBus()); | ||
418 | 55 | QPrinterInfo info = QPrinterInfo::printerInfo(m_printer->name()); | ||
419 | 56 | |||
420 | 57 | backend = new PrinterCupsBackend(client, info, notifier); | ||
421 | 58 | printer = QSharedPointer<Printer>(new Printer(backend)); | ||
422 | 59 | } else { | ||
423 | 60 | backend = m_backend; | ||
424 | 61 | printer = m_printer; | ||
425 | 62 | } | ||
426 | 63 | |||
427 | 64 | // Construct a job | ||
428 | 65 | QSharedPointer<PrinterJob> job = QSharedPointer<PrinterJob>( | ||
429 | 66 | new PrinterJob(m_printer->name(), backend, m_job->jobId()) | ||
430 | 67 | ); | ||
431 | 68 | |||
432 | 69 | // Copy things that we don't set in extended attributes | ||
433 | 70 | job->setImpressionsCompleted(m_job->impressionsCompleted()); | ||
434 | 71 | job->setState(m_job->state()); | ||
435 | 72 | job->setTitle(m_job->title()); | ||
436 | 73 | |||
437 | 74 | // Set the printer for this thread | ||
438 | 75 | job->setPrinter(printer); | ||
439 | 76 | |||
440 | 77 | // Load the extended attributes of the job | ||
441 | 78 | job->loadDefaults(); | ||
442 | 79 | |||
443 | 80 | Q_EMIT loaded(m_job, job); | ||
444 | 81 | |||
445 | 82 | // If the given Printer was not loaded expose our loaded one | ||
446 | 83 | // FIXME: for now skip this, need to check if having different | ||
447 | 84 | // notifier/ippClient/backend could cause issues? | ||
448 | 85 | if (false && m_printer->type() == PrinterEnum::PrinterType::ProxyType) { | ||
449 | 86 | Q_EMIT printerLoaded(printer); | ||
450 | 87 | } | ||
451 | 88 | |||
452 | 89 | Q_EMIT finished(); | ||
453 | 90 | } | ||
454 | 0 | 91 | ||
455 | === added file 'modules/Ubuntu/Components/Extras/Printers/cups/jobloader.h' | |||
456 | --- modules/Ubuntu/Components/Extras/Printers/cups/jobloader.h 1970-01-01 00:00:00 +0000 | |||
457 | +++ modules/Ubuntu/Components/Extras/Printers/cups/jobloader.h 2017-03-13 12:51:30 +0000 | |||
458 | @@ -0,0 +1,50 @@ | |||
459 | 1 | /* | ||
460 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
461 | 3 | * | ||
462 | 4 | * This program is free software; you can redistribute it and/or modify | ||
463 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
464 | 6 | * the Free Software Foundation; version 3. | ||
465 | 7 | * | ||
466 | 8 | * This program is distributed in the hope that it will be useful, | ||
467 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
468 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
469 | 11 | * GNU Lesser General Public License for more details. | ||
470 | 12 | * | ||
471 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
472 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
473 | 15 | */ | ||
474 | 16 | |||
475 | 17 | #ifndef USC_PRINTERS_CUPS_JOBLOADER_H | ||
476 | 18 | #define USC_PRINTERS_CUPS_JOBLOADER_H | ||
477 | 19 | |||
478 | 20 | #include "printer/printer.h" | ||
479 | 21 | #include "printer/printerjob.h" | ||
480 | 22 | |||
481 | 23 | #include <QList> | ||
482 | 24 | #include <QObject> | ||
483 | 25 | #include <QSharedPointer> | ||
484 | 26 | |||
485 | 27 | class JobLoader : public QObject | ||
486 | 28 | { | ||
487 | 29 | Q_OBJECT | ||
488 | 30 | PrinterBackend *m_backend; | ||
489 | 31 | QSharedPointer<PrinterJob> m_job; | ||
490 | 32 | QSharedPointer<Printer> m_printer; | ||
491 | 33 | public: | ||
492 | 34 | explicit JobLoader(QSharedPointer<Printer> printer, | ||
493 | 35 | QSharedPointer<PrinterJob> printerJob, | ||
494 | 36 | PrinterBackend *backend, | ||
495 | 37 | QObject *parent = Q_NULLPTR); | ||
496 | 38 | ~JobLoader(); | ||
497 | 39 | |||
498 | 40 | public Q_SLOTS: | ||
499 | 41 | void load(); | ||
500 | 42 | |||
501 | 43 | Q_SIGNALS: | ||
502 | 44 | void finished(); | ||
503 | 45 | void loaded(QSharedPointer<PrinterJob> oldJob, | ||
504 | 46 | QSharedPointer<PrinterJob> newJob); | ||
505 | 47 | void printerLoaded(QSharedPointer<Printer> printer); | ||
506 | 48 | }; | ||
507 | 49 | |||
508 | 50 | #endif // USC_PRINTERS_CUPS_JOBLOADER_H | ||
509 | 0 | 51 | ||
510 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp' | |||
511 | --- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 2017-03-06 13:19:08 +0000 | |||
512 | +++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 2017-03-13 12:51:30 +0000 | |||
513 | @@ -31,113 +31,184 @@ | |||
514 | 31 | : QAbstractListModel(parent) | 31 | : QAbstractListModel(parent) |
515 | 32 | , m_backend(backend) | 32 | , m_backend(backend) |
516 | 33 | { | 33 | { |
517 | 34 | update(); | ||
518 | 35 | |||
519 | 36 | QObject::connect(m_backend, &PrinterBackend::jobCreated, | 34 | QObject::connect(m_backend, &PrinterBackend::jobCreated, |
521 | 37 | this, &JobModel::jobSignalCatchAll); | 35 | this, &JobModel::jobCreated); |
522 | 38 | QObject::connect(m_backend, &PrinterBackend::jobState, | 36 | QObject::connect(m_backend, &PrinterBackend::jobState, |
524 | 39 | this, &JobModel::jobSignalCatchAll); | 37 | this, &JobModel::jobState); |
525 | 40 | QObject::connect(m_backend, &PrinterBackend::jobCompleted, | 38 | QObject::connect(m_backend, &PrinterBackend::jobCompleted, |
527 | 41 | this, &JobModel::jobSignalCatchAll); | 39 | this, &JobModel::jobCompleted); |
528 | 40 | |||
529 | 41 | connect(m_backend, SIGNAL(jobLoaded(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>)), | ||
530 | 42 | this, SLOT(updateJob(QSharedPointer<PrinterJob>, QSharedPointer<PrinterJob>))); | ||
531 | 43 | |||
532 | 44 | // Impressions completed happens via printer state changed | ||
533 | 45 | QObject::connect(m_backend, &PrinterBackend::printerStateChanged, | ||
534 | 46 | &m_signalHandler, &SignalRateLimiter::onPrinterStateChanged); | ||
535 | 47 | |||
536 | 48 | QObject::connect(&m_signalHandler, SIGNAL(printerModified(const QString&)), | ||
537 | 49 | this, SLOT(jobSignalPrinterModified(const QString&))); | ||
538 | 50 | |||
539 | 51 | // Add already existing jobs | ||
540 | 52 | // FIXME: even this should probably be in a background thread? | ||
541 | 53 | // so that it doesn't block startup? | ||
542 | 54 | Q_FOREACH(auto job, m_backend->printerGetJobs()) { | ||
543 | 55 | addJob(job); | ||
544 | 56 | } | ||
545 | 42 | } | 57 | } |
546 | 43 | 58 | ||
547 | 44 | JobModel::~JobModel() | 59 | JobModel::~JobModel() |
548 | 45 | { | 60 | { |
549 | 46 | } | 61 | } |
550 | 47 | 62 | ||
565 | 48 | void JobModel::jobSignalCatchAll( | 63 | void JobModel::jobCreated( |
566 | 49 | const QString &text, const QString &printer_uri, | 64 | const QString &text, const QString &printer_uri, |
567 | 50 | const QString &printer_name, uint printer_state, | 65 | const QString &printer_name, uint printer_state, |
568 | 51 | const QString &printer_state_reasons, bool printer_is_accepting_jobs, | 66 | const QString &printer_state_reasons, bool printer_is_accepting_jobs, |
569 | 52 | uint job_id, uint job_state, const QString &job_state_reasons, | 67 | uint job_id, uint job_state, const QString &job_state_reasons, |
570 | 53 | const QString &job_name, uint job_impressions_completed) | 68 | const QString &job_name, uint job_impressions_completed) |
571 | 54 | { | 69 | { |
572 | 55 | Q_UNUSED(text); | 70 | Q_UNUSED(text); // "Job Created" |
573 | 56 | Q_UNUSED(printer_uri); | 71 | Q_UNUSED(printer_uri); |
574 | 57 | Q_UNUSED(printer_name); | 72 | Q_UNUSED(printer_state); |
575 | 58 | Q_UNUSED(printer_state); | 73 | Q_UNUSED(printer_state_reasons); |
576 | 59 | Q_UNUSED(printer_state_reasons); | 74 | Q_UNUSED(printer_is_accepting_jobs); |
577 | 60 | Q_UNUSED(printer_is_accepting_jobs); | 75 | Q_UNUSED(job_state_reasons); |
578 | 61 | Q_UNUSED(job_id); | 76 | |
579 | 77 | QSharedPointer<PrinterJob> job = QSharedPointer<PrinterJob>( | ||
580 | 78 | new PrinterJob(printer_name, m_backend, job_id) | ||
581 | 79 | ); | ||
582 | 80 | job->setImpressionsCompleted(job_impressions_completed); | ||
583 | 81 | job->setState(static_cast<PrinterEnum::JobState>(job_state)); | ||
584 | 82 | job->setTitle(job_name); | ||
585 | 83 | |||
586 | 84 | // Printers listens to rowInserted and spawns a JobLoader to set the | ||
587 | 85 | // printer of the job, which triggers the extended attributes to be loaded | ||
588 | 86 | // once complete this triggers JobModel::updateJob | ||
589 | 87 | addJob(job); | ||
590 | 88 | } | ||
591 | 89 | |||
592 | 90 | void JobModel::jobState( | ||
593 | 91 | const QString &text, const QString &printer_uri, | ||
594 | 92 | const QString &printer_name, uint printer_state, | ||
595 | 93 | const QString &printer_state_reasons, bool printer_is_accepting_jobs, | ||
596 | 94 | uint job_id, uint job_state, const QString &job_state_reasons, | ||
597 | 95 | const QString &job_name, uint job_impressions_completed) | ||
598 | 96 | { | ||
599 | 97 | Q_UNUSED(text); | ||
600 | 98 | Q_UNUSED(printer_uri); | ||
601 | 99 | Q_UNUSED(printer_state); | ||
602 | 100 | Q_UNUSED(printer_state_reasons); | ||
603 | 101 | Q_UNUSED(printer_is_accepting_jobs); | ||
604 | 102 | Q_UNUSED(job_state_reasons); | ||
605 | 103 | Q_UNUSED(job_name); | ||
606 | 104 | |||
607 | 105 | QSharedPointer<PrinterJob> job = getJob(printer_name, job_id); | ||
608 | 106 | |||
609 | 107 | if (job) { | ||
610 | 108 | job->setImpressionsCompleted(job_impressions_completed); | ||
611 | 109 | job->setState(static_cast<PrinterEnum::JobState>(job_state)); | ||
612 | 110 | |||
613 | 111 | updateJob(job); | ||
614 | 112 | } else { | ||
615 | 113 | qWarning() << "JobModel::jobState for unknown job: " << job_name << " (" | ||
616 | 114 | << job_id << ") for " << printer_name; | ||
617 | 115 | } | ||
618 | 116 | } | ||
619 | 117 | |||
620 | 118 | void JobModel::jobCompleted( | ||
621 | 119 | const QString &text, const QString &printer_uri, | ||
622 | 120 | const QString &printer_name, uint printer_state, | ||
623 | 121 | const QString &printer_state_reasons, bool printer_is_accepting_jobs, | ||
624 | 122 | uint job_id, uint job_state, const QString &job_state_reasons, | ||
625 | 123 | const QString &job_name, uint job_impressions_completed) | ||
626 | 124 | { | ||
627 | 125 | Q_UNUSED(text); | ||
628 | 126 | Q_UNUSED(printer_uri); | ||
629 | 127 | Q_UNUSED(printer_state); | ||
630 | 128 | Q_UNUSED(printer_state_reasons); | ||
631 | 129 | Q_UNUSED(printer_is_accepting_jobs); | ||
632 | 62 | Q_UNUSED(job_state); | 130 | Q_UNUSED(job_state); |
633 | 63 | Q_UNUSED(job_state_reasons); | 131 | Q_UNUSED(job_state_reasons); |
634 | 64 | Q_UNUSED(job_name); | 132 | Q_UNUSED(job_name); |
711 | 65 | 133 | Q_UNUSED(job_impressions_completed); | |
712 | 66 | auto job = getJobById(job_id); | 134 | |
713 | 67 | if (job) | 135 | auto job = getJob(printer_name, job_id); |
714 | 68 | job->setImpressionsCompleted(job_impressions_completed); | 136 | if (job) { |
715 | 69 | 137 | removeJob(job); | |
716 | 70 | update(); | 138 | } else { |
717 | 71 | } | 139 | qWarning() << "JobModel::jobCompleted for unknown job: " << job_name << " (" |
718 | 72 | 140 | << job_id << ") for " << printer_name; | |
719 | 73 | void JobModel::update() | 141 | } |
720 | 74 | { | 142 | } |
721 | 75 | // Store the old count and get the new printers | 143 | |
722 | 76 | int oldCount = m_jobs.size(); | 144 | void JobModel::jobSignalPrinterModified(const QString &printerName) |
723 | 77 | QList<QSharedPointer<PrinterJob>> newJobs = m_backend->printerGetJobs(); | 145 | { |
724 | 78 | 146 | qDebug() << Q_FUNC_INFO << printerName; | |
725 | 79 | // Go through the old model | 147 | |
726 | 80 | for (int i=0; i < m_jobs.count(); i++) { | 148 | // Find the active job and force a refresh |
727 | 81 | // Determine if the old printer exists in the new model | 149 | Q_FOREACH(auto job, m_jobs) { |
728 | 82 | bool exists = false; | 150 | if (job->printerName() == printerName |
729 | 83 | 151 | && job->state() == PrinterEnum::JobState::Processing) { | |
730 | 84 | Q_FOREACH(QSharedPointer<PrinterJob> p, newJobs) { | 152 | qDebug() << Q_FUNC_INFO << "Forcing refresh" << job->jobId(); |
731 | 85 | if (p->jobId() == m_jobs.at(i)->jobId()) { | 153 | Q_EMIT forceJobRefresh(printerName, job->jobId()); |
732 | 86 | exists = true; | 154 | } |
733 | 87 | 155 | } | |
734 | 88 | // Ensure the other properties of the job are up to date | 156 | } |
735 | 89 | if (!m_jobs.at(i)->deepCompare(p)) { | 157 | |
736 | 90 | m_jobs.at(i)->updateFrom(p); | 158 | void JobModel::addJob(QSharedPointer<PrinterJob> job) |
737 | 91 | 159 | { | |
738 | 92 | Q_EMIT dataChanged(index(i), index(i)); | 160 | int i = m_jobs.size(); |
739 | 93 | } | 161 | qDebug() << Q_FUNC_INFO << job->jobId() << i; |
740 | 94 | 162 | ||
741 | 95 | break; | 163 | beginInsertRows(QModelIndex(), i, i); |
742 | 96 | } | 164 | m_jobs.append(job); |
743 | 97 | } | 165 | endInsertRows(); |
744 | 98 | 166 | ||
745 | 99 | // If it doesn't exist then remove it from the old model | 167 | Q_EMIT countChanged(); |
746 | 100 | if (!exists) { | 168 | } |
747 | 101 | beginRemoveRows(QModelIndex(), i, i); | 169 | |
748 | 102 | QSharedPointer<PrinterJob> p = m_jobs.takeAt(i); | 170 | void JobModel::removeJob(QSharedPointer<PrinterJob> job) |
749 | 103 | endRemoveRows(); | 171 | { |
750 | 104 | 172 | qDebug() << Q_FUNC_INFO << job->jobId(); | |
751 | 105 | i--; // as we have removed an item decrement | 173 | int i = m_jobs.indexOf(job); |
752 | 106 | } | 174 | beginRemoveRows(QModelIndex(), i, i); |
753 | 107 | } | 175 | m_jobs.removeAt(i); |
754 | 108 | 176 | endRemoveRows(); | |
755 | 109 | // Go through the new model | 177 | |
756 | 110 | for (int i=0; i < newJobs.count(); i++) { | 178 | Q_EMIT countChanged(); |
757 | 111 | // Determine if the new printer exists in the old model | 179 | } |
758 | 112 | bool exists = false; | 180 | |
759 | 113 | int j; | 181 | // This is used by JobModel::jobState as it has modified an existing job |
760 | 114 | 182 | void JobModel::updateJob(QSharedPointer<PrinterJob> job) | |
761 | 115 | for (j=0; j < m_jobs.count(); j++) { | 183 | { |
762 | 116 | if (m_jobs.at(j)->jobId() == newJobs.at(i)->jobId()) { | 184 | qDebug() << Q_FUNC_INFO << job->jobId(); |
763 | 117 | exists = true; | 185 | |
764 | 118 | break; | 186 | int i = m_jobs.indexOf(job); |
765 | 119 | } | 187 | QModelIndex idx = index(i); |
766 | 120 | } | 188 | Q_EMIT dataChanged(idx, idx); |
767 | 121 | 189 | } | |
768 | 122 | if (exists) { | 190 | |
769 | 123 | if (j == i) { // New printer exists and in correct position | 191 | // This is used by JobLoader as it creates a new job to prevent threading issues |
770 | 124 | continue; | 192 | void JobModel::updateJob(QSharedPointer<PrinterJob> oldJob, |
771 | 125 | } else { | 193 | QSharedPointer<PrinterJob> newJob) |
772 | 126 | // New printer does exist but needs to be moved in old model | 194 | { |
773 | 127 | beginMoveRows(QModelIndex(), j, 1, QModelIndex(), i); | 195 | qDebug() << Q_FUNC_INFO << oldJob->jobId() << newJob->jobId(); |
774 | 128 | m_jobs.move(j, i); | 196 | |
775 | 129 | endMoveRows(); | 197 | int i = m_jobs.indexOf(oldJob); |
776 | 130 | } | 198 | QModelIndex idx = index(i); |
777 | 131 | } else { | 199 | |
778 | 132 | // New printer does not exist insert into model | 200 | if (i > -1) { |
779 | 133 | beginInsertRows(QModelIndex(), i, i); | 201 | // Copy the preloaded Printer (?) so that JobModel always shows correct |
780 | 134 | m_jobs.insert(i, newJobs.at(i)); | 202 | // attributes, eg colorModel needs Printer::supportedColorModels |
781 | 135 | endInsertRows(); | 203 | // |
782 | 136 | } | 204 | // FIXME: does it break anything as the Printer is not from PrinterModel |
783 | 137 | } | 205 | // Maybe all comparisions should just use printerName() ? |
784 | 138 | 206 | oldJob->setPrinter(newJob->printer()); | |
785 | 139 | if (oldCount != m_jobs.size()) { | 207 | |
786 | 140 | Q_EMIT countChanged(); | 208 | oldJob->updateFrom(newJob); |
787 | 209 | Q_EMIT dataChanged(idx, idx); | ||
788 | 210 | } else { | ||
789 | 211 | qWarning() << "Tried to updateJob which doesn't exist:" << newJob->printerName() << newJob->jobId(); | ||
790 | 141 | } | 212 | } |
791 | 142 | } | 213 | } |
792 | 143 | 214 | ||
793 | @@ -307,10 +378,10 @@ | |||
794 | 307 | return result; | 378 | return result; |
795 | 308 | } | 379 | } |
796 | 309 | 380 | ||
798 | 310 | QSharedPointer<PrinterJob> JobModel::getJobById(const int &id) | 381 | QSharedPointer<PrinterJob> JobModel::getJob(const QString &printerName, const int &id) |
799 | 311 | { | 382 | { |
800 | 312 | Q_FOREACH(auto job, m_jobs) { | 383 | Q_FOREACH(auto job, m_jobs) { |
802 | 313 | if (job->jobId() == id) { | 384 | if (job->printerName() == printerName && job->jobId() == id) { |
803 | 314 | return job; | 385 | return job; |
804 | 315 | } | 386 | } |
805 | 316 | } | 387 | } |
806 | 317 | 388 | ||
807 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h' | |||
808 | --- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 2017-03-06 13:19:08 +0000 | |||
809 | +++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 2017-03-13 12:51:30 +0000 | |||
810 | @@ -20,6 +20,7 @@ | |||
811 | 20 | #include "printers_global.h" | 20 | #include "printers_global.h" |
812 | 21 | #include "backend/backend.h" | 21 | #include "backend/backend.h" |
813 | 22 | #include "printer/printerjob.h" | 22 | #include "printer/printerjob.h" |
814 | 23 | #include "printer/signalratelimiter.h" | ||
815 | 23 | 24 | ||
816 | 24 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> |
817 | 25 | #include <QByteArray> | 26 | #include <QByteArray> |
818 | @@ -30,6 +31,8 @@ | |||
819 | 30 | #include <QTimer> | 31 | #include <QTimer> |
820 | 31 | #include <QVariant> | 32 | #include <QVariant> |
821 | 32 | 33 | ||
822 | 34 | class PrinterBackend; | ||
823 | 35 | class PrinterJob; | ||
824 | 33 | class PRINTERS_DECL_EXPORT JobModel : public QAbstractListModel | 36 | class PRINTERS_DECL_EXPORT JobModel : public QAbstractListModel |
825 | 34 | { | 37 | { |
826 | 35 | Q_OBJECT | 38 | Q_OBJECT |
827 | @@ -76,23 +79,46 @@ | |||
828 | 76 | int count() const; | 79 | int count() const; |
829 | 77 | 80 | ||
830 | 78 | Q_INVOKABLE QVariantMap get(const int row) const; | 81 | Q_INVOKABLE QVariantMap get(const int row) const; |
832 | 79 | QSharedPointer<PrinterJob> getJobById(const int &id); | 82 | QSharedPointer<PrinterJob> getJob(const QString &printerName, const int &id); |
833 | 83 | public Q_SLOTS: | ||
834 | 84 | void updateJob(QSharedPointer<PrinterJob> oldJob, | ||
835 | 85 | QSharedPointer<PrinterJob> newJob); | ||
836 | 80 | private: | 86 | private: |
837 | 87 | void addJob(QSharedPointer<PrinterJob> job); | ||
838 | 88 | void removeJob(QSharedPointer<PrinterJob> job); | ||
839 | 89 | void updateJob(QSharedPointer<PrinterJob> Job); | ||
840 | 90 | |||
841 | 81 | PrinterBackend *m_backend; | 91 | PrinterBackend *m_backend; |
842 | 82 | 92 | ||
843 | 83 | QList<QSharedPointer<PrinterJob>> m_jobs; | 93 | QList<QSharedPointer<PrinterJob>> m_jobs; |
844 | 94 | SignalRateLimiter m_signalHandler; | ||
845 | 84 | private Q_SLOTS: | 95 | private Q_SLOTS: |
854 | 85 | void update(); | 96 | void jobCreated(const QString &text, const QString &printer_uri, |
855 | 86 | void jobSignalCatchAll(const QString &text, const QString &printer_uri, | 97 | const QString &printer_name, uint printer_state, |
856 | 87 | const QString &printer_name, uint printer_state, | 98 | const QString &printer_state_reasons, |
857 | 88 | const QString &printer_state_reasons, | 99 | bool printer_is_accepting_jobs, uint job_id, |
858 | 89 | bool printer_is_accepting_jobs, uint job_id, | 100 | uint job_state, const QString &job_state_reasons, |
859 | 90 | uint job_state, const QString &job_state_reasons, | 101 | const QString &job_name, |
860 | 91 | const QString &job_name, | 102 | uint job_impressions_completed); |
861 | 92 | uint job_impressions_completed); | 103 | void jobState(const QString &text, const QString &printer_uri, |
862 | 104 | const QString &printer_name, uint printer_state, | ||
863 | 105 | const QString &printer_state_reasons, | ||
864 | 106 | bool printer_is_accepting_jobs, uint job_id, | ||
865 | 107 | uint job_state, const QString &job_state_reasons, | ||
866 | 108 | const QString &job_name, | ||
867 | 109 | uint job_impressions_completed); | ||
868 | 110 | void jobCompleted(const QString &text, const QString &printer_uri, | ||
869 | 111 | const QString &printer_name, uint printer_state, | ||
870 | 112 | const QString &printer_state_reasons, | ||
871 | 113 | bool printer_is_accepting_jobs, uint job_id, | ||
872 | 114 | uint job_state, const QString &job_state_reasons, | ||
873 | 115 | const QString &job_name, | ||
874 | 116 | uint job_impressions_completed); | ||
875 | 117 | void jobSignalPrinterModified(const QString &printerName); | ||
876 | 93 | 118 | ||
877 | 94 | Q_SIGNALS: | 119 | Q_SIGNALS: |
878 | 95 | void countChanged(); | 120 | void countChanged(); |
879 | 121 | void forceJobRefresh(const QString &printerName, const int jobId); | ||
880 | 96 | }; | 122 | }; |
881 | 97 | 123 | ||
882 | 98 | class PRINTERS_DECL_EXPORT JobFilter : public QSortFilterProxyModel | 124 | class PRINTERS_DECL_EXPORT JobFilter : public QSortFilterProxyModel |
883 | 99 | 125 | ||
884 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp' | |||
885 | --- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-06 15:29:04 +0000 | |||
886 | +++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-13 12:51:30 +0000 | |||
887 | @@ -32,9 +32,9 @@ | |||
888 | 32 | QObject::connect(m_backend, &PrinterBackend::printerAdded, | 32 | QObject::connect(m_backend, &PrinterBackend::printerAdded, |
889 | 33 | this, &PrinterModel::printerAdded); | 33 | this, &PrinterModel::printerAdded); |
890 | 34 | QObject::connect(m_backend, &PrinterBackend::printerModified, | 34 | QObject::connect(m_backend, &PrinterBackend::printerModified, |
892 | 35 | &m_signalHandler, &PrinterSignalHandler::onPrinterModified); | 35 | &m_signalHandler, &SignalRateLimiter::onPrinterModified); |
893 | 36 | QObject::connect(m_backend, &PrinterBackend::printerStateChanged, | 36 | QObject::connect(m_backend, &PrinterBackend::printerStateChanged, |
895 | 37 | &m_signalHandler, &PrinterSignalHandler::onPrinterModified); | 37 | &m_signalHandler, &SignalRateLimiter::onPrinterModified); |
896 | 38 | QObject::connect(m_backend, &PrinterBackend::printerDeleted, | 38 | QObject::connect(m_backend, &PrinterBackend::printerDeleted, |
897 | 39 | this, &PrinterModel::printerDeleted); | 39 | this, &PrinterModel::printerDeleted); |
898 | 40 | 40 | ||
899 | @@ -127,22 +127,6 @@ | |||
900 | 127 | return QSharedPointer<Printer>(Q_NULLPTR); | 127 | return QSharedPointer<Printer>(Q_NULLPTR); |
901 | 128 | } | 128 | } |
902 | 129 | 129 | ||
903 | 130 | void PrinterModel::movePrinter(const int &from, const int &to) | ||
904 | 131 | { | ||
905 | 132 | int size = m_printers.size(); | ||
906 | 133 | if (from < 0 || to < 0 || from >= size || to >= size) { | ||
907 | 134 | qWarning() << Q_FUNC_INFO << "Illegal move operation from" | ||
908 | 135 | << from << "to" << to << ". Size was" << size; | ||
909 | 136 | return; | ||
910 | 137 | } | ||
911 | 138 | if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), to)) { | ||
912 | 139 | qWarning() << Q_FUNC_INFO << "failed to move rows."; | ||
913 | 140 | return; | ||
914 | 141 | } | ||
915 | 142 | m_printers.move(from, to); | ||
916 | 143 | endMoveRows(); | ||
917 | 144 | } | ||
918 | 145 | |||
919 | 146 | void PrinterModel::removePrinter(QSharedPointer<Printer> printer, const CountChangeSignal ¬ify) | 130 | void PrinterModel::removePrinter(QSharedPointer<Printer> printer, const CountChangeSignal ¬ify) |
920 | 147 | { | 131 | { |
921 | 148 | int idx = m_printers.indexOf(printer); | 132 | int idx = m_printers.indexOf(printer); |
922 | 149 | 133 | ||
923 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.h' | |||
924 | --- modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-06 15:29:04 +0000 | |||
925 | +++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-13 12:51:30 +0000 | |||
926 | @@ -21,7 +21,7 @@ | |||
927 | 21 | 21 | ||
928 | 22 | #include "models/jobmodel.h" | 22 | #include "models/jobmodel.h" |
929 | 23 | #include "printer/printer.h" | 23 | #include "printer/printer.h" |
931 | 24 | #include "printer/printersignalhandler.h" | 24 | #include "printer/signalratelimiter.h" |
932 | 25 | 25 | ||
933 | 26 | #include <QAbstractListModel> | 26 | #include <QAbstractListModel> |
934 | 27 | #include <QByteArray> | 27 | #include <QByteArray> |
935 | @@ -98,13 +98,12 @@ | |||
936 | 98 | const CountChangeSignal ¬ify = CountChangeSignal::Defer); | 98 | const CountChangeSignal ¬ify = CountChangeSignal::Defer); |
937 | 99 | void removePrinter(QSharedPointer<Printer> printer, | 99 | void removePrinter(QSharedPointer<Printer> printer, |
938 | 100 | const CountChangeSignal ¬ify = CountChangeSignal::Defer); | 100 | const CountChangeSignal ¬ify = CountChangeSignal::Defer); |
939 | 101 | void movePrinter(const int &from, const int &to); | ||
940 | 102 | void updatePrinter(QSharedPointer<Printer> old, | 101 | void updatePrinter(QSharedPointer<Printer> old, |
941 | 103 | QSharedPointer<Printer> newPrinter); | 102 | QSharedPointer<Printer> newPrinter); |
942 | 104 | PrinterBackend *m_backend; | 103 | PrinterBackend *m_backend; |
943 | 105 | 104 | ||
944 | 106 | QList<QSharedPointer<Printer>> m_printers; | 105 | QList<QSharedPointer<Printer>> m_printers; |
946 | 107 | PrinterSignalHandler m_signalHandler; | 106 | SignalRateLimiter m_signalHandler; |
947 | 108 | 107 | ||
948 | 109 | private Q_SLOTS: | 108 | private Q_SLOTS: |
949 | 110 | void printerLoaded(QSharedPointer<Printer> printer); | 109 | void printerLoaded(QSharedPointer<Printer> printer); |
950 | 111 | 110 | ||
951 | === modified file 'modules/Ubuntu/Components/Extras/Printers/plugin.cpp' | |||
952 | --- modules/Ubuntu/Components/Extras/Printers/plugin.cpp 2017-03-08 11:29:01 +0000 | |||
953 | +++ modules/Ubuntu/Components/Extras/Printers/plugin.cpp 2017-03-13 12:51:30 +0000 | |||
954 | @@ -54,6 +54,7 @@ | |||
955 | 54 | 54 | ||
956 | 55 | qmlRegisterUncreatableType<PrinterEnum>(uri, 0, 1, "PrinterEnum", "Is an enum"); | 55 | qmlRegisterUncreatableType<PrinterEnum>(uri, 0, 1, "PrinterEnum", "Is an enum"); |
957 | 56 | qRegisterMetaType<QList<PrinterDriver>>("QList<PrinterDriver>"); | 56 | qRegisterMetaType<QList<PrinterDriver>>("QList<PrinterDriver>"); |
958 | 57 | qRegisterMetaType<QSharedPointer<PrinterJob>>("QSharedPointer<PrinterJob>"); | ||
959 | 57 | qRegisterMetaType<QList<QSharedPointer<Printer>>>("QList<QSharedPointer<Printer>>"); | 58 | qRegisterMetaType<QList<QSharedPointer<Printer>>>("QList<QSharedPointer<Printer>>"); |
960 | 58 | qRegisterMetaType<Device>("Device"); | 59 | qRegisterMetaType<Device>("Device"); |
961 | 59 | } | 60 | } |
962 | 60 | 61 | ||
963 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp' | |||
964 | --- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-09 15:50:41 +0000 | |||
965 | +++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-13 12:51:30 +0000 | |||
966 | @@ -379,10 +379,20 @@ | |||
967 | 379 | void Printer::updateFrom(QSharedPointer<Printer> other) | 379 | void Printer::updateFrom(QSharedPointer<Printer> other) |
968 | 380 | { | 380 | { |
969 | 381 | PrinterBackend *tmp = m_backend; | 381 | PrinterBackend *tmp = m_backend; |
970 | 382 | |||
971 | 383 | // Copy values from other printer which has been loaded in another thread | ||
972 | 384 | // Note: do not use loadAttributes otherwise can cause UI block | ||
973 | 385 | m_acceptJobs = other->m_acceptJobs; | ||
974 | 382 | m_backend = other->m_backend; | 386 | m_backend = other->m_backend; |
975 | 387 | m_defaultColorModel = other->m_defaultColorModel; | ||
976 | 388 | m_defaultPrintQuality = other->m_defaultPrintQuality; | ||
977 | 389 | m_deviceUri = other->m_deviceUri; | ||
978 | 390 | m_shared = other->m_shared; | ||
979 | 391 | m_stateMessage = other->m_stateMessage; | ||
980 | 392 | m_supportedColorModels = other->m_supportedColorModels; | ||
981 | 393 | m_supportedPrintQualities = other->m_supportedPrintQualities; | ||
982 | 394 | |||
983 | 383 | other->m_backend = tmp; | 395 | other->m_backend = tmp; |
984 | 384 | |||
985 | 385 | loadAttributes(); | ||
986 | 386 | } | 396 | } |
987 | 387 | 397 | ||
988 | 388 | void Printer::onPrinterStateChanged( | 398 | void Printer::onPrinterStateChanged( |
989 | 389 | 399 | ||
990 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp' | |||
991 | --- modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-02-24 17:47:22 +0000 | |||
992 | +++ modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-03-13 12:51:30 +0000 | |||
993 | @@ -150,8 +150,6 @@ | |||
994 | 150 | return; | 150 | return; |
995 | 151 | } | 151 | } |
996 | 152 | 152 | ||
997 | 153 | qWarning() << Q_FUNC_INFO << jobId(); | ||
998 | 154 | |||
999 | 155 | if (jobId() > 0) { | 153 | if (jobId() > 0) { |
1000 | 156 | // Load the extra attributes for the job | 154 | // Load the extra attributes for the job |
1001 | 157 | // NOTE: we don't need to type check them as they have been filtered for us | 155 | // NOTE: we don't need to type check them as they have been filtered for us |
1002 | @@ -165,11 +163,15 @@ | |||
1003 | 165 | // No colorModel will result in PrinterJob using defaultColorModel | 163 | // No colorModel will result in PrinterJob using defaultColorModel |
1004 | 166 | QString colorModel = attributes.value("ColorModel").toString(); | 164 | QString colorModel = attributes.value("ColorModel").toString(); |
1005 | 167 | for (int i=0; i < m_printer->supportedColorModels().length(); i++) { | 165 | for (int i=0; i < m_printer->supportedColorModels().length(); i++) { |
1007 | 168 | if (m_printer->supportedColorModels().at(i).originalOption == colorModel) { | 166 | if (m_printer->supportedColorModels().at(i).name == colorModel) { |
1008 | 169 | setColorModel(i); | 167 | setColorModel(i); |
1009 | 170 | } | 168 | } |
1010 | 171 | } | 169 | } |
1011 | 172 | 170 | ||
1012 | 171 | // TODO: do we need to set timezone? | ||
1013 | 172 | setCompletedTime(attributes.value("CompletedTime").toDateTime()); | ||
1014 | 173 | setCreationTime(attributes.value("CreationTime").toDateTime()); | ||
1015 | 174 | |||
1016 | 173 | // No duplexMode will result in PrinterJob using defaultDuplexMode | 175 | // No duplexMode will result in PrinterJob using defaultDuplexMode |
1017 | 174 | QString duplex = attributes.value("Duplex").toString(); | 176 | QString duplex = attributes.value("Duplex").toString(); |
1018 | 175 | PrinterEnum::DuplexMode duplexMode = Utils::ppdChoiceToDuplexMode(duplex); | 177 | PrinterEnum::DuplexMode duplexMode = Utils::ppdChoiceToDuplexMode(duplex); |
1019 | @@ -179,6 +181,7 @@ | |||
1020 | 179 | } | 181 | } |
1021 | 180 | } | 182 | } |
1022 | 181 | 183 | ||
1023 | 184 | setImpressionsCompleted(attributes.value("impressionsCompleted").toInt()); | ||
1024 | 182 | setLandscape(attributes.value("landscape").toBool()); | 185 | setLandscape(attributes.value("landscape").toBool()); |
1025 | 183 | setMessages(attributes.value("messages").toStringList()); | 186 | setMessages(attributes.value("messages").toStringList()); |
1026 | 184 | 187 | ||
1027 | @@ -192,6 +195,11 @@ | |||
1028 | 192 | setPrintRange(pageRanges.join(QLocale::system().groupSeparator())); | 195 | setPrintRange(pageRanges.join(QLocale::system().groupSeparator())); |
1029 | 193 | } | 196 | } |
1030 | 194 | 197 | ||
1031 | 198 | // TODO: do we need timezone? | ||
1032 | 199 | // processingTime.setTimeZone(QTimeZone::systemTimeZone()); | ||
1033 | 200 | // processingTime.setTime_t(cupsJob->processing_time); | ||
1034 | 201 | setProcessingTime(attributes.value("ProcessingTime").toDateTime()); | ||
1035 | 202 | |||
1036 | 195 | // No quality will result in PrinterJob using defaultPrintQuality | 203 | // No quality will result in PrinterJob using defaultPrintQuality |
1037 | 196 | QString quality = attributes.value("quality").toString(); | 204 | QString quality = attributes.value("quality").toString(); |
1038 | 197 | for (int i=0; i < m_printer->supportedPrintQualities().length(); i++) { | 205 | for (int i=0; i < m_printer->supportedPrintQualities().length(); i++) { |
1039 | @@ -201,11 +209,13 @@ | |||
1040 | 201 | } | 209 | } |
1041 | 202 | 210 | ||
1042 | 203 | setReverse(attributes.value("OutputOrder").toString() == "Reverse"); | 211 | setReverse(attributes.value("OutputOrder").toString() == "Reverse"); |
1043 | 212 | setSize(attributes.value("Size").toInt()); | ||
1044 | 213 | setUser(attributes.value("User").toString()); | ||
1045 | 214 | } else { | ||
1046 | 215 | setColorModel(m_printer->supportedColorModels().indexOf(m_printer->defaultColorModel())); | ||
1047 | 216 | setDuplexMode(m_printer->supportedDuplexModes().indexOf(m_printer->defaultDuplexMode())); | ||
1048 | 217 | setQuality(m_printer->supportedPrintQualities().indexOf(m_printer->defaultPrintQuality())); | ||
1049 | 204 | } | 218 | } |
1050 | 205 | |||
1051 | 206 | setColorModel(m_printer->supportedColorModels().indexOf(m_printer->defaultColorModel())); | ||
1052 | 207 | setDuplexMode(m_printer->supportedDuplexModes().indexOf(m_printer->defaultDuplexMode())); | ||
1053 | 208 | setQuality(m_printer->supportedPrintQualities().indexOf(m_printer->defaultPrintQuality())); | ||
1054 | 209 | } | 219 | } |
1055 | 210 | 220 | ||
1056 | 211 | QStringList PrinterJob::messages() const | 221 | QStringList PrinterJob::messages() const |
1057 | @@ -382,7 +392,6 @@ | |||
1058 | 382 | 392 | ||
1059 | 383 | Q_EMIT printerChanged(); | 393 | Q_EMIT printerChanged(); |
1060 | 384 | } | 394 | } |
1061 | 385 | loadDefaults(); | ||
1062 | 386 | } | 395 | } |
1063 | 387 | 396 | ||
1064 | 388 | void PrinterJob::setPrintRange(const QString &printRange) | 397 | void PrinterJob::setPrintRange(const QString &printRange) |
1065 | @@ -478,30 +487,44 @@ | |||
1066 | 478 | // Return true if they are the same | 487 | // Return true if they are the same |
1067 | 479 | return collate() == other->collate() | 488 | return collate() == other->collate() |
1068 | 480 | && colorModel() == other->colorModel() | 489 | && colorModel() == other->colorModel() |
1069 | 490 | && completedTime() == other->completedTime() | ||
1070 | 481 | && copies() == other->copies() | 491 | && copies() == other->copies() |
1071 | 492 | && creationTime() == other->creationTime() | ||
1072 | 482 | && duplexMode() == other->duplexMode() | 493 | && duplexMode() == other->duplexMode() |
1073 | 494 | && impressionsCompleted() == other->impressionsCompleted() | ||
1074 | 483 | && landscape() == other->landscape() | 495 | && landscape() == other->landscape() |
1075 | 496 | && messages() == other->messages() | ||
1076 | 484 | && printRange() == other->printRange() | 497 | && printRange() == other->printRange() |
1077 | 485 | && printRangeMode() == other->printRangeMode() | 498 | && printRangeMode() == other->printRangeMode() |
1078 | 499 | && processingTime() == other->processingTime() | ||
1079 | 486 | && quality() == other->quality() | 500 | && quality() == other->quality() |
1080 | 487 | && reverse() == other->reverse() | 501 | && reverse() == other->reverse() |
1081 | 502 | && size() == other->size() | ||
1082 | 488 | && state() == other->state() | 503 | && state() == other->state() |
1084 | 489 | && title() == other->title(); | 504 | && title() == other->title() |
1085 | 505 | && user() == other->user(); | ||
1086 | 490 | } | 506 | } |
1087 | 491 | 507 | ||
1088 | 492 | void PrinterJob::updateFrom(QSharedPointer<PrinterJob> other) | 508 | void PrinterJob::updateFrom(QSharedPointer<PrinterJob> other) |
1089 | 493 | { | 509 | { |
1090 | 494 | setCollate(other->collate()); | 510 | setCollate(other->collate()); |
1091 | 495 | setColorModel(other->colorModel()); | 511 | setColorModel(other->colorModel()); |
1092 | 512 | setCompletedTime(other->completedTime()); | ||
1093 | 496 | setCopies(other->copies()); | 513 | setCopies(other->copies()); |
1094 | 514 | setCreationTime(other->creationTime()); | ||
1095 | 497 | setDuplexMode(other->duplexMode()); | 515 | setDuplexMode(other->duplexMode()); |
1096 | 516 | setImpressionsCompleted(other->impressionsCompleted()); | ||
1097 | 498 | setLandscape(other->landscape()); | 517 | setLandscape(other->landscape()); |
1098 | 518 | setMessages(other->messages()); | ||
1099 | 499 | setPrintRange(other->printRange()); | 519 | setPrintRange(other->printRange()); |
1100 | 500 | setPrintRangeMode(other->printRangeMode()); | 520 | setPrintRangeMode(other->printRangeMode()); |
1101 | 521 | setProcessingTime(other->processingTime()); | ||
1102 | 501 | setQuality(other->quality()); | 522 | setQuality(other->quality()); |
1103 | 502 | setReverse(other->reverse()); | 523 | setReverse(other->reverse()); |
1104 | 524 | setSize(other->size()); | ||
1105 | 503 | setState(other->state()); | 525 | setState(other->state()); |
1106 | 504 | setTitle(other->title()); | 526 | setTitle(other->title()); |
1107 | 527 | setUser(other->user()); | ||
1108 | 505 | } | 528 | } |
1109 | 506 | 529 | ||
1110 | 507 | QString PrinterJob::user() const | 530 | QString PrinterJob::user() const |
1111 | 508 | 531 | ||
1112 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printerjob.h' | |||
1113 | --- modules/Ubuntu/Components/Extras/Printers/printer/printerjob.h 2017-03-01 14:17:52 +0000 | |||
1114 | +++ modules/Ubuntu/Components/Extras/Printers/printer/printerjob.h 2017-03-13 12:51:30 +0000 | |||
1115 | @@ -95,6 +95,7 @@ | |||
1116 | 95 | PrinterEnum::DuplexMode getDuplexMode() const; | 95 | PrinterEnum::DuplexMode getDuplexMode() const; |
1117 | 96 | ColorModel getColorModel() const; | 96 | ColorModel getColorModel() const; |
1118 | 97 | PrintQuality getPrintQuality() const; | 97 | PrintQuality getPrintQuality() const; |
1119 | 98 | void loadDefaults(); | ||
1120 | 98 | Q_INVOKABLE void printFile(const QUrl &url); | 99 | Q_INVOKABLE void printFile(const QUrl &url); |
1121 | 99 | void setCollate(const bool collate); | 100 | void setCollate(const bool collate); |
1122 | 100 | void setColorModel(const int colorModel); | 101 | void setColorModel(const int colorModel); |
1123 | @@ -118,8 +119,6 @@ | |||
1124 | 118 | void setUser(const QString &user); | 119 | void setUser(const QString &user); |
1125 | 119 | 120 | ||
1126 | 120 | void updateFrom(QSharedPointer<PrinterJob> other); | 121 | void updateFrom(QSharedPointer<PrinterJob> other); |
1127 | 121 | private Q_SLOTS: | ||
1128 | 122 | void loadDefaults(); | ||
1129 | 123 | Q_SIGNALS: | 122 | Q_SIGNALS: |
1130 | 124 | void collateChanged(); | 123 | void collateChanged(); |
1131 | 125 | void colorModelChanged(); | 124 | void colorModelChanged(); |
1132 | 126 | 125 | ||
1133 | === renamed file 'modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.cpp' => 'modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp' | |||
1134 | --- modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.cpp 2017-02-21 10:46:29 +0000 | |||
1135 | +++ modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp 2017-03-13 12:51:30 +0000 | |||
1136 | @@ -14,9 +14,9 @@ | |||
1137 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1138 | 15 | */ | 15 | */ |
1139 | 16 | 16 | ||
1141 | 17 | #include "printersignalhandler.h" | 17 | #include "signalratelimiter.h" |
1142 | 18 | 18 | ||
1144 | 19 | PrinterSignalHandler::PrinterSignalHandler(int triggerEventDelay, | 19 | SignalRateLimiter::SignalRateLimiter(int triggerEventDelay, |
1145 | 20 | QObject *parent) | 20 | QObject *parent) |
1146 | 21 | : QObject(parent) | 21 | : QObject(parent) |
1147 | 22 | { | 22 | { |
1148 | @@ -24,11 +24,11 @@ | |||
1149 | 24 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(process())); | 24 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(process())); |
1150 | 25 | } | 25 | } |
1151 | 26 | 26 | ||
1153 | 27 | PrinterSignalHandler::~PrinterSignalHandler() | 27 | SignalRateLimiter::~SignalRateLimiter() |
1154 | 28 | { | 28 | { |
1155 | 29 | } | 29 | } |
1156 | 30 | 30 | ||
1158 | 31 | void PrinterSignalHandler::process() | 31 | void SignalRateLimiter::process() |
1159 | 32 | { | 32 | { |
1160 | 33 | Q_FOREACH(auto printer, m_unprocessed) { | 33 | Q_FOREACH(auto printer, m_unprocessed) { |
1161 | 34 | Q_EMIT printerModified(printer); | 34 | Q_EMIT printerModified(printer); |
1162 | @@ -37,7 +37,7 @@ | |||
1163 | 37 | m_timer.stop(); | 37 | m_timer.stop(); |
1164 | 38 | } | 38 | } |
1165 | 39 | 39 | ||
1167 | 40 | void PrinterSignalHandler::onPrinterModified( | 40 | void SignalRateLimiter::onPrinterModified( |
1168 | 41 | const QString &text, const QString &printerUri, | 41 | const QString &text, const QString &printerUri, |
1169 | 42 | const QString &printerName, uint printerState, | 42 | const QString &printerName, uint printerState, |
1170 | 43 | const QString &printerStateReason, bool acceptingJobs) | 43 | const QString &printerStateReason, bool acceptingJobs) |
1171 | @@ -49,11 +49,22 @@ | |||
1172 | 49 | Q_UNUSED(printerStateReason); | 49 | Q_UNUSED(printerStateReason); |
1173 | 50 | Q_UNUSED(acceptingJobs); | 50 | Q_UNUSED(acceptingJobs); |
1174 | 51 | 51 | ||
1175 | 52 | // Track when the first item was added to the unprocessed queue | ||
1176 | 53 | if (m_unprocessed.count() == 0) { | ||
1177 | 54 | m_unprocessed_time = QDateTime::currentDateTime(); | ||
1178 | 55 | } | ||
1179 | 56 | |||
1180 | 52 | m_unprocessed << printerName; | 57 | m_unprocessed << printerName; |
1181 | 53 | m_timer.start(); | 58 | m_timer.start(); |
1182 | 59 | |||
1183 | 60 | // Ensure that process is fired if we have reached four times | ||
1184 | 61 | // longer than the timer, this is due to many signals coming in rapidly | ||
1185 | 62 | if (m_unprocessed_time.msecsTo(QDateTime::currentDateTime()) > m_timer.interval() * 4) { | ||
1186 | 63 | process(); | ||
1187 | 64 | } | ||
1188 | 54 | } | 65 | } |
1189 | 55 | 66 | ||
1191 | 56 | void PrinterSignalHandler::onPrinterStateChanged( | 67 | void SignalRateLimiter::onPrinterStateChanged( |
1192 | 57 | const QString &text, const QString &printerUri, | 68 | const QString &text, const QString &printerUri, |
1193 | 58 | const QString &printerName, uint printerState, | 69 | const QString &printerName, uint printerState, |
1194 | 59 | const QString &printerStateReason, bool acceptingJobs) | 70 | const QString &printerStateReason, bool acceptingJobs) |
1195 | @@ -64,6 +75,17 @@ | |||
1196 | 64 | Q_UNUSED(printerStateReason); | 75 | Q_UNUSED(printerStateReason); |
1197 | 65 | Q_UNUSED(acceptingJobs); | 76 | Q_UNUSED(acceptingJobs); |
1198 | 66 | 77 | ||
1199 | 78 | // Track when the first item was added to the unprocessed queue | ||
1200 | 79 | if (m_unprocessed.count() == 0) { | ||
1201 | 80 | m_unprocessed_time = QDateTime::currentDateTime(); | ||
1202 | 81 | } | ||
1203 | 82 | |||
1204 | 67 | m_unprocessed << printerName; | 83 | m_unprocessed << printerName; |
1205 | 68 | m_timer.start(); | 84 | m_timer.start(); |
1206 | 85 | |||
1207 | 86 | // Ensure that process is fired if we have reached four times | ||
1208 | 87 | // longer than the timer, this is due to many signals coming in rapidly | ||
1209 | 88 | if (m_unprocessed_time.msecsTo(QDateTime::currentDateTime()) > m_timer.interval() * 4) { | ||
1210 | 89 | process(); | ||
1211 | 90 | } | ||
1212 | 69 | } | 91 | } |
1213 | 70 | 92 | ||
1214 | === renamed file 'modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.h' => 'modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h' | |||
1215 | --- modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.h 2017-02-21 10:46:29 +0000 | |||
1216 | +++ modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h 2017-03-13 12:51:30 +0000 | |||
1217 | @@ -14,24 +14,26 @@ | |||
1218 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1219 | 15 | */ | 15 | */ |
1220 | 16 | 16 | ||
1223 | 17 | #ifndef USC_PRINTER_SIGNAL_HANDLER_H | 17 | #ifndef USC_SIGNAL_RATE_LIMITER_H |
1224 | 18 | #define USC_PRINTER_SIGNAL_HANDLER_H | 18 | #define USC_SIGNAL_RATE_LIMITER_H |
1225 | 19 | 19 | ||
1226 | 20 | #include "printers_global.h" | 20 | #include "printers_global.h" |
1227 | 21 | 21 | ||
1228 | 22 | #include <QDateTime> | ||
1229 | 22 | #include <QObject> | 23 | #include <QObject> |
1230 | 23 | #include <QSet> | 24 | #include <QSet> |
1231 | 24 | #include <QTimer> | 25 | #include <QTimer> |
1232 | 25 | 26 | ||
1234 | 26 | class PRINTERS_DECL_EXPORT PrinterSignalHandler : public QObject | 27 | class PRINTERS_DECL_EXPORT SignalRateLimiter : public QObject |
1235 | 27 | { | 28 | { |
1236 | 28 | Q_OBJECT | 29 | Q_OBJECT |
1237 | 29 | QTimer m_timer; | 30 | QTimer m_timer; |
1238 | 30 | QSet<QString> m_unprocessed; | 31 | QSet<QString> m_unprocessed; |
1239 | 32 | QDateTime m_unprocessed_time; | ||
1240 | 31 | public: | 33 | public: |
1242 | 32 | explicit PrinterSignalHandler(int triggerEventDelay = 500, | 34 | explicit SignalRateLimiter(int triggerEventDelay = 500, |
1243 | 33 | QObject *parent = Q_NULLPTR); | 35 | QObject *parent = Q_NULLPTR); |
1245 | 34 | ~PrinterSignalHandler(); | 36 | ~SignalRateLimiter(); |
1246 | 35 | 37 | ||
1247 | 36 | public Q_SLOTS: | 38 | public Q_SLOTS: |
1248 | 37 | void onPrinterModified( | 39 | void onPrinterModified( |
1249 | @@ -52,4 +54,4 @@ | |||
1250 | 52 | void printerModified(const QString &printerName); | 54 | void printerModified(const QString &printerName); |
1251 | 53 | }; | 55 | }; |
1252 | 54 | 56 | ||
1254 | 55 | #endif // USC_PRINTER_SIGNAL_HANDLER_H | 57 | #endif // USC_SIGNAL_RATE_LIMITERR_H |
1255 | 56 | 58 | ||
1256 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp' | |||
1257 | --- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-09 14:34:05 +0000 | |||
1258 | +++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-13 12:51:30 +0000 | |||
1259 | @@ -58,8 +58,20 @@ | |||
1260 | 58 | const QModelIndex &parent, int first, int) { | 58 | const QModelIndex &parent, int first, int) { |
1261 | 59 | int jobId = m_jobs.data(m_jobs.index(first, 0, parent), | 59 | int jobId = m_jobs.data(m_jobs.index(first, 0, parent), |
1262 | 60 | JobModel::Roles::IdRole).toInt(); | 60 | JobModel::Roles::IdRole).toInt(); |
1265 | 61 | jobAdded(m_jobs.getJobById(jobId)); | 61 | QString printerName = m_jobs.data( |
1266 | 62 | }); | 62 | m_jobs.index(first, 0, parent), |
1267 | 63 | JobModel::Roles::PrinterNameRole | ||
1268 | 64 | ).toString(); | ||
1269 | 65 | |||
1270 | 66 | jobAdded(m_jobs.getJob(printerName, jobId)); | ||
1271 | 67 | }); | ||
1272 | 68 | |||
1273 | 69 | // If the jobModel forces a refresh, load extended attributes for the job | ||
1274 | 70 | connect(&m_jobs, &JobModel::forceJobRefresh, [this]( | ||
1275 | 71 | const QString &printerName, const int jobId) { | ||
1276 | 72 | jobAdded(m_jobs.getJob(printerName, jobId)); | ||
1277 | 73 | }); | ||
1278 | 74 | |||
1279 | 63 | connect(&m_model, &QAbstractItemModel::rowsInserted, [this]( | 75 | connect(&m_model, &QAbstractItemModel::rowsInserted, [this]( |
1280 | 64 | const QModelIndex &parent, int first, int) { | 76 | const QModelIndex &parent, int first, int) { |
1281 | 65 | auto printer = m_model.data( | 77 | auto printer = m_model.data( |
1282 | @@ -78,6 +90,17 @@ | |||
1283 | 78 | ); | 90 | ); |
1284 | 79 | } | 91 | } |
1285 | 80 | 92 | ||
1286 | 93 | // Ensure existing jobs have been added, incase some were added before | ||
1287 | 94 | // the connect to rowsInserted was done | ||
1288 | 95 | for (int i = 0; i < m_jobs.rowCount(); i++) { | ||
1289 | 96 | jobAdded( | ||
1290 | 97 | m_jobs.getJob( | ||
1291 | 98 | m_jobs.data(m_jobs.index(i), JobModel::Roles::PrinterNameRole).toString(), | ||
1292 | 99 | m_jobs.data(m_jobs.index(i), JobModel::IdRole).toInt() | ||
1293 | 100 | ) | ||
1294 | 101 | ); | ||
1295 | 102 | } | ||
1296 | 103 | |||
1297 | 81 | if (m_backend->type() == PrinterEnum::PrinterType::CupsType) { | 104 | if (m_backend->type() == PrinterEnum::PrinterType::CupsType) { |
1298 | 82 | ((PrinterCupsBackend*) m_backend)->createSubscription(); | 105 | ((PrinterCupsBackend*) m_backend)->createSubscription(); |
1299 | 83 | } | 106 | } |
1300 | @@ -271,8 +294,13 @@ | |||
1301 | 271 | void Printers::jobAdded(QSharedPointer<PrinterJob> job) | 294 | void Printers::jobAdded(QSharedPointer<PrinterJob> job) |
1302 | 272 | { | 295 | { |
1303 | 273 | auto printer = m_model.getPrinterByName(job->printerName()); | 296 | auto printer = m_model.getPrinterByName(job->printerName()); |
1306 | 274 | if (printer && job) | 297 | |
1307 | 275 | job->setPrinter(printer); | 298 | // Check if we have a valid printer, does not need to be loaded as JobLoader |
1308 | 299 | // creates it's own Backend. | ||
1309 | 300 | if (printer && job) { | ||
1310 | 301 | // Trigger JobLoader to load extended attributes in the background | ||
1311 | 302 | m_backend->requestJobExtendedAttributes(printer, job); | ||
1312 | 303 | } | ||
1313 | 276 | } | 304 | } |
1314 | 277 | 305 | ||
1315 | 278 | void Printers::printerAdded(QSharedPointer<Printer> printer) | 306 | void Printers::printerAdded(QSharedPointer<Printer> printer) |
1316 | @@ -288,10 +316,9 @@ | |||
1317 | 288 | ).toString(); | 316 | ).toString(); |
1318 | 289 | 317 | ||
1319 | 290 | int jobId = m_jobs.data(idx, JobModel::Roles::IdRole).toInt(); | 318 | int jobId = m_jobs.data(idx, JobModel::Roles::IdRole).toInt(); |
1321 | 291 | auto job = m_jobs.getJobById(jobId); | 319 | auto job = m_jobs.getJob(printerName, jobId); |
1322 | 292 | if (printerName == printer->name() && !job->printer()) { | 320 | if (printerName == printer->name() && !job->printer()) { |
1325 | 293 | job->setPrinter(printer); | 321 | jobAdded(job); |
1324 | 294 | return; | ||
1326 | 295 | } | 322 | } |
1327 | 296 | } | 323 | } |
1328 | 297 | } | 324 | } |
1329 | 298 | 325 | ||
1330 | === modified file 'po/ubuntu-ui-extras.pot' | |||
1331 | --- po/ubuntu-ui-extras.pot 2017-03-08 16:55:21 +0000 | |||
1332 | +++ po/ubuntu-ui-extras.pot 2017-03-13 12:51:30 +0000 | |||
1333 | @@ -8,7 +8,7 @@ | |||
1334 | 8 | msgstr "" | 8 | msgstr "" |
1335 | 9 | "Project-Id-Version: ubuntu-ui-extras\n" | 9 | "Project-Id-Version: ubuntu-ui-extras\n" |
1336 | 10 | "Report-Msgid-Bugs-To: \n" | 10 | "Report-Msgid-Bugs-To: \n" |
1338 | 11 | "POT-Creation-Date: 2017-03-08 17:54+0100\n" | 11 | "POT-Creation-Date: 2017-03-13 12:44+0000\n" |
1339 | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
1340 | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
1341 | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" |
1342 | @@ -99,7 +99,7 @@ | |||
1343 | 99 | msgid "Stopped" | 99 | msgid "Stopped" |
1344 | 100 | msgstr "" | 100 | msgstr "" |
1345 | 101 | 101 | ||
1347 | 102 | #: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:331 | 102 | #: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:357 |
1348 | 103 | msgid "Test page" | 103 | msgid "Test page" |
1349 | 104 | msgstr "" | 104 | msgstr "" |
1350 | 105 | 105 | ||
1351 | 106 | 106 | ||
1352 | === modified file 'tests/unittests/Printers/CMakeLists.txt' | |||
1353 | --- tests/unittests/Printers/CMakeLists.txt 2017-03-08 16:13:02 +0000 | |||
1354 | +++ tests/unittests/Printers/CMakeLists.txt 2017-03-13 12:51:30 +0000 | |||
1355 | @@ -45,9 +45,9 @@ | |||
1356 | 45 | target_link_libraries(testPrintersJobFilter UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) | 45 | target_link_libraries(testPrintersJobFilter UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) |
1357 | 46 | add_test(tst_jobfilter testPrintersJobFilter) | 46 | add_test(tst_jobfilter testPrintersJobFilter) |
1358 | 47 | 47 | ||
1362 | 48 | add_executable(testPrintersSignalHandler tst_signalhandler.cpp ${MOCK_SOURCES}) | 48 | add_executable(testPrintersSignalRateLimiter tst_signalratelimiter.cpp ${MOCK_SOURCES}) |
1363 | 49 | target_link_libraries(testPrintersSignalHandler UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) | 49 | target_link_libraries(testPrintersSignalRateLimiter UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) |
1364 | 50 | add_test(tst_signalhandler testPrintersSignalHandler) | 50 | add_test(tst_signalratelimiter testPrintersSignalRateLimiter) |
1365 | 51 | 51 | ||
1366 | 52 | add_executable(testPrintersDevice tst_printerdevice.cpp ${MOCK_SOURCES}) | 52 | add_executable(testPrintersDevice tst_printerdevice.cpp ${MOCK_SOURCES}) |
1367 | 53 | target_link_libraries(testPrintersDevice UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) | 53 | target_link_libraries(testPrintersDevice UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui) |
1368 | 54 | 54 | ||
1369 | === renamed file 'tests/unittests/Printers/tst_signalhandler.cpp' => 'tests/unittests/Printers/tst_signalratelimiter.cpp' | |||
1370 | --- tests/unittests/Printers/tst_signalhandler.cpp 2017-02-21 10:46:29 +0000 | |||
1371 | +++ tests/unittests/Printers/tst_signalratelimiter.cpp 2017-03-13 12:51:30 +0000 | |||
1372 | @@ -14,31 +14,51 @@ | |||
1373 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1374 | 15 | */ | 15 | */ |
1375 | 16 | 16 | ||
1377 | 17 | #include "printer/printersignalhandler.h" | 17 | #include "printer/signalratelimiter.h" |
1378 | 18 | 18 | ||
1379 | 19 | #include <QDateTime> | ||
1380 | 19 | #include <QDebug> | 20 | #include <QDebug> |
1381 | 20 | #include <QObject> | 21 | #include <QObject> |
1382 | 21 | #include <QSignalSpy> | 22 | #include <QSignalSpy> |
1383 | 22 | #include <QTest> | 23 | #include <QTest> |
1384 | 23 | 24 | ||
1386 | 24 | class TestSignalHandler : public QObject | 25 | class TestSignalRateLimiter : public QObject |
1387 | 25 | { | 26 | { |
1388 | 26 | Q_OBJECT | 27 | Q_OBJECT |
1389 | 27 | private Q_SLOTS: | 28 | private Q_SLOTS: |
1390 | 28 | void testEmptyCount() | 29 | void testEmptyCount() |
1391 | 29 | { | 30 | { |
1393 | 30 | PrinterSignalHandler handler(500); | 31 | SignalRateLimiter handler(500); |
1394 | 31 | QSignalSpy modifiedSpy(&handler, SIGNAL(printerModified(const QString&))); | 32 | QSignalSpy modifiedSpy(&handler, SIGNAL(printerModified(const QString&))); |
1395 | 32 | 33 | ||
1397 | 33 | for (int i = 0; i < 500; i++) { | 34 | for (int i = 0; i < 20; i++) { |
1398 | 34 | handler.onPrinterStateChanged("spam!", "ipp://bar/baz", "printer-a", 0, "none", true); | 35 | handler.onPrinterStateChanged("spam!", "ipp://bar/baz", "printer-a", 0, "none", true); |
1399 | 35 | } | 36 | } |
1400 | 36 | 37 | ||
1401 | 37 | modifiedSpy.wait(1000); | 38 | modifiedSpy.wait(1000); |
1402 | 38 | QCOMPARE(modifiedSpy.count(), 1); | 39 | QCOMPARE(modifiedSpy.count(), 1); |
1403 | 39 | } | 40 | } |
1404 | 41 | void testUnprocessedTime() | ||
1405 | 42 | { | ||
1406 | 43 | // Keep sending jobs with no gap for longer than four times the | ||
1407 | 44 | // event delay. Check that two signals are emitted. | ||
1408 | 45 | // One from the forcing of the signal and one as the timer finishes | ||
1409 | 46 | |||
1410 | 47 | int eventDelay = 200; | ||
1411 | 48 | SignalRateLimiter handler(eventDelay); | ||
1412 | 49 | QSignalSpy modifiedSpy(&handler, SIGNAL(printerModified(const QString&))); | ||
1413 | 50 | |||
1414 | 51 | QDateTime start = QDateTime::currentDateTime(); | ||
1415 | 52 | |||
1416 | 53 | while (start.msecsTo(QDateTime::currentDateTime()) < eventDelay * 5) { | ||
1417 | 54 | handler.onPrinterStateChanged("spam!", "ipp://foo/bar", "printer-a", 0, "none", true); | ||
1418 | 55 | } | ||
1419 | 56 | |||
1420 | 57 | modifiedSpy.wait(eventDelay * 2); | ||
1421 | 58 | QCOMPARE(modifiedSpy.count(), 2); | ||
1422 | 59 | } | ||
1423 | 40 | }; | 60 | }; |
1424 | 41 | 61 | ||
1427 | 42 | QTEST_GUILESS_MAIN(TestSignalHandler) | 62 | QTEST_GUILESS_MAIN(TestSignalRateLimiter) |
1428 | 43 | #include "tst_signalhandler.moc" | 63 | #include "tst_signalratelimiter.moc" |
1429 | 44 | 64 |
Testing:
- Add a printer which has an address of lpd://127.0.0.1 so that it will spool on the cups server
- Download the serverguide.pdf (which has loads of pages) from [0]
- Open the PrinterQueue.qml example and open the printer you just added
- Add the serverguide.pdf to the printer queue for the printer you just added
- Watch the printing N pages count increment (also note the freezes that happen, eg if there is already a job being rendered when starting the example it can freeze)
0 - http:// bazaar. launchpad. net/~ubuntu- docviewer- dev/ubuntu- docviewer- app/lo- viewer/ download/ head:/servergui de.pdf- 20150423201617- 20cgubqqf8rhoke i-1/serverguide .pdf