Merge lp:~jonas-drange/ubuntu-ui-extras/shared into lp:~phablet-team/ubuntu-ui-extras/printer-staging

Proposed by Jonas G. Drange
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 143
Merged at revision: 142
Proposed branch: lp:~jonas-drange/ubuntu-ui-extras/shared
Merge into: lp:~phablet-team/ubuntu-ui-extras/printer-staging
Diff against target: 401 lines (+153/-2)
15 files modified
modules/Ubuntu/Components/Extras/Example/Printers.qml (+13/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp (+8/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend.h (+2/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+13/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h (+2/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp (+2/-0)
modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp (+20/-0)
modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h (+1/-0)
modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+7/-0)
modules/Ubuntu/Components/Extras/Printers/models/printermodel.h (+1/-0)
modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+26/-2)
modules/Ubuntu/Components/Extras/Printers/printer/printer.h (+4/-0)
tests/unittests/Printers/mockbackend.h (+7/-0)
tests/unittests/Printers/tst_printer.cpp (+26/-0)
tests/unittests/Printers/tst_printermodel.cpp (+21/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-ui-extras/shared
Reviewer Review Type Date Requested Status
Andrew Hayzen (community) Approve
Review via email: mp+318907@code.launchpad.net

Commit message

adds read/write of the shared property

Description of the change

adds read/write of the shared property

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

The code looks good, can you add the shared option as a delegate in the examples? (so that we can easily test)

review: Needs Fixing
143. By Jonas G. Drange

adds delegate for shared

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

LGTM :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/Extras/Example/Printers.qml'
--- modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-02 15:08:24 +0000
+++ modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-03 15:07:56 +0000
@@ -134,6 +134,19 @@
134 left: parent.left134 left: parent.left
135 right: parent.right135 right: parent.right
136 }136 }
137 text: "Shared"
138
139 control: Switch {
140 checked: printer.shared
141 onCheckedChanged: printer.shared = checked
142 }
143 }
144
145 ListItems.Standard {
146 anchors {
147 left: parent.left
148 right: parent.right
149 }
137 text: "Jobs"150 text: "Jobs"
138 progression: true151 progression: true
139 onClicked: pageStack.push(jobPage, { printer: printer })152 onClicked: pageStack.push(jobPage, { printer: printer })
140153
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-01 12:53:55 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-03 15:07:56 +0000
@@ -91,6 +91,14 @@
91 return QString();91 return QString();
92}92}
9393
94QString PrinterBackend::printerSetShared(const QString &name,
95 const bool shared)
96{
97 Q_UNUSED(name);
98 Q_UNUSED(shared);
99 return QString();
100}
101
94QString PrinterBackend::printerSetInfo(const QString &name,102QString PrinterBackend::printerSetInfo(const QString &name,
95 const QString &info)103 const QString &info)
96{104{
97105
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.h'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-01 12:53:55 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-03 15:07:56 +0000
@@ -63,6 +63,8 @@
63 const QString &name,63 const QString &name,
64 const bool accept,64 const bool accept,
65 const QString &reason = QString::null);65 const QString &reason = QString::null);
66 virtual QString printerSetShared(const QString &name,
67 const bool shared);
66 virtual QString printerSetInfo(const QString &name,68 virtual QString printerSetInfo(const QString &name,
67 const QString &info);69 const QString &info);
68 virtual QString printerAddOption(const QString &name,70 virtual QString printerAddOption(const QString &name,
6971
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-02 14:29:46 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-03 15:07:56 +0000
@@ -179,6 +179,16 @@
179 return QString();179 return QString();
180}180}
181181
182QString PrinterCupsBackend::printerSetShared(const QString &name,
183 const bool shared)
184{
185 if (!m_client->printerSetShared(name, shared)) {
186 return m_client->getLastError();
187 }
188 return QString();
189}
190
191
182QString PrinterCupsBackend::printerSetInfo(const QString &name,192QString PrinterCupsBackend::printerSetInfo(const QString &name,
183 const QString &info)193 const QString &info)
184{194{
@@ -309,6 +319,9 @@
309 } else {319 } else {
310 ret[option] = QString();320 ret[option] = QString();
311 }321 }
322 } else if (option == QStringLiteral("Shared") && dest) {
323 ret[option] = cupsGetOption("printer-is-shared",
324 dest->num_options, dest->options);
312 }325 }
313 }326 }
314 return ret;327 return ret;
315328
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-02 14:28:53 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-03 15:07:56 +0000
@@ -55,6 +55,8 @@
55 const QString &name,55 const QString &name,
56 const bool accept,56 const bool accept,
57 const QString &reason = QString::null) override;57 const QString &reason = QString::null) override;
58 virtual QString printerSetShared(const QString &name,
59 const bool shared) override;
58 virtual QString printerSetInfo(const QString &name,60 virtual QString printerSetInfo(const QString &name,
59 const QString &info) override;61 const QString &info) override;
60 virtual QString printerAddOption(const QString &name,62 virtual QString printerAddOption(const QString &name,
6163
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-02 13:50:54 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-03 15:07:56 +0000
@@ -65,6 +65,8 @@
65 ret[option] = QLatin1String("");65 ret[option] = QLatin1String("");
66 } else if (option == QLatin1String("DeviceUri")) {66 } else if (option == QLatin1String("DeviceUri")) {
67 ret[option] = QLatin1String("");67 ret[option] = QLatin1String("");
68 } else if (option == QLatin1String("Shared")) {
69 ret[option] = false;
68 } else {70 } else {
69 throw std::invalid_argument("Invalid value for PDF printer: " + option.toStdString());71 throw std::invalid_argument("Invalid value for PDF printer: " + option.toStdString());
70 }72 }
7173
=== modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp'
--- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-02 14:52:47 +0000
+++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-03 15:07:56 +0000
@@ -250,6 +250,26 @@
250 }250 }
251}251}
252252
253bool IppClient::printerSetShared(const QString &printerName, const bool shared)
254{
255 ipp_t *request;
256
257 if (!isPrinterNameValid(printerName)) {
258 setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName));
259 return false;
260 }
261
262 request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
263 addPrinterUri(request, printerName);
264 addRequestingUsername(request, NULL);
265 ippAddBoolean(request, IPP_TAG_OPERATION,
266 "printer-is-shared", shared ? 1 : 0);
267
268 /* TODO: The request will fail if this was a printer class, and it should
269 be retried. */
270
271 return sendRequest(request, CupsResourceAdmin);
272}
253273
254bool IppClient::printerClassSetInfo(const QString &name,274bool IppClient::printerClassSetInfo(const QString &name,
255 const QString &info)275 const QString &info)
256276
=== modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h'
--- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-02 14:28:53 +0000
+++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-03 15:07:56 +0000
@@ -57,6 +57,7 @@
57 bool printerSetEnabled(const QString &printerName, const bool enabled);57 bool printerSetEnabled(const QString &printerName, const bool enabled);
58 bool printerSetAcceptJobs(const QString &printerName, const bool accept,58 bool printerSetAcceptJobs(const QString &printerName, const bool accept,
59 const QString &reason);59 const QString &reason);
60 bool printerSetShared(const QString &printerName, const bool shared);
60 bool printerClassSetInfo(const QString &name, const QString &info);61 bool printerClassSetInfo(const QString &name, const QString &info);
61 bool printerClassSetOption(const QString &name, const QString &option,62 bool printerClassSetOption(const QString &name, const QString &option,
62 const QStringList &values);63 const QStringList &values);
6364
=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp'
--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-02 14:28:53 +0000
+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-03 15:07:56 +0000
@@ -295,6 +295,9 @@
295 case AcceptJobsRole:295 case AcceptJobsRole:
296 ret = printer->acceptJobs();296 ret = printer->acceptJobs();
297 break;297 break;
298 case SharedRole:
299 ret = printer->shared();
300 break;
298 }301 }
299 }302 }
300303
@@ -350,6 +353,9 @@
350 case AcceptJobsRole:353 case AcceptJobsRole:
351 printer->setAcceptJobs(value.toBool());354 printer->setAcceptJobs(value.toBool());
352 break;355 break;
356 case SharedRole:
357 printer->setShared(value.toBool());
358 break;
353 }359 }
354 }360 }
355361
@@ -372,6 +378,7 @@
372 names[MakeRole] = "make";378 names[MakeRole] = "make";
373 names[EnabledRole] = "printerEnabled";379 names[EnabledRole] = "printerEnabled";
374 names[AcceptJobsRole] = "acceptJobs";380 names[AcceptJobsRole] = "acceptJobs";
381 names[SharedRole] = "shared";
375 names[PrintQualityRole] = "printQuality";382 names[PrintQualityRole] = "printQuality";
376 names[SupportedPrintQualitiesRole] = "supportedPrintQualities";383 names[SupportedPrintQualitiesRole] = "supportedPrintQualities";
377 names[DescriptionRole] = "description";384 names[DescriptionRole] = "description";
378385
=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.h'
--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-02 14:28:53 +0000
+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-03 15:07:56 +0000
@@ -52,6 +52,7 @@
52 LocationRole,52 LocationRole,
53 EnabledRole,53 EnabledRole,
54 AcceptJobsRole,54 AcceptJobsRole,
55 SharedRole,
55 PrintQualityRole,56 PrintQualityRole,
56 SupportedPrintQualitiesRole,57 SupportedPrintQualitiesRole,
57 DescriptionRole,58 DescriptionRole,
5859
=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp'
--- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-02 15:39:26 +0000
+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-03 15:07:56 +0000
@@ -84,11 +84,17 @@
84 m_stateMessage = serverAttrs.value(QStringLiteral("StateMessage")).toString();84 m_stateMessage = serverAttrs.value(QStringLiteral("StateMessage")).toString();
85}85}
8686
87
87void Printer::updateDeviceUri(const QMap<QString, QVariant> &serverAttrs)88void Printer::updateDeviceUri(const QMap<QString, QVariant> &serverAttrs)
88{89{
89 m_deviceUri = serverAttrs.value(QStringLiteral("DeviceUri")).toString();90 m_deviceUri = serverAttrs.value(QStringLiteral("DeviceUri")).toString();
90}91}
9192
93void Printer::updateShared(const QMap<QString, QVariant> &serverAttrs)
94{
95 m_shared = serverAttrs.value(QStringLiteral("Shared")).toBool();
96}
97
92void Printer::loadAttributes()98void Printer::loadAttributes()
93{99{
94 auto opts = QStringList({100 auto opts = QStringList({
@@ -98,7 +104,8 @@
98 QStringLiteral("DefaultPrintQuality"),104 QStringLiteral("DefaultPrintQuality"),
99 QStringLiteral("SupportedPrintQualities"),105 QStringLiteral("SupportedPrintQualities"),
100 QStringLiteral("StateMessage"),106 QStringLiteral("StateMessage"),
101 QStringLiteral("DeviceUri")107 QStringLiteral("DeviceUri"),
108 QStringLiteral("Shared")
102 });109 });
103 auto result = m_backend->printerGetOptions(name(), opts);110 auto result = m_backend->printerGetOptions(name(), opts);
104111
@@ -107,6 +114,7 @@
107 updatePrintQualities(result);114 updatePrintQualities(result);
108 updateLastMessage(result);115 updateLastMessage(result);
109 updateDeviceUri(result);116 updateDeviceUri(result);
117 updateShared(result);
110}118}
111119
112ColorModel Printer::defaultColorModel() const120ColorModel Printer::defaultColorModel() const
@@ -211,6 +219,11 @@
211 return m_backend->state();219 return m_backend->state();
212}220}
213221
222bool Printer::shared() const
223{
224 return m_shared;
225}
226
214bool Printer::acceptJobs() const227bool Printer::acceptJobs() const
215{228{
216 return m_acceptJobs;229 return m_acceptJobs;
@@ -283,6 +296,16 @@
283 }296 }
284}297}
285298
299void Printer::setShared(const bool shared)
300{
301 if (this->shared() != shared) {
302 QString reply = m_backend->printerSetShared(name(), shared);
303 if (!reply.isEmpty()) {
304 qWarning() << Q_FUNC_INFO << "failed to set shared:" << reply;
305 }
306 }
307}
308
286void Printer::setDefaultPrintQuality(const PrintQuality &quality)309void Printer::setDefaultPrintQuality(const PrintQuality &quality)
287{310{
288 if (defaultPrintQuality() == quality) {311 if (defaultPrintQuality() == quality) {
@@ -344,7 +367,8 @@
344 && enabled() == other->enabled()367 && enabled() == other->enabled()
345 && state() == other->state()368 && state() == other->state()
346 && lastMessage() == other->lastMessage()369 && lastMessage() == other->lastMessage()
347 && deviceUri() == other->deviceUri();370 && deviceUri() == other->deviceUri()
371 && shared() == other->shared();
348}372}
349373
350void Printer::updateFrom(QSharedPointer<Printer> other)374void Printer::updateFrom(QSharedPointer<Printer> other)
351375
=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.h'
--- modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-02 14:41:00 +0000
+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-03 15:07:56 +0000
@@ -60,6 +60,7 @@
60 PrinterEnum::AccessControl accessControl() const;60 PrinterEnum::AccessControl accessControl() const;
61 PrinterEnum::ErrorPolicy errorPolicy() const;61 PrinterEnum::ErrorPolicy errorPolicy() const;
62 PrinterEnum::State state() const;62 PrinterEnum::State state() const;
63 bool shared() const;
63 bool acceptJobs() const;64 bool acceptJobs() const;
64 bool holdsDefinition() const;65 bool holdsDefinition() const;
65 QString lastMessage() const;66 QString lastMessage() const;
@@ -72,6 +73,7 @@
72 void setDefaultDuplexMode(const PrinterEnum::DuplexMode &duplexMode);73 void setDefaultDuplexMode(const PrinterEnum::DuplexMode &duplexMode);
73 void setEnabled(const bool enabled);74 void setEnabled(const bool enabled);
74 void setAcceptJobs(const bool accepting);75 void setAcceptJobs(const bool accepting);
76 void setShared(const bool shared);
75 void setDefaultPrintQuality(const PrintQuality &quality);77 void setDefaultPrintQuality(const PrintQuality &quality);
76 void setDefaultPageSize(const QPageSize &pageSize);78 void setDefaultPageSize(const QPageSize &pageSize);
77 void setJobModel(JobModel* jobModel);79 void setJobModel(JobModel* jobModel);
@@ -96,6 +98,7 @@
96 void updatePrintQualities(const QMap<QString, QVariant> &serverAttrs);98 void updatePrintQualities(const QMap<QString, QVariant> &serverAttrs);
97 void updateLastMessage(const QMap<QString, QVariant> &serverAttrs);99 void updateLastMessage(const QMap<QString, QVariant> &serverAttrs);
98 void updateDeviceUri(const QMap<QString, QVariant> &serverAttrs);100 void updateDeviceUri(const QMap<QString, QVariant> &serverAttrs);
101 void updateShared(const QMap<QString, QVariant> &serverAttrs);
99 void loadAttributes();102 void loadAttributes();
100103
101 JobFilter m_jobs;104 JobFilter m_jobs;
@@ -105,6 +108,7 @@
105 PrintQuality m_defaultPrintQuality;108 PrintQuality m_defaultPrintQuality;
106 QList<PrintQuality> m_supportedPrintQualities;109 QList<PrintQuality> m_supportedPrintQualities;
107 bool m_acceptJobs;110 bool m_acceptJobs;
111 bool m_shared;
108 QString m_deviceUri;112 QString m_deviceUri;
109113
110 QString m_stateMessage;114 QString m_stateMessage;
111115
=== modified file 'tests/unittests/Printers/mockbackend.h'
--- tests/unittests/Printers/mockbackend.h 2017-03-01 18:11:04 +0000
+++ tests/unittests/Printers/mockbackend.h 2017-03-03 15:07:56 +0000
@@ -105,6 +105,13 @@
105 return returnValue;105 return returnValue;
106 }106 }
107107
108 virtual QString printerSetShared(const QString &name,
109 const bool shared) override
110 {
111 printerOptions[name].insert("Shared", shared);
112 return returnValue;
113 }
114
108 virtual QString printerSetInfo(const QString &name,115 virtual QString printerSetInfo(const QString &name,
109 const QString &info) override116 const QString &info) override
110 {117 {
111118
=== modified file 'tests/unittests/Printers/tst_printer.cpp'
--- tests/unittests/Printers/tst_printer.cpp 2017-03-02 14:41:00 +0000
+++ tests/unittests/Printers/tst_printer.cpp 2017-03-03 15:07:56 +0000
@@ -289,6 +289,32 @@
289 p2.setAcceptJobs(false);289 p2.setAcceptJobs(false);
290 QVERIFY(!backend->printerOptions[m_printerName]["AcceptJobs"].toBool());290 QVERIFY(!backend->printerOptions[m_printerName]["AcceptJobs"].toBool());
291 }291 }
292 void testShared()
293 {
294 MockPrinterBackend *backend = new MockPrinterBackend(m_printerName);
295
296 backend->printerOptions[m_printerName].insert("Shared", false);
297 Printer p(backend);
298 QVERIFY(!p.shared());
299
300 backend->printerOptions[m_printerName].insert("Shared", true);
301 Printer p2(backend);
302 QVERIFY(p2.shared());
303 }
304 void testSetShared()
305 {
306 MockPrinterBackend *backend = new MockPrinterBackend(m_printerName);
307
308 backend->printerOptions[m_printerName].insert("Shared", false);
309 Printer p(backend);
310 p.setShared(true);
311 QVERIFY(backend->printerOptions[m_printerName]["Shared"].toBool());
312
313 backend->printerOptions[m_printerName].insert("Shared", true);
314 Printer p2(backend);
315 p2.setShared(false);
316 QVERIFY(!backend->printerOptions[m_printerName]["Shared"].toBool());
317 }
292 void testJobs()318 void testJobs()
293 {319 {
294 JobModel jobs;320 JobModel jobs;
295321
=== modified file 'tests/unittests/Printers/tst_printermodel.cpp'
--- tests/unittests/Printers/tst_printermodel.cpp 2017-03-02 14:41:00 +0000
+++ tests/unittests/Printers/tst_printermodel.cpp 2017-03-03 15:07:56 +0000
@@ -362,6 +362,27 @@
362 QCOMPARE(m_model->data(m_model->index(2), PrinterModel::AcceptJobsRole).toBool(),362 QCOMPARE(m_model->data(m_model->index(2), PrinterModel::AcceptJobsRole).toBool(),
363 true);363 true);
364 }364 }
365 void testSharedRole()
366 {
367 MockPrinterBackend* backendA = new MockPrinterBackend("a-printer");
368 backendA->printerOptions["a-printer"].insert("Shared", false);
369
370 auto printerA = QSharedPointer<Printer>(new Printer(backendA));
371 m_backend->mockPrinterLoaded(printerA);
372
373 MockPrinterBackend* backendB = new MockPrinterBackend("b-printer");
374 backendB->printerOptions["b-printer"].insert("Shared", true);
375
376 auto printerB = QSharedPointer<Printer>(new Printer(backendB));
377 m_backend->mockPrinterLoaded(printerB);
378
379 QCOMPARE(m_model->data(m_model->index(0), PrinterModel::SharedRole).toBool(),
380 false);
381 QCOMPARE(m_model->data(m_model->index(1), PrinterModel::SharedRole).toBool(),
382 false);
383 QCOMPARE(m_model->data(m_model->index(2), PrinterModel::SharedRole).toBool(),
384 true);
385 }
365 void testPrintQualityRole()386 void testPrintQualityRole()
366 {387 {
367 PrintQuality a;388 PrintQuality a;

Subscribers

People subscribed via source and target branches