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
1=== modified file 'modules/Ubuntu/Components/Extras/Example/Printers.qml'
2--- modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-02 15:08:24 +0000
3+++ modules/Ubuntu/Components/Extras/Example/Printers.qml 2017-03-03 15:07:56 +0000
4@@ -134,6 +134,19 @@
5 left: parent.left
6 right: parent.right
7 }
8+ text: "Shared"
9+
10+ control: Switch {
11+ checked: printer.shared
12+ onCheckedChanged: printer.shared = checked
13+ }
14+ }
15+
16+ ListItems.Standard {
17+ anchors {
18+ left: parent.left
19+ right: parent.right
20+ }
21 text: "Jobs"
22 progression: true
23 onClicked: pageStack.push(jobPage, { printer: printer })
24
25=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp'
26--- modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-01 12:53:55 +0000
27+++ modules/Ubuntu/Components/Extras/Printers/backend/backend.cpp 2017-03-03 15:07:56 +0000
28@@ -91,6 +91,14 @@
29 return QString();
30 }
31
32+QString PrinterBackend::printerSetShared(const QString &name,
33+ const bool shared)
34+{
35+ Q_UNUSED(name);
36+ Q_UNUSED(shared);
37+ return QString();
38+}
39+
40 QString PrinterBackend::printerSetInfo(const QString &name,
41 const QString &info)
42 {
43
44=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend.h'
45--- modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-01 12:53:55 +0000
46+++ modules/Ubuntu/Components/Extras/Printers/backend/backend.h 2017-03-03 15:07:56 +0000
47@@ -63,6 +63,8 @@
48 const QString &name,
49 const bool accept,
50 const QString &reason = QString::null);
51+ virtual QString printerSetShared(const QString &name,
52+ const bool shared);
53 virtual QString printerSetInfo(const QString &name,
54 const QString &info);
55 virtual QString printerAddOption(const QString &name,
56
57=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp'
58--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-02 14:29:46 +0000
59+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-03 15:07:56 +0000
60@@ -179,6 +179,16 @@
61 return QString();
62 }
63
64+QString PrinterCupsBackend::printerSetShared(const QString &name,
65+ const bool shared)
66+{
67+ if (!m_client->printerSetShared(name, shared)) {
68+ return m_client->getLastError();
69+ }
70+ return QString();
71+}
72+
73+
74 QString PrinterCupsBackend::printerSetInfo(const QString &name,
75 const QString &info)
76 {
77@@ -309,6 +319,9 @@
78 } else {
79 ret[option] = QString();
80 }
81+ } else if (option == QStringLiteral("Shared") && dest) {
82+ ret[option] = cupsGetOption("printer-is-shared",
83+ dest->num_options, dest->options);
84 }
85 }
86 return ret;
87
88=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h'
89--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-02 14:28:53 +0000
90+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-03-03 15:07:56 +0000
91@@ -55,6 +55,8 @@
92 const QString &name,
93 const bool accept,
94 const QString &reason = QString::null) override;
95+ virtual QString printerSetShared(const QString &name,
96+ const bool shared) override;
97 virtual QString printerSetInfo(const QString &name,
98 const QString &info) override;
99 virtual QString printerAddOption(const QString &name,
100
101=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp'
102--- modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-02 13:50:54 +0000
103+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_pdf.cpp 2017-03-03 15:07:56 +0000
104@@ -65,6 +65,8 @@
105 ret[option] = QLatin1String("");
106 } else if (option == QLatin1String("DeviceUri")) {
107 ret[option] = QLatin1String("");
108+ } else if (option == QLatin1String("Shared")) {
109+ ret[option] = false;
110 } else {
111 throw std::invalid_argument("Invalid value for PDF printer: " + option.toStdString());
112 }
113
114=== modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp'
115--- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-02 14:52:47 +0000
116+++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.cpp 2017-03-03 15:07:56 +0000
117@@ -250,6 +250,26 @@
118 }
119 }
120
121+bool IppClient::printerSetShared(const QString &printerName, const bool shared)
122+{
123+ ipp_t *request;
124+
125+ if (!isPrinterNameValid(printerName)) {
126+ setInternalStatus(QString("%1 is not a valid printer name.").arg(printerName));
127+ return false;
128+ }
129+
130+ request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
131+ addPrinterUri(request, printerName);
132+ addRequestingUsername(request, NULL);
133+ ippAddBoolean(request, IPP_TAG_OPERATION,
134+ "printer-is-shared", shared ? 1 : 0);
135+
136+ /* TODO: The request will fail if this was a printer class, and it should
137+ be retried. */
138+
139+ return sendRequest(request, CupsResourceAdmin);
140+}
141
142 bool IppClient::printerClassSetInfo(const QString &name,
143 const QString &info)
144
145=== modified file 'modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h'
146--- modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-02 14:28:53 +0000
147+++ modules/Ubuntu/Components/Extras/Printers/cups/ippclient.h 2017-03-03 15:07:56 +0000
148@@ -57,6 +57,7 @@
149 bool printerSetEnabled(const QString &printerName, const bool enabled);
150 bool printerSetAcceptJobs(const QString &printerName, const bool accept,
151 const QString &reason);
152+ bool printerSetShared(const QString &printerName, const bool shared);
153 bool printerClassSetInfo(const QString &name, const QString &info);
154 bool printerClassSetOption(const QString &name, const QString &option,
155 const QStringList &values);
156
157=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp'
158--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-02 14:28:53 +0000
159+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-03 15:07:56 +0000
160@@ -295,6 +295,9 @@
161 case AcceptJobsRole:
162 ret = printer->acceptJobs();
163 break;
164+ case SharedRole:
165+ ret = printer->shared();
166+ break;
167 }
168 }
169
170@@ -350,6 +353,9 @@
171 case AcceptJobsRole:
172 printer->setAcceptJobs(value.toBool());
173 break;
174+ case SharedRole:
175+ printer->setShared(value.toBool());
176+ break;
177 }
178 }
179
180@@ -372,6 +378,7 @@
181 names[MakeRole] = "make";
182 names[EnabledRole] = "printerEnabled";
183 names[AcceptJobsRole] = "acceptJobs";
184+ names[SharedRole] = "shared";
185 names[PrintQualityRole] = "printQuality";
186 names[SupportedPrintQualitiesRole] = "supportedPrintQualities";
187 names[DescriptionRole] = "description";
188
189=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.h'
190--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-02 14:28:53 +0000
191+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-03 15:07:56 +0000
192@@ -52,6 +52,7 @@
193 LocationRole,
194 EnabledRole,
195 AcceptJobsRole,
196+ SharedRole,
197 PrintQualityRole,
198 SupportedPrintQualitiesRole,
199 DescriptionRole,
200
201=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp'
202--- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-02 15:39:26 +0000
203+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-03 15:07:56 +0000
204@@ -84,11 +84,17 @@
205 m_stateMessage = serverAttrs.value(QStringLiteral("StateMessage")).toString();
206 }
207
208+
209 void Printer::updateDeviceUri(const QMap<QString, QVariant> &serverAttrs)
210 {
211 m_deviceUri = serverAttrs.value(QStringLiteral("DeviceUri")).toString();
212 }
213
214+void Printer::updateShared(const QMap<QString, QVariant> &serverAttrs)
215+{
216+ m_shared = serverAttrs.value(QStringLiteral("Shared")).toBool();
217+}
218+
219 void Printer::loadAttributes()
220 {
221 auto opts = QStringList({
222@@ -98,7 +104,8 @@
223 QStringLiteral("DefaultPrintQuality"),
224 QStringLiteral("SupportedPrintQualities"),
225 QStringLiteral("StateMessage"),
226- QStringLiteral("DeviceUri")
227+ QStringLiteral("DeviceUri"),
228+ QStringLiteral("Shared")
229 });
230 auto result = m_backend->printerGetOptions(name(), opts);
231
232@@ -107,6 +114,7 @@
233 updatePrintQualities(result);
234 updateLastMessage(result);
235 updateDeviceUri(result);
236+ updateShared(result);
237 }
238
239 ColorModel Printer::defaultColorModel() const
240@@ -211,6 +219,11 @@
241 return m_backend->state();
242 }
243
244+bool Printer::shared() const
245+{
246+ return m_shared;
247+}
248+
249 bool Printer::acceptJobs() const
250 {
251 return m_acceptJobs;
252@@ -283,6 +296,16 @@
253 }
254 }
255
256+void Printer::setShared(const bool shared)
257+{
258+ if (this->shared() != shared) {
259+ QString reply = m_backend->printerSetShared(name(), shared);
260+ if (!reply.isEmpty()) {
261+ qWarning() << Q_FUNC_INFO << "failed to set shared:" << reply;
262+ }
263+ }
264+}
265+
266 void Printer::setDefaultPrintQuality(const PrintQuality &quality)
267 {
268 if (defaultPrintQuality() == quality) {
269@@ -344,7 +367,8 @@
270 && enabled() == other->enabled()
271 && state() == other->state()
272 && lastMessage() == other->lastMessage()
273- && deviceUri() == other->deviceUri();
274+ && deviceUri() == other->deviceUri()
275+ && shared() == other->shared();
276 }
277
278 void Printer::updateFrom(QSharedPointer<Printer> other)
279
280=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.h'
281--- modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-02 14:41:00 +0000
282+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.h 2017-03-03 15:07:56 +0000
283@@ -60,6 +60,7 @@
284 PrinterEnum::AccessControl accessControl() const;
285 PrinterEnum::ErrorPolicy errorPolicy() const;
286 PrinterEnum::State state() const;
287+ bool shared() const;
288 bool acceptJobs() const;
289 bool holdsDefinition() const;
290 QString lastMessage() const;
291@@ -72,6 +73,7 @@
292 void setDefaultDuplexMode(const PrinterEnum::DuplexMode &duplexMode);
293 void setEnabled(const bool enabled);
294 void setAcceptJobs(const bool accepting);
295+ void setShared(const bool shared);
296 void setDefaultPrintQuality(const PrintQuality &quality);
297 void setDefaultPageSize(const QPageSize &pageSize);
298 void setJobModel(JobModel* jobModel);
299@@ -96,6 +98,7 @@
300 void updatePrintQualities(const QMap<QString, QVariant> &serverAttrs);
301 void updateLastMessage(const QMap<QString, QVariant> &serverAttrs);
302 void updateDeviceUri(const QMap<QString, QVariant> &serverAttrs);
303+ void updateShared(const QMap<QString, QVariant> &serverAttrs);
304 void loadAttributes();
305
306 JobFilter m_jobs;
307@@ -105,6 +108,7 @@
308 PrintQuality m_defaultPrintQuality;
309 QList<PrintQuality> m_supportedPrintQualities;
310 bool m_acceptJobs;
311+ bool m_shared;
312 QString m_deviceUri;
313
314 QString m_stateMessage;
315
316=== modified file 'tests/unittests/Printers/mockbackend.h'
317--- tests/unittests/Printers/mockbackend.h 2017-03-01 18:11:04 +0000
318+++ tests/unittests/Printers/mockbackend.h 2017-03-03 15:07:56 +0000
319@@ -105,6 +105,13 @@
320 return returnValue;
321 }
322
323+ virtual QString printerSetShared(const QString &name,
324+ const bool shared) override
325+ {
326+ printerOptions[name].insert("Shared", shared);
327+ return returnValue;
328+ }
329+
330 virtual QString printerSetInfo(const QString &name,
331 const QString &info) override
332 {
333
334=== modified file 'tests/unittests/Printers/tst_printer.cpp'
335--- tests/unittests/Printers/tst_printer.cpp 2017-03-02 14:41:00 +0000
336+++ tests/unittests/Printers/tst_printer.cpp 2017-03-03 15:07:56 +0000
337@@ -289,6 +289,32 @@
338 p2.setAcceptJobs(false);
339 QVERIFY(!backend->printerOptions[m_printerName]["AcceptJobs"].toBool());
340 }
341+ void testShared()
342+ {
343+ MockPrinterBackend *backend = new MockPrinterBackend(m_printerName);
344+
345+ backend->printerOptions[m_printerName].insert("Shared", false);
346+ Printer p(backend);
347+ QVERIFY(!p.shared());
348+
349+ backend->printerOptions[m_printerName].insert("Shared", true);
350+ Printer p2(backend);
351+ QVERIFY(p2.shared());
352+ }
353+ void testSetShared()
354+ {
355+ MockPrinterBackend *backend = new MockPrinterBackend(m_printerName);
356+
357+ backend->printerOptions[m_printerName].insert("Shared", false);
358+ Printer p(backend);
359+ p.setShared(true);
360+ QVERIFY(backend->printerOptions[m_printerName]["Shared"].toBool());
361+
362+ backend->printerOptions[m_printerName].insert("Shared", true);
363+ Printer p2(backend);
364+ p2.setShared(false);
365+ QVERIFY(!backend->printerOptions[m_printerName]["Shared"].toBool());
366+ }
367 void testJobs()
368 {
369 JobModel jobs;
370
371=== modified file 'tests/unittests/Printers/tst_printermodel.cpp'
372--- tests/unittests/Printers/tst_printermodel.cpp 2017-03-02 14:41:00 +0000
373+++ tests/unittests/Printers/tst_printermodel.cpp 2017-03-03 15:07:56 +0000
374@@ -362,6 +362,27 @@
375 QCOMPARE(m_model->data(m_model->index(2), PrinterModel::AcceptJobsRole).toBool(),
376 true);
377 }
378+ void testSharedRole()
379+ {
380+ MockPrinterBackend* backendA = new MockPrinterBackend("a-printer");
381+ backendA->printerOptions["a-printer"].insert("Shared", false);
382+
383+ auto printerA = QSharedPointer<Printer>(new Printer(backendA));
384+ m_backend->mockPrinterLoaded(printerA);
385+
386+ MockPrinterBackend* backendB = new MockPrinterBackend("b-printer");
387+ backendB->printerOptions["b-printer"].insert("Shared", true);
388+
389+ auto printerB = QSharedPointer<Printer>(new Printer(backendB));
390+ m_backend->mockPrinterLoaded(printerB);
391+
392+ QCOMPARE(m_model->data(m_model->index(0), PrinterModel::SharedRole).toBool(),
393+ false);
394+ QCOMPARE(m_model->data(m_model->index(1), PrinterModel::SharedRole).toBool(),
395+ false);
396+ QCOMPARE(m_model->data(m_model->index(2), PrinterModel::SharedRole).toBool(),
397+ true);
398+ }
399 void testPrintQualityRole()
400 {
401 PrintQuality a;

Subscribers

People subscribed via source and target branches