Merge lp:~jonas-drange/ubuntu-ui-extras/printers-unstable into lp:~phablet-team/ubuntu-ui-extras/printer-staging
- printers-unstable
- Merge into printer-staging
Proposed by
Jonas G. Drange
Status: | Rejected |
---|---|
Rejected by: | Jonas G. Drange |
Proposed branch: | lp:~jonas-drange/ubuntu-ui-extras/printers-unstable |
Merge into: | lp:~phablet-team/ubuntu-ui-extras/printer-staging |
Diff against target: |
815 lines (+306/-12) 19 files modified
modules/Ubuntu/Components/Extras/Example/Printers.qml (+21/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp (+13/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend.h (+2/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+27/-7) modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h (+3/-0) modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp (+2/-0) modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp (+19/-2) modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h (+1/-0) modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+30/-0) modules/Ubuntu/Components/Extras/Printers/models/printermodel.h (+6/-0) modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+30/-2) modules/Ubuntu/Components/Extras/Printers/printer/printer.h (+5/-0) modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+43/-0) modules/Ubuntu/Components/Extras/Printers/printers/printers.h (+7/-0) po/ubuntu-ui-extras.pot (+25/-1) tests/unittests/Printers/mockbackend.h (+6/-0) tests/unittests/Printers/tst_printer.cpp (+7/-0) tests/unittests/Printers/tst_printerfilter.cpp (+30/-0) tests/unittests/Printers/tst_printermodel.cpp (+29/-0) |
To merge this branch: | bzr merge lp:~jonas-drange/ubuntu-ui-extras/printers-unstable |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+319096@code.launchpad.net |
Commit message
wip
Description of the change
To post a comment you must log in.
Unmerged revisions
- 147. By Jonas G. Drange
-
lazily create remote/local printer list
- 146. By Jonas G. Drange
-
merge remote
- 145. By Jonas G. Drange
-
merge copies
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'modules/Ubuntu/Components/Extras/Example/Printers.qml' |
2 | --- modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-03 15:07:45 +0000 |
3 | +++ modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-06 16:14:22 +0000 |
4 | @@ -171,6 +171,27 @@ |
5 | } |
6 | } |
7 | |
8 | + ListItems.Standard { |
9 | + anchors { |
10 | + left: parent.left |
11 | + right: parent.right |
12 | + } |
13 | + text: "Copies" |
14 | + |
15 | + control: TextField { |
16 | + id: copiesField |
17 | + inputMethodHints: Qt.ImhDigitsOnly |
18 | + text: printer.copies |
19 | + validator: IntValidator { |
20 | + bottom: 1 |
21 | + top: 999 |
22 | + } |
23 | + width: units.gu(10) |
24 | + onTextChanged: printer.copies = text |
25 | + } |
26 | + |
27 | + } |
28 | + |
29 | |
30 | ListItems.ValueSelector { |
31 | anchors { |
32 | |
33 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp' |
34 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-03 13:25:39 +0000 |
35 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-06 16:14:22 +0000 |
36 | @@ -91,6 +91,14 @@ |
37 | return QString(); |
38 | } |
39 | |
40 | +QString PrinterBackend::printerSetCopies(const QString &name, |
41 | + const int &copies) |
42 | +{ |
43 | + Q_UNUSED(name); |
44 | + Q_UNUSED(copies); |
45 | + return QString(); |
46 | +} |
47 | + |
48 | QString PrinterBackend::printerSetShared(const QString &name, |
49 | const bool shared) |
50 | { |
51 | @@ -202,6 +210,11 @@ |
52 | return QString(); |
53 | } |
54 | |
55 | +bool PrinterBackend::isRemote() const |
56 | +{ |
57 | + return false; |
58 | +} |
59 | + |
60 | PrinterEnum::State PrinterBackend::state() const |
61 | { |
62 | return PrinterEnum::State::IdleState; |
63 | |
64 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.h' |
65 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-03 13:25:39 +0000 |
66 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-06 16:14:22 +0000 |
67 | @@ -63,6 +63,7 @@ |
68 | const QString &name, |
69 | const bool accept, |
70 | const QString &reason = QString::null); |
71 | + virtual QString printerSetCopies(const QString &name, const int &copies); |
72 | virtual QString printerSetShared(const QString &name, |
73 | const bool shared); |
74 | virtual QString printerSetInfo(const QString &name, |
75 | @@ -92,6 +93,7 @@ |
76 | virtual QString description() const; |
77 | virtual QString location() const; |
78 | virtual QString makeAndModel() const; |
79 | + virtual bool isRemote() const; |
80 | |
81 | virtual PrinterEnum::State state() const; |
82 | virtual QList<QPageSize> supportedPageSizes() const; |
83 | |
84 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp' |
85 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-03 16:22:18 +0000 |
86 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-06 16:14:22 +0000 |
87 | @@ -40,7 +40,10 @@ |
88 | , m_knownQualityOptions({ |
89 | "Quality", "PrintQuality", "HPPrintQuality", "StpQuality", |
90 | "OutputMode",}) |
91 | - , m_extendedAttributeNames({"StateMessage", "DeviceUri", "IsShared"}) |
92 | + , m_extendedAttributeNames({ |
93 | + QStringLiteral("StateMessage"), QStringLiteral("DeviceUri"), |
94 | + QStringLiteral("IsShared"), QStringLiteral("Copies"), |
95 | + }) |
96 | , m_client(client) |
97 | , m_info(info) |
98 | , m_notifier(notifier) |
99 | @@ -179,6 +182,15 @@ |
100 | return QString(); |
101 | } |
102 | |
103 | +QString PrinterCupsBackend::printerSetCopies(const QString &name, |
104 | + const int &copies) |
105 | +{ |
106 | + if (!m_client->printerSetCopies(name, copies)) { |
107 | + return m_client->getLastError(); |
108 | + } |
109 | + return QString(); |
110 | +} |
111 | + |
112 | QString PrinterCupsBackend::printerSetShared(const QString &name, |
113 | const bool shared) |
114 | { |
115 | @@ -188,7 +200,6 @@ |
116 | return QString(); |
117 | } |
118 | |
119 | - |
120 | QString PrinterCupsBackend::printerSetInfo(const QString &name, |
121 | const QString &info) |
122 | { |
123 | @@ -233,8 +244,11 @@ |
124 | if (options.contains(extendedOption)) { |
125 | extendedAttributesResults = m_client->printerGetAttributes( |
126 | name, QStringList({ |
127 | - "device-uri", "printer-uri-supported", |
128 | - "printer-state-message"}) |
129 | + QStringLiteral("device-uri"), |
130 | + QStringLiteral("printer-uri-supported"), |
131 | + QStringLiteral("printer-state-message"), |
132 | + QStringLiteral("copies-default"), |
133 | + }) |
134 | ); |
135 | break; |
136 | } |
137 | @@ -314,11 +328,12 @@ |
138 | auto res = extendedAttributesResults; |
139 | if (!res["device-uri"].toString().isEmpty()) { |
140 | ret[option] = res["device-uri"]; |
141 | - } else if (res["printer-uri-supported"].toString().isEmpty()) { |
142 | + } |
143 | + if (!res["printer-uri-supported"].toString().isEmpty()) { |
144 | ret[option] = res["printer-uri-supported"]; |
145 | - } else { |
146 | - ret[option] = QString(); |
147 | } |
148 | + } else if (option == QStringLiteral("Copies")) { |
149 | + ret[option] = extendedAttributesResults[QStringLiteral("copies-default")]; |
150 | } else if (option == QStringLiteral("Shared") && dest) { |
151 | ret[option] = cupsGetOption("printer-is-shared", |
152 | dest->num_options, dest->options); |
153 | @@ -571,6 +586,11 @@ |
154 | return m_info.makeAndModel(); |
155 | } |
156 | |
157 | +bool PrinterCupsBackend::isRemote() const |
158 | +{ |
159 | + return m_info.isRemote(); |
160 | +} |
161 | + |
162 | PrinterEnum::State PrinterCupsBackend::state() const |
163 | { |
164 | switch (m_info.state()) { |
165 | |
166 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h' |
167 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-03 13:25:39 +0000 |
168 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-06 16:14:22 +0000 |
169 | @@ -55,6 +55,8 @@ |
170 | const QString &name, |
171 | const bool accept, |
172 | const QString &reason = QString::null) override; |
173 | + virtual QString printerSetCopies( |
174 | + const QString &name, const int &copies) override; |
175 | virtual QString printerSetShared(const QString &name, |
176 | const bool shared) override; |
177 | virtual QString printerSetInfo(const QString &name, |
178 | @@ -84,6 +86,7 @@ |
179 | virtual QString description() const override; |
180 | virtual QString location() const override; |
181 | virtual QString makeAndModel() const override; |
182 | + virtual bool isRemote() const override; |
183 | |
184 | virtual PrinterEnum::State state() const override; |
185 | virtual QList<QPageSize> supportedPageSizes() const override; |
186 | |
187 | === modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp' |
188 | --- modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-03 13:25:39 +0000 |
189 | +++ modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-06 16:14:22 +0000 |
190 | @@ -65,6 +65,8 @@ |
191 | ret[option] = QLatin1String(""); |
192 | } else if (option == QLatin1String("DeviceUri")) { |
193 | ret[option] = QLatin1String(""); |
194 | + } else if (option == QLatin1String("Copies")) { |
195 | + ret[option] = 0; |
196 | } else if (option == QLatin1String("Shared")) { |
197 | ret[option] = false; |
198 | } else { |
199 | |
200 | === modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp' |
201 | --- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-03 16:22:18 +0000 |
202 | +++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-06 16:14:22 +0000 |
203 | @@ -250,6 +250,24 @@ |
204 | } |
205 | } |
206 | |
207 | +bool IppClient::printerSetCopies(const QString &printerName, const int &copies) |
208 | +{ |
209 | + ipp_t *request; |
210 | + |
211 | + if (!isPrinterNameValid(printerName)) { |
212 | + setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName)); |
213 | + return false; |
214 | + } |
215 | + request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER); |
216 | + addPrinterUri(request, printerName); |
217 | + addRequestingUsername(request, NULL); |
218 | + ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_INTEGER, |
219 | + "copies-default", copies); |
220 | + /* TODO: The request will fail if this was a printer class, and it should |
221 | + be retried. */ |
222 | + return sendRequest(request, CupsResourceAdmin); |
223 | +} |
224 | + |
225 | bool IppClient::printerSetShared(const QString &printerName, const bool shared) |
226 | { |
227 | ipp_t *request; |
228 | @@ -264,7 +282,6 @@ |
229 | addRequestingUsername(request, NULL); |
230 | ippAddBoolean(request, IPP_TAG_OPERATION, |
231 | "printer-is-shared", shared ? 1 : 0); |
232 | - |
233 | /* TODO: The request will fail if this was a printer class, and it should |
234 | be retried. */ |
235 | |
236 | @@ -272,7 +289,7 @@ |
237 | } |
238 | |
239 | bool IppClient::printerClassSetInfo(const QString &name, |
240 | - const QString &info) |
241 | + const QString &info) |
242 | { |
243 | if (!isPrinterNameValid(name)) { |
244 | setInternalStatus(QString("%1 is not a valid printer name.").arg(name)); |
245 | |
246 | === modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h' |
247 | --- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-03 16:22:18 +0000 |
248 | +++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-06 16:14:22 +0000 |
249 | @@ -57,6 +57,7 @@ |
250 | bool printerSetEnabled(const QString &printerName, const bool enabled); |
251 | bool printerSetAcceptJobs(const QString &printerName, const bool accept, |
252 | const QString &reason); |
253 | + bool printerSetCopies(const QString &printerName, const int &copies); |
254 | bool printerSetShared(const QString &printerName, const bool shared); |
255 | bool printerClassSetInfo(const QString &name, const QString &info); |
256 | bool printerClassSetOption(const QString &name, const QString &option, |
257 | |
258 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp' |
259 | --- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-03 13:25:39 +0000 |
260 | +++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-06 16:14:22 +0000 |
261 | @@ -22,6 +22,7 @@ |
262 | #include "utils.h" |
263 | |
264 | #include <QDebug> |
265 | +#include <QUrl> |
266 | |
267 | PrinterModel::PrinterModel(PrinterBackend *backend, QObject *parent) |
268 | : QAbstractListModel(parent) |
269 | @@ -217,6 +218,9 @@ |
270 | case DeviceUriRole: |
271 | ret = printer->deviceUri(); |
272 | break; |
273 | + case HostNameRole: |
274 | + ret = QUrl(printer->deviceUri()).host(); |
275 | + break; |
276 | case MakeRole: |
277 | ret = printer->make(); |
278 | break; |
279 | @@ -283,12 +287,18 @@ |
280 | case IsRawRole: |
281 | ret = !printer->holdsDefinition(); |
282 | break; |
283 | + case IsRemoteRole: |
284 | + ret = printer->isRemote(); |
285 | + break; |
286 | case LastMessageRole: |
287 | ret = printer->lastMessage(); |
288 | break; |
289 | case JobRole: |
290 | ret = QVariant::fromValue(printer->jobs()); |
291 | break; |
292 | + case CopiesRole: |
293 | + ret = printer->copies(); |
294 | + break; |
295 | case EnabledRole: |
296 | ret = printer->enabled(); |
297 | break; |
298 | @@ -353,6 +363,8 @@ |
299 | case AcceptJobsRole: |
300 | printer->setAcceptJobs(value.toBool()); |
301 | break; |
302 | + case CopiesRole: |
303 | + printer->setCopies(value.toInt()); |
304 | case SharedRole: |
305 | printer->setShared(value.toBool()); |
306 | break; |
307 | @@ -375,6 +387,7 @@ |
308 | names[SupportedDuplexModesRole] = "supportedDuplexModes"; |
309 | names[NameRole] = "name"; |
310 | names[DeviceUriRole] = "deviceUri"; |
311 | + names[HostNameRole] = "hostname"; |
312 | names[MakeRole] = "make"; |
313 | names[EnabledRole] = "printerEnabled"; |
314 | names[AcceptJobsRole] = "acceptJobs"; |
315 | @@ -390,7 +403,9 @@ |
316 | names[IsPdfRole] = "isPdf"; |
317 | names[IsLoadedRole] = "isLoaded"; |
318 | names[IsRawRole] = "isRaw"; |
319 | + names[IsRemoteRole] = "isRemote"; |
320 | names[LastMessageRole] = "lastMessage"; |
321 | + names[CopiesRole] = "copies"; |
322 | names[JobRole] = "jobs"; |
323 | } |
324 | |
325 | @@ -469,6 +484,13 @@ |
326 | m_pdf = pdf; |
327 | } |
328 | |
329 | +void PrinterFilter::filterOnRemote(const bool remote) |
330 | +{ |
331 | + m_remoteEnabled = true; |
332 | + m_remote = remote; |
333 | + invalidate(); |
334 | +} |
335 | + |
336 | bool PrinterFilter::filterAcceptsRow(int sourceRow, |
337 | const QModelIndex &sourceParent) const |
338 | { |
339 | @@ -494,6 +516,14 @@ |
340 | accepts = m_state == state; |
341 | } |
342 | |
343 | + // If m_remote is true, we only show remote printers. |
344 | + if (accepts && m_remoteEnabled) { |
345 | + const bool isRemote = childIndex.model()->data( |
346 | + childIndex, PrinterModel::IsRemoteRole |
347 | + ).toBool(); |
348 | + accepts = m_remote == isRemote; |
349 | + } |
350 | + |
351 | return accepts; |
352 | } |
353 | bool PrinterFilter::lessThan(const QModelIndex &left, |
354 | |
355 | === modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.h' |
356 | --- modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-03 13:25:39 +0000 |
357 | +++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-06 16:14:22 +0000 |
358 | @@ -48,6 +48,7 @@ |
359 | SupportedDuplexModesRole, |
360 | NameRole, |
361 | DeviceUriRole, |
362 | + HostNameRole, |
363 | MakeRole, |
364 | LocationRole, |
365 | EnabledRole, |
366 | @@ -71,7 +72,9 @@ |
367 | |
368 | /* Indicates that this printers has no associated PPD. */ |
369 | IsRawRole, |
370 | + IsRemoteRole, |
371 | LastMessageRole, |
372 | + CopiesRole, |
373 | JobRole, |
374 | LastRole = JobRole, |
375 | }; |
376 | @@ -131,6 +134,7 @@ |
377 | void filterOnState(const PrinterEnum::State &state); |
378 | void filterOnRecent(const bool recent); |
379 | void filterOnPdf(const bool pdf); |
380 | + void filterOnRemote(const bool remote); |
381 | |
382 | int count() const; |
383 | protected: |
384 | @@ -153,6 +157,8 @@ |
385 | bool m_recentEnabled = false; |
386 | bool m_pdfEnabled = false; |
387 | bool m_pdf = false; |
388 | + bool m_remoteEnabled = false; |
389 | + bool m_remote = false; |
390 | }; |
391 | |
392 | #endif // USC_PRINTER_MODEL_H |
393 | |
394 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp' |
395 | --- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-03 13:25:39 +0000 |
396 | +++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-06 16:14:22 +0000 |
397 | @@ -90,6 +90,11 @@ |
398 | m_deviceUri = serverAttrs.value(QStringLiteral("DeviceUri")).toString(); |
399 | } |
400 | |
401 | +void Printer::updateCopies(const QMap<QString, QVariant> &serverAttrs) |
402 | +{ |
403 | + m_copies = serverAttrs.value(QStringLiteral("Copies")).toInt(); |
404 | +} |
405 | + |
406 | void Printer::updateShared(const QMap<QString, QVariant> &serverAttrs) |
407 | { |
408 | m_shared = serverAttrs.value(QStringLiteral("Shared")).toBool(); |
409 | @@ -105,7 +110,8 @@ |
410 | QStringLiteral("SupportedPrintQualities"), |
411 | QStringLiteral("StateMessage"), |
412 | QStringLiteral("DeviceUri"), |
413 | - QStringLiteral("Shared") |
414 | + QStringLiteral("Copies"), |
415 | + QStringLiteral("Shared"), |
416 | }); |
417 | auto result = m_backend->printerGetOptions(name(), opts); |
418 | |
419 | @@ -114,6 +120,7 @@ |
420 | updatePrintQualities(result); |
421 | updateLastMessage(result); |
422 | updateDeviceUri(result); |
423 | + updateCopies(result); |
424 | updateShared(result); |
425 | } |
426 | |
427 | @@ -234,11 +241,21 @@ |
428 | return m_backend->holdsDefinition(); |
429 | } |
430 | |
431 | +bool Printer::isRemote() const |
432 | +{ |
433 | + return m_backend->isRemote(); |
434 | +} |
435 | + |
436 | PrinterEnum::PrinterType Printer::type() const |
437 | { |
438 | return m_backend->type(); |
439 | } |
440 | |
441 | +int Printer::copies() const |
442 | +{ |
443 | + return m_copies; |
444 | +} |
445 | + |
446 | void Printer::setDefaultColorModel(const ColorModel &colorModel) |
447 | { |
448 | if (defaultColorModel() == colorModel) { |
449 | @@ -342,6 +359,15 @@ |
450 | m_backend->refresh(); |
451 | } |
452 | |
453 | +void Printer::setCopies(const int &copies) |
454 | +{ |
455 | + if (this->copies() == copies) { |
456 | + return; |
457 | + } |
458 | + |
459 | + m_backend->printerSetCopies(name(), copies); |
460 | +} |
461 | + |
462 | QString Printer::lastMessage() const |
463 | { |
464 | return m_stateMessage; |
465 | @@ -368,7 +394,9 @@ |
466 | && state() == other->state() |
467 | && lastMessage() == other->lastMessage() |
468 | && deviceUri() == other->deviceUri() |
469 | - && shared() == other->shared(); |
470 | + && shared() == other->shared() |
471 | + && copies() == other->copies() |
472 | + && isRemote() == other->isRemote(); |
473 | } |
474 | |
475 | void Printer::updateFrom(QSharedPointer<Printer> other) |
476 | |
477 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.h' |
478 | --- modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-03 13:25:39 +0000 |
479 | +++ modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-06 16:14:22 +0000 |
480 | @@ -63,8 +63,10 @@ |
481 | bool shared() const; |
482 | bool acceptJobs() const; |
483 | bool holdsDefinition() const; |
484 | + bool isRemote() const; |
485 | QString lastMessage() const; |
486 | QAbstractItemModel* jobs(); |
487 | + int copies() const; |
488 | |
489 | PrinterEnum::PrinterType type() const; |
490 | |
491 | @@ -77,6 +79,7 @@ |
492 | void setDefaultPrintQuality(const PrintQuality &quality); |
493 | void setDefaultPageSize(const QPageSize &pageSize); |
494 | void setJobModel(JobModel* jobModel); |
495 | + void setCopies(const int &copies); |
496 | |
497 | bool deepCompare(QSharedPointer<Printer> other) const; |
498 | void updateFrom(QSharedPointer<Printer> other); |
499 | @@ -98,6 +101,7 @@ |
500 | void updatePrintQualities(const QMap<QString, QVariant> &serverAttrs); |
501 | void updateLastMessage(const QMap<QString, QVariant> &serverAttrs); |
502 | void updateDeviceUri(const QMap<QString, QVariant> &serverAttrs); |
503 | + void updateCopies(const QMap<QString, QVariant> &serverAttrs); |
504 | void updateShared(const QMap<QString, QVariant> &serverAttrs); |
505 | void loadAttributes(); |
506 | |
507 | @@ -110,6 +114,7 @@ |
508 | bool m_acceptJobs; |
509 | bool m_shared; |
510 | QString m_deviceUri; |
511 | + int m_copies; |
512 | |
513 | QString m_stateMessage; |
514 | }; |
515 | |
516 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp' |
517 | --- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-06 13:19:08 +0000 |
518 | +++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-06 16:14:22 +0000 |
519 | @@ -104,6 +104,36 @@ |
520 | return ret; |
521 | } |
522 | |
523 | +QAbstractItemModel* Printers::remotePrinters() |
524 | +{ |
525 | + // Lazily initialize the model with remote printers. |
526 | + if (!m_remotePrinters.sourceModel()) { |
527 | + m_remotePrinters.setSourceModel(&m_model); |
528 | + m_remotePrinters.setSortRole(PrinterModel::Roles::DefaultPrinterRole); |
529 | + m_remotePrinters.sort(0, Qt::DescendingOrder); |
530 | + m_remotePrinters.filterOnRemote(true); |
531 | + } |
532 | + |
533 | + auto ret = &m_remotePrinters; |
534 | + QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership); |
535 | + return ret; |
536 | +} |
537 | +QAbstractItemModel* Printers::localPrinters() |
538 | +{ |
539 | + /* Lazily initialize this model. Local printers are discerned from remotes |
540 | + by checking if they are remote. */ |
541 | + if (!m_localPrinters.sourceModel()) { |
542 | + m_localPrinters.setSourceModel(&m_model); |
543 | + m_localPrinters.setSortRole(PrinterModel::Roles::NameRole); |
544 | + m_localPrinters.sort(0, Qt::DescendingOrder); |
545 | + m_localPrinters.filterOnRemote(false); |
546 | + } |
547 | + |
548 | + auto ret = &m_localPrinters; |
549 | + QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership); |
550 | + return ret; |
551 | +} |
552 | + |
553 | QAbstractItemModel* Printers::printJobs() |
554 | { |
555 | auto ret = &m_jobs; |
556 | @@ -197,6 +227,9 @@ |
557 | m_lastMessage = reply; |
558 | return false; |
559 | } |
560 | + |
561 | + provisionPrinter(name); |
562 | + |
563 | return true; |
564 | } |
565 | |
566 | @@ -212,9 +245,19 @@ |
567 | m_lastMessage = reply; |
568 | return false; |
569 | } |
570 | + |
571 | + provisionPrinter(name); |
572 | + |
573 | return true; |
574 | } |
575 | |
576 | +void Printers::provisionPrinter(const QString &name) |
577 | +{ |
578 | + // We mimic what System Config Printer does here. |
579 | + m_backend->printerSetEnabled(name, true); |
580 | + m_backend->printerSetAcceptJobs(name, true); |
581 | +} |
582 | + |
583 | bool Printers::removePrinter(const QString &name) |
584 | { |
585 | QString reply = m_backend->printerDelete(name); |
586 | |
587 | === modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.h' |
588 | --- modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-03-06 11:44:11 +0000 |
589 | +++ modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-03-06 16:14:22 +0000 |
590 | @@ -36,6 +36,8 @@ |
591 | Q_OBJECT |
592 | Q_PROPERTY(QAbstractItemModel* allPrinters READ allPrinters CONSTANT) |
593 | Q_PROPERTY(QAbstractItemModel* allPrintersWithPdf READ allPrintersWithPdf CONSTANT) |
594 | + Q_PROPERTY(QAbstractItemModel* remotePrinters READ remotePrinters CONSTANT) |
595 | + Q_PROPERTY(QAbstractItemModel* localPrinters READ localPrinters CONSTANT) |
596 | Q_PROPERTY(QAbstractItemModel* printJobs READ printJobs CONSTANT) |
597 | Q_PROPERTY(QAbstractItemModel* drivers READ drivers CONSTANT) |
598 | Q_PROPERTY(QString driverFilter READ driverFilter WRITE setDriverFilter NOTIFY driverFilterChanged) |
599 | @@ -51,6 +53,8 @@ |
600 | |
601 | QAbstractItemModel* allPrinters(); |
602 | QAbstractItemModel* allPrintersWithPdf(); |
603 | + QAbstractItemModel* remotePrinters(); |
604 | + QAbstractItemModel* localPrinters(); |
605 | QAbstractItemModel* printJobs(); |
606 | QAbstractItemModel* drivers(); |
607 | QString driverFilter() const; |
608 | @@ -98,12 +102,15 @@ |
609 | void driverFilterChanged(); |
610 | |
611 | private: |
612 | + void provisionPrinter(const QString &name); |
613 | PrinterBackend *m_backend; |
614 | DriverModel m_drivers; |
615 | PrinterModel m_model; |
616 | JobModel m_jobs; |
617 | PrinterFilter m_allPrinters; |
618 | PrinterFilter m_allPrintersWithPdf; |
619 | + PrinterFilter m_remotePrinters; |
620 | + PrinterFilter m_localPrinters; |
621 | PrinterFilter m_recentPrinters; |
622 | QString m_lastMessage; |
623 | }; |
624 | |
625 | === modified file 'po/ubuntu-ui-extras.pot' |
626 | --- po/ubuntu-ui-extras.pot 2017-03-01 14:57:45 +0000 |
627 | +++ po/ubuntu-ui-extras.pot 2017-03-06 16:14:22 +0000 |
628 | @@ -8,7 +8,7 @@ |
629 | msgstr "" |
630 | "Project-Id-Version: ubuntu-ui-extras\n" |
631 | "Report-Msgid-Bugs-To: \n" |
632 | -"POT-Creation-Date: 2017-03-01 15:51+0100\n" |
633 | +"POT-Creation-Date: 2017-03-03 15:12+0100\n" |
634 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
635 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
636 | "Language-Team: LANGUAGE <LL@li.org>\n" |
637 | @@ -17,6 +17,14 @@ |
638 | "Content-Type: text/plain; charset=CHARSET\n" |
639 | "Content-Transfer-Encoding: 8bit\n" |
640 | |
641 | +#: modules/Ubuntu/Components/Extras/Example/Printers.qml:106 |
642 | +msgid "Aborted" |
643 | +msgstr "" |
644 | + |
645 | +#: modules/Ubuntu/Components/Extras/Example/Printers.qml:108 |
646 | +msgid "Active" |
647 | +msgstr "" |
648 | + |
649 | #: modules/Ubuntu/Components/Extras/PhotoEditor.qml:206 |
650 | #: modules/Ubuntu/Components/Extras/PhotoEditor/ExposureAdjuster.qml:81 |
651 | msgid "Cancel" |
652 | @@ -43,10 +51,18 @@ |
653 | msgid "Enhancing photo..." |
654 | msgstr "" |
655 | |
656 | +#: modules/Ubuntu/Components/Extras/Example/Printers.qml:104 |
657 | +msgid "Idle" |
658 | +msgstr "" |
659 | + |
660 | #: modules/Ubuntu/Components/Extras/Printers/utils.h:61 |
661 | msgid "Long Edge (Standard)" |
662 | msgstr "" |
663 | |
664 | +#: modules/Ubuntu/Components/Extras/Example/Printers.qml:115 |
665 | +msgid "No messages" |
666 | +msgstr "" |
667 | + |
668 | #: modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp:47 |
669 | msgid "Normal" |
670 | msgstr "" |
671 | @@ -79,6 +95,14 @@ |
672 | msgid "Short Edge (Flip)" |
673 | msgstr "" |
674 | |
675 | +#: modules/Ubuntu/Components/Extras/Example/Printers.qml:110 |
676 | +msgid "Stopped" |
677 | +msgstr "" |
678 | + |
679 | +#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:278 |
680 | +msgid "Test page" |
681 | +msgstr "" |
682 | + |
683 | #: modules/Ubuntu/Components/Extras/PhotoEditor.qml:197 |
684 | msgid "This will undo all edits, including those from previous sessions." |
685 | msgstr "" |
686 | |
687 | === modified file 'tests/unittests/Printers/mockbackend.h' |
688 | --- tests/unittests/Printers/mockbackend.h 2017-03-03 13:25:39 +0000 |
689 | +++ tests/unittests/Printers/mockbackend.h 2017-03-06 16:14:22 +0000 |
690 | @@ -248,6 +248,11 @@ |
691 | return m_makeAndModel; |
692 | } |
693 | |
694 | + virtual bool isRemote() const override |
695 | + { |
696 | + return m_remote; |
697 | + } |
698 | + |
699 | virtual PrinterEnum::State state() const override |
700 | { |
701 | return m_state; |
702 | @@ -410,6 +415,7 @@ |
703 | QMap<QString, PrinterEnum::OperationPolicy> operationPolicies; |
704 | |
705 | bool m_holdsDefinition = true; |
706 | + bool m_remote = false; |
707 | |
708 | QString m_description = QString::null; |
709 | QString m_location = QString::null; |
710 | |
711 | === modified file 'tests/unittests/Printers/tst_printer.cpp' |
712 | --- tests/unittests/Printers/tst_printer.cpp 2017-03-03 13:25:39 +0000 |
713 | +++ tests/unittests/Printers/tst_printer.cpp 2017-03-06 16:14:22 +0000 |
714 | @@ -86,6 +86,13 @@ |
715 | m_backend->m_location = "location"; |
716 | QCOMPARE(m_instance->location(), m_backend->location()); |
717 | } |
718 | + void testRemote() |
719 | + { |
720 | + m_backend->m_remote = false; |
721 | + QCOMPARE(m_instance->isRemote(), m_backend->isRemote()); |
722 | + m_backend->m_remote = true; |
723 | + QCOMPARE(m_instance->isRemote(), m_backend->isRemote()); |
724 | + } |
725 | void testSupportedDuplexModes_data() |
726 | { |
727 | QTest::addColumn<QList<PrinterEnum::DuplexMode>>("modes"); |
728 | |
729 | === modified file 'tests/unittests/Printers/tst_printerfilter.cpp' |
730 | --- tests/unittests/Printers/tst_printerfilter.cpp 2017-02-23 13:00:05 +0000 |
731 | +++ tests/unittests/Printers/tst_printerfilter.cpp 2017-03-06 16:14:22 +0000 |
732 | @@ -119,6 +119,36 @@ |
733 | |
734 | delete model; |
735 | } |
736 | + void testRemoteAndLocal() |
737 | + { |
738 | + QScopedPointer<MockPrinterBackend> backend(new MockPrinterBackend); |
739 | + PrinterModel *model = new PrinterModel(backend.data()); |
740 | + |
741 | + PrinterFilter locals; |
742 | + locals.setSourceModel(model); |
743 | + locals.filterOnRemote(false); |
744 | + locals.filterOnPdf(false); |
745 | + |
746 | + PrinterFilter remotes; |
747 | + remotes.setSourceModel(model); |
748 | + remotes.filterOnRemote(true); |
749 | + locals.filterOnPdf(false); |
750 | + |
751 | + MockPrinterBackend* backendA = new MockPrinterBackend("a-printer"); |
752 | + backendA->m_remote = true; |
753 | + auto printerA = QSharedPointer<Printer>(new Printer(backendA)); |
754 | + |
755 | + MockPrinterBackend* backendB = new MockPrinterBackend("b-printer"); |
756 | + backendB->m_remote = false; |
757 | + auto printerB = QSharedPointer<Printer>(new Printer(backendB)); |
758 | + |
759 | + // Load the two printers |
760 | + backend->mockPrinterLoaded(printerA); |
761 | + backend->mockPrinterLoaded(printerB); |
762 | + |
763 | + QCOMPARE(locals.count(), 1); |
764 | + QCOMPARE(remotes.count(), 1); |
765 | + } |
766 | }; |
767 | |
768 | QTEST_GUILESS_MAIN(TestPrinterFilter) |
769 | |
770 | === modified file 'tests/unittests/Printers/tst_printermodel.cpp' |
771 | --- tests/unittests/Printers/tst_printermodel.cpp 2017-03-03 13:25:39 +0000 |
772 | +++ tests/unittests/Printers/tst_printermodel.cpp 2017-03-06 16:14:22 +0000 |
773 | @@ -297,6 +297,19 @@ |
774 | QCOMPARE(m_model->data(m_model->index(1), PrinterModel::DeviceUriRole).toString(), |
775 | (QString) "/dev/null"); |
776 | } |
777 | + void testHostNameRole() |
778 | + { |
779 | + MockPrinterBackend* backend = new MockPrinterBackend("a-printer"); |
780 | + backend->printerOptions["a-printer"].insert( |
781 | + "DeviceUri", "ipps://foo.local/bar" |
782 | + ); |
783 | + |
784 | + auto printerA = QSharedPointer<Printer>(new Printer(backend)); |
785 | + m_backend->mockPrinterLoaded(printerA); |
786 | + |
787 | + QCOMPARE(m_model->data(m_model->index(1), PrinterModel::HostNameRole).toString(), |
788 | + (QString) "foo.local"); |
789 | + } |
790 | void testLastMessageRole() |
791 | { |
792 | MockPrinterBackend* backend = new MockPrinterBackend("a-printer"); |
793 | @@ -322,6 +335,22 @@ |
794 | QCOMPARE(m_model->data(m_model->index(1), PrinterModel::LocationRole).toString(), |
795 | QString("test-location")); |
796 | } |
797 | + void testIsRemoteRole() |
798 | + { |
799 | + MockPrinterBackend* backend = new MockPrinterBackend("a-printer"); |
800 | + auto printer = QSharedPointer<Printer>(new Printer(backend)); |
801 | + |
802 | + backend->m_remote = false; |
803 | + m_backend->mockPrinterLoaded(printer); |
804 | + QCOMPARE(m_model->data(m_model->index(1), PrinterModel::IsRemoteRole).toBool(), |
805 | + false); |
806 | + |
807 | + backend->m_remote = true; |
808 | + m_backend->mockPrinterLoaded(printer); |
809 | + QCOMPARE(m_model->data(m_model->index(1), PrinterModel::IsRemoteRole).toBool(), |
810 | + true); |
811 | + |
812 | + } |
813 | void testEnabledRole() |
814 | { |
815 | PrinterBackend* backend = new MockPrinterBackend("a-printer"); |