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