Merge lp:~jonas-drange/ubuntu-settings-components/cups-notifications into lp:~phablet-team/ubuntu-settings-components/printer-components
- cups-notifications
- Merge into printer-components
Proposed by
Jonas G. Drange
Status: | Merged |
---|---|
Approved by: | Andrew Hayzen |
Approved revision: | 227 |
Merged at revision: | 225 |
Proposed branch: | lp:~jonas-drange/ubuntu-settings-components/cups-notifications |
Merge into: | lp:~phablet-team/ubuntu-settings-components/printer-components |
Diff against target: |
880 lines (+417/-79) 17 files modified
plugins/Ubuntu/Settings/Printers/CMakeLists.txt (+9/-1) plugins/Ubuntu/Settings/Printers/backend/backend.h (+25/-5) plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp (+46/-9) plugins/Ubuntu/Settings/Printers/backend/backend_cups.h (+8/-0) plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp (+10/-0) plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h (+2/-0) plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp (+61/-0) plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h (+2/-0) plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+21/-11) plugins/Ubuntu/Settings/Printers/models/printermodel.h (+5/-5) plugins/Ubuntu/Settings/Printers/org.cups.cupsd.Notifier.xml (+146/-0) plugins/Ubuntu/Settings/Printers/printers/printers.cpp (+7/-5) plugins/Ubuntu/Settings/Printers/printers/printers.h (+2/-4) tests/unittests/Printers/mockbackend.h (+35/-20) tests/unittests/Printers/tst_printerfilter.cpp (+8/-6) tests/unittests/Printers/tst_printermodel.cpp (+28/-11) tests/unittests/Printers/tst_printers.cpp (+2/-2) |
To merge this branch: | bzr merge lp:~jonas-drange/ubuntu-settings-components/cups-notifications |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrew Hayzen (community) | Approve | ||
Review via email: mp+316253@code.launchpad.net |
Commit message
* Deprecate QTimer based update()
* Replace with cups subscription based update()
* Fixes tests.
Description of the change
To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote : | # |
- 224. By Jonas G. Drange
-
implements fewer signals
- 225. By Jonas G. Drange
-
removes unused stuff
Revision history for this message
Andrew Hayzen (ahayzen) wrote : | # |
This looks good, can you do a pull of trunk. Then this can be approved. We can link the JobModel in a separate branch :-)
- 226. By Jonas G. Drange
-
merges trunk
- 227. By Jonas G. Drange
-
mock backend returns an empty job list for now
Revision history for this message
Andrew Hayzen (ahayzen) wrote : | # |
LGTM, and the tests pass now :-)
100% tests passed, 0 tests failed out of 7
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'plugins/Ubuntu/Settings/Printers/CMakeLists.txt' |
2 | --- plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-02-02 16:00:55 +0000 |
3 | +++ plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-02-03 12:26:13 +0000 |
4 | @@ -2,14 +2,21 @@ |
5 | |
6 | add_definitions(-DUBUNTUSETTINGSPRINTERS_LIBRARY) |
7 | |
8 | -include_directories(${CUPS_INCLUDE_DIR}) |
9 | +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CUPS_INCLUDE_DIR}) |
10 | |
11 | find_package(Qt5Gui REQUIRED) |
12 | find_package(Qt5PrintSupport REQUIRED) |
13 | find_package(Qt5Qml REQUIRED) |
14 | +find_package(Qt5DBus REQUIRED) |
15 | find_package(Qt5Concurrent REQUIRED) |
16 | |
17 | +qt5_add_dbus_interface( |
18 | + GEN_SOURCES |
19 | + ${CMAKE_CURRENT_SOURCE_DIR}/org.cups.cupsd.Notifier.xml |
20 | + cupsdnotifier) |
21 | + |
22 | add_library(UbuntuSettingsPrintersQml SHARED |
23 | + ${GEN_SOURCES} |
24 | backend/backend.cpp |
25 | backend/backend_cups.cpp |
26 | backend/backend_pdf.cpp |
27 | @@ -29,6 +36,7 @@ |
28 | ) |
29 | |
30 | target_link_libraries(UbuntuSettingsPrintersQml |
31 | + Qt5::DBus |
32 | Qt5::Gui |
33 | Qt5::PrintSupport |
34 | Qt5::Qml |
35 | |
36 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend.h' |
37 | --- plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-02 17:22:55 +0000 |
38 | +++ plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-02-03 12:26:13 +0000 |
39 | @@ -149,14 +149,34 @@ |
40 | virtual void refresh(); |
41 | |
42 | Q_SIGNALS: |
43 | - void printerAdded(const QString &name); |
44 | - void printerModified(const QString &name, const bool ppdChanged); |
45 | - void printerDeleted(const QString &name); |
46 | - void printerStateChanged(const QString &name); |
47 | - |
48 | void printerDriversLoaded(const QList<PrinterDriver> &drivers); |
49 | void printerDriversFailedToLoad(const QString &errorMessage); |
50 | |
51 | + void printerAdded( |
52 | + const QString &text, |
53 | + const QString &printerUri, |
54 | + const QString &printerName, |
55 | + uint printerState, |
56 | + const QString &printerStateReason, |
57 | + bool acceptingJobs |
58 | + ); |
59 | + void printerDeleted( |
60 | + const QString &text, |
61 | + const QString &printerUri, |
62 | + const QString &printerName, |
63 | + uint printerState, |
64 | + const QString &printerStateReason, |
65 | + bool acceptingJobs |
66 | + ); |
67 | + void printerModified( |
68 | + const QString &text, |
69 | + const QString &printerUri, |
70 | + const QString &printerName, |
71 | + uint printerState, |
72 | + const QString &printerStateReason, |
73 | + bool acceptingJobs |
74 | + ); |
75 | + |
76 | protected: |
77 | const QString m_printerName; |
78 | }; |
79 | |
80 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp' |
81 | --- plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-02 17:22:55 +0000 |
82 | +++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-03 12:26:13 +0000 |
83 | @@ -19,29 +19,56 @@ |
84 | #include "i18n.h" |
85 | #include "utils.h" |
86 | |
87 | +#include <QDBusConnection> |
88 | |
89 | PrinterCupsBackend::PrinterCupsBackend(QObject *parent) |
90 | - : PrinterCupsBackend(new CupsFacade(), QPrinterInfo(), parent) |
91 | + : PrinterCupsBackend(new CupsFacade(), QPrinterInfo(), |
92 | + new OrgCupsCupsdNotifierInterface("", |
93 | + CUPSD_NOTIFIER_DBUS_PATH, |
94 | + QDBusConnection::systemBus()), |
95 | + parent) |
96 | { |
97 | - // If we create the CupsFacade, we're in charge of RAII. |
98 | + // Use proper RAII of things we create: |
99 | m_cups->setParent(this); |
100 | - |
101 | - connect(m_cups, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&)), |
102 | - this, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&))); |
103 | - connect(m_cups, SIGNAL(printerDriversFailedToLoad(const QString&)), |
104 | - this, SIGNAL(printerDriversFailedToLoad(const QString&))); |
105 | + m_notifier->setParent(this); |
106 | } |
107 | |
108 | PrinterCupsBackend::PrinterCupsBackend(CupsFacade *cups, QPrinterInfo info, |
109 | + OrgCupsCupsdNotifierInterface *notifier, |
110 | QObject *parent) |
111 | : PrinterBackend(info.printerName(), parent) |
112 | , m_cups(cups) |
113 | , m_info(info) |
114 | + , m_notifier(notifier) |
115 | { |
116 | + connect(m_cups, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&)), |
117 | + this, SIGNAL(printerDriversLoaded(const QList<PrinterDriver>&))); |
118 | + connect(m_cups, SIGNAL(printerDriversFailedToLoad(const QString&)), |
119 | + this, SIGNAL(printerDriversFailedToLoad(const QString&))); |
120 | + |
121 | + connect(m_notifier, SIGNAL(PrinterAdded(const QString&, const QString&, |
122 | + const QString&, uint, |
123 | + const QString&, bool)), |
124 | + this, SIGNAL(printerAdded(const QString&, const QString&, |
125 | + const QString&, uint, |
126 | + const QString&, bool))); |
127 | + connect(m_notifier, SIGNAL(PrinterDeleted(const QString&, const QString&, |
128 | + const QString&, uint, |
129 | + const QString&, bool)), |
130 | + this, SIGNAL(printerDeleted(const QString&, const QString&, |
131 | + const QString&, uint, |
132 | + const QString&, bool))); |
133 | + connect(m_notifier, SIGNAL(PrinterModified(const QString&, const QString&, |
134 | + const QString&, uint, |
135 | + const QString&, bool)), |
136 | + this, SIGNAL(printerModified(const QString&, const QString&, |
137 | + const QString&, uint, |
138 | + const QString&, bool))); |
139 | } |
140 | |
141 | PrinterCupsBackend::~PrinterCupsBackend() |
142 | { |
143 | + cancelSubscription(); |
144 | } |
145 | |
146 | QString PrinterCupsBackend::printerAdd(const QString &name, |
147 | @@ -316,14 +343,13 @@ |
148 | QPrinterInfo info = QPrinterInfo::printerInfo(name); |
149 | |
150 | if (!info.isNull()) { |
151 | - list.append(new Printer(new PrinterCupsBackend(m_cups, info))); |
152 | + list.append(new Printer(new PrinterCupsBackend(m_cups, info, m_notifier))); |
153 | } else { |
154 | qWarning() << "Printer is null so skipping (" << name << ")"; |
155 | } |
156 | } |
157 | |
158 | // Cups allows a faux PDF printer. |
159 | - // TODO: Translate. |
160 | list.append(new Printer(new PrinterPdfBackend(__("Create PDF")))); |
161 | |
162 | return list; |
163 | @@ -362,3 +388,14 @@ |
164 | m_info = QPrinterInfo::printerInfo(m_printerName); |
165 | } |
166 | } |
167 | + |
168 | +void PrinterCupsBackend::createSubscription() |
169 | +{ |
170 | + m_cupsSubscriptionId = m_cups->createSubscription(); |
171 | +} |
172 | + |
173 | +void PrinterCupsBackend::cancelSubscription() |
174 | +{ |
175 | + if (m_cupsSubscriptionId > 0) |
176 | + m_cups->cancelSubscription(m_cupsSubscriptionId); |
177 | +} |
178 | |
179 | === modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.h' |
180 | --- plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 2017-02-02 17:22:55 +0000 |
181 | +++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 2017-02-03 12:26:13 +0000 |
182 | @@ -19,14 +19,18 @@ |
183 | |
184 | #include "backend/backend.h" |
185 | #include "cups/cupsfacade.h" |
186 | +#include "cupsdnotifier.h" // Note: this file was generated. |
187 | |
188 | #include <QPrinterInfo> |
189 | |
190 | +#define CUPSD_NOTIFIER_DBUS_PATH "/org/cups/cupsd/Notifier" |
191 | + |
192 | class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend |
193 | { |
194 | public: |
195 | explicit PrinterCupsBackend(QObject *parent = Q_NULLPTR); |
196 | explicit PrinterCupsBackend(CupsFacade *cups, QPrinterInfo info, |
197 | + OrgCupsCupsdNotifierInterface* notifier, |
198 | QObject *parent = Q_NULLPTR); |
199 | virtual ~PrinterCupsBackend() override; |
200 | |
201 | @@ -125,10 +129,14 @@ |
202 | |
203 | public Q_SLOTS: |
204 | virtual void refresh() override; |
205 | + void createSubscription(); |
206 | |
207 | private: |
208 | + void cancelSubscription(); |
209 | CupsFacade *m_cups; |
210 | QPrinterInfo m_info; |
211 | + OrgCupsCupsdNotifierInterface *m_notifier; |
212 | + int m_cupsSubscriptionId = -1; |
213 | }; |
214 | |
215 | #endif // USC_PRINTERS_CUPS_BACKEND_H |
216 | |
217 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp' |
218 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-02 16:00:55 +0000 |
219 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-03 12:26:13 +0000 |
220 | @@ -433,6 +433,16 @@ |
221 | Q_EMIT requestPrinterDriverCancel(); |
222 | } |
223 | |
224 | +int CupsFacade::createSubscription() |
225 | +{ |
226 | + return helper.createSubscription(); |
227 | +} |
228 | + |
229 | +void CupsFacade::cancelSubscription(const int &subscriptionId) |
230 | +{ |
231 | + helper.cancelSubscription(subscriptionId); |
232 | +} |
233 | + |
234 | PrinterDriverLoader::PrinterDriverLoader( |
235 | const QString &deviceId, const QString &language, |
236 | const QString &makeModel, const QString &product, |
237 | |
238 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h' |
239 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-02 16:00:55 +0000 |
240 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-03 12:26:13 +0000 |
241 | @@ -92,6 +92,8 @@ |
242 | QList<cups_job_t *> printerGetJobs(const QString &name); |
243 | int printFileToDest(const QString &filepath, const QString &title, |
244 | const cups_dest_t *dest); |
245 | + int createSubscription(); |
246 | + void cancelSubscription(const int &subscriptionId); |
247 | |
248 | public Q_SLOTS: |
249 | void requestPrinterDrivers( |
250 | |
251 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp' |
252 | --- plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp 2017-01-30 11:37:07 +0000 |
253 | +++ plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp 2017-02-03 12:26:13 +0000 |
254 | @@ -735,3 +735,64 @@ |
255 | return cupsDoRequest(m_connection, request, |
256 | resourceChar.toUtf8()); |
257 | } |
258 | + |
259 | +int CupsPkHelper::createSubscription() |
260 | +{ |
261 | + ipp_t *req; |
262 | + ipp_t *resp; |
263 | + ipp_attribute_t *attr; |
264 | + int subscriptionId = -1; |
265 | + |
266 | + req = ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION); |
267 | + ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, |
268 | + "printer-uri", NULL, "/"); |
269 | + ippAddString(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, |
270 | + "notify-events", NULL, "all"); |
271 | + ippAddString(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, |
272 | + "notify-recipient-uri", NULL, "dbus://"); |
273 | + ippAddInteger(req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, |
274 | + "notify-lease-duration", 0); |
275 | + |
276 | + resp = cupsDoRequest(m_connection, req, |
277 | + getResource(CphResourceRoot).toUtf8()); |
278 | + if (!isReplyOk(resp, true)) { |
279 | + return subscriptionId; |
280 | + } |
281 | + |
282 | + attr = ippFindAttribute(resp, "notify-subscription-id", IPP_TAG_INTEGER); |
283 | + |
284 | + if (!attr) { |
285 | + qWarning() << "ipp-create-printer-subscription response doesn't" |
286 | + " contain subscription id."; |
287 | + } else { |
288 | + subscriptionId = ippGetInteger(attr, 0); |
289 | + } |
290 | + |
291 | + ippDelete (resp); |
292 | + |
293 | + return subscriptionId; |
294 | +} |
295 | + |
296 | +void CupsPkHelper::cancelSubscription(const int &subscriptionId) |
297 | +{ |
298 | + ipp_t *req; |
299 | + ipp_t *resp; |
300 | + |
301 | + if (subscriptionId <= 0) { |
302 | + return; |
303 | + } |
304 | + |
305 | + req = ippNewRequest(IPP_CANCEL_SUBSCRIPTION); |
306 | + ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, |
307 | + "printer-uri", NULL, "/"); |
308 | + ippAddInteger(req, IPP_TAG_OPERATION, IPP_TAG_INTEGER, |
309 | + "notify-subscription-id", subscriptionId); |
310 | + |
311 | + resp = cupsDoRequest(m_connection, req, |
312 | + getResource(CphResourceRoot).toUtf8()); |
313 | + if (!isReplyOk(resp, true)) { |
314 | + return; |
315 | + } |
316 | + |
317 | + ippDelete(resp); |
318 | +} |
319 | |
320 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h' |
321 | --- plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h 2017-01-26 16:14:55 +0000 |
322 | +++ plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h 2017-02-03 12:26:13 +0000 |
323 | @@ -73,6 +73,8 @@ |
324 | const QStringList &includeSchemes = QStringList(), |
325 | const QStringList &excludeSchemes = QStringList() |
326 | ); |
327 | + int createSubscription(); |
328 | + void cancelSubscription(const int &subscriptionId); |
329 | |
330 | private: |
331 | enum CphResource |
332 | |
333 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp' |
334 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-02-02 16:00:55 +0000 |
335 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-02-03 12:26:13 +0000 |
336 | @@ -24,31 +24,41 @@ |
337 | #include <QDebug> |
338 | #include <QQmlEngine> |
339 | |
340 | -PrinterModel::PrinterModel(const int updateIntervalMSecs, QObject *parent) |
341 | - : PrinterModel(new PrinterCupsBackend, updateIntervalMSecs, parent) |
342 | +PrinterModel::PrinterModel(QObject *parent) |
343 | + : PrinterModel(new PrinterCupsBackend, parent) |
344 | { |
345 | } |
346 | |
347 | -PrinterModel::PrinterModel(PrinterBackend *backend, |
348 | - const int updateIntervalMSecs, |
349 | - QObject *parent) |
350 | +PrinterModel::PrinterModel(PrinterBackend *backend, QObject *parent) |
351 | : QAbstractListModel(parent) |
352 | , m_backend(backend) |
353 | { |
354 | update(); |
355 | - startUpdateTimer(updateIntervalMSecs); |
356 | + |
357 | + QObject::connect(m_backend, &PrinterBackend::printerAdded, |
358 | + this, &PrinterModel::printerSignalCatchall); |
359 | + QObject::connect(m_backend, &PrinterBackend::printerModified, |
360 | + this, &PrinterModel::printerSignalCatchall); |
361 | + QObject::connect(m_backend, &PrinterBackend::printerDeleted, |
362 | + this, &PrinterModel::printerSignalCatchall); |
363 | } |
364 | |
365 | PrinterModel::~PrinterModel() |
366 | { |
367 | } |
368 | |
369 | -void PrinterModel::startUpdateTimer(const int &msecs) |
370 | +void PrinterModel::printerSignalCatchall( |
371 | + const QString &text, const QString &printerUri, |
372 | + const QString &printerName, uint printerState, |
373 | + const QString &printerStateReason, bool acceptingJobs) |
374 | { |
375 | - // Start a timer to poll for changes in the printers |
376 | - m_update_timer.setParent(this); |
377 | - connect(&m_update_timer, SIGNAL(timeout()), this, SLOT(update())); |
378 | - m_update_timer.start(msecs); |
379 | + Q_UNUSED(text); |
380 | + Q_UNUSED(printerUri); |
381 | + Q_UNUSED(printerName); |
382 | + Q_UNUSED(printerState); |
383 | + Q_UNUSED(printerStateReason); |
384 | + Q_UNUSED(acceptingJobs); |
385 | + update(); |
386 | } |
387 | |
388 | void PrinterModel::update() |
389 | |
390 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.h' |
391 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-02-02 16:00:55 +0000 |
392 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-02-03 12:26:13 +0000 |
393 | @@ -35,9 +35,8 @@ |
394 | Q_OBJECT |
395 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
396 | public: |
397 | - explicit PrinterModel(const int updateIntervalMSecs=5000, QObject *parent = Q_NULLPTR); |
398 | - explicit PrinterModel(PrinterBackend *backend, const int updateIntervalMSecs=5000, |
399 | - QObject *parent = Q_NULLPTR); |
400 | + explicit PrinterModel(QObject *parent = Q_NULLPTR); |
401 | + explicit PrinterModel(PrinterBackend *backend, QObject *parent = Q_NULLPTR); |
402 | ~PrinterModel(); |
403 | |
404 | enum Roles |
405 | @@ -80,7 +79,6 @@ |
406 | |
407 | Q_INVOKABLE QVariantMap get(const int row) const; |
408 | private: |
409 | - QTimer m_update_timer; |
410 | PrinterBackend *m_backend; |
411 | |
412 | /* FIXME: there's currently no need to share the Printer obj with QML, so |
413 | @@ -89,8 +87,10 @@ |
414 | QMap<QString, JobModel *> m_job_models; |
415 | |
416 | private Q_SLOTS: |
417 | - void startUpdateTimer(const int &msecs); |
418 | void update(); |
419 | + void printerSignalCatchall(const QString &text, const QString &printerUri, |
420 | + const QString &printerName, uint printerState, |
421 | + const QString &printerStateReason, bool acceptingJobs); |
422 | |
423 | Q_SIGNALS: |
424 | void countChanged(); |
425 | |
426 | === added file 'plugins/Ubuntu/Settings/Printers/org.cups.cupsd.Notifier.xml' |
427 | --- plugins/Ubuntu/Settings/Printers/org.cups.cupsd.Notifier.xml 1970-01-01 00:00:00 +0000 |
428 | +++ plugins/Ubuntu/Settings/Printers/org.cups.cupsd.Notifier.xml 2017-02-03 12:26:13 +0000 |
429 | @@ -0,0 +1,146 @@ |
430 | +<node> |
431 | + |
432 | + <interface name="org.cups.cupsd.Notifier"> |
433 | + |
434 | + <signal name="ServerStarted"> |
435 | + <arg type="s" name="text" /> |
436 | + </signal> |
437 | + |
438 | + <signal name="ServerRestarted"> |
439 | + <arg type="s" name="text" /> |
440 | + </signal> |
441 | + |
442 | + <signal name="ServerStopped"> |
443 | + <arg type="s" name="text" /> |
444 | + </signal> |
445 | + |
446 | + <signal name="ServerAudit"> |
447 | + <arg type="s" name="text" /> |
448 | + </signal> |
449 | + |
450 | + <signal name="PrinterAdded"> |
451 | + <arg type="s" name="text" /> |
452 | + <arg type="s" name="printer_uri" /> |
453 | + <arg type="s" name="printer_name" /> |
454 | + <arg type="u" name="printer_state" /> |
455 | + <arg type="s" name="printer_state_reasons" /> |
456 | + <arg type="b" name="printer_is_accepting_jobs" /> |
457 | + </signal> |
458 | + |
459 | + <signal name="PrinterDeleted"> |
460 | + <arg type="s" name="text" /> |
461 | + <arg type="s" name="printer_uri" /> |
462 | + <arg type="s" name="printer_name" /> |
463 | + <arg type="u" name="printer_state" /> |
464 | + <arg type="s" name="printer_state_reasons" /> |
465 | + <arg type="b" name="printer_is_accepting_jobs" /> |
466 | + </signal> |
467 | + |
468 | + <signal name="PrinterModified"> |
469 | + <arg type="s" name="text" /> |
470 | + <arg type="s" name="printer_uri" /> |
471 | + <arg type="s" name="printer_name" /> |
472 | + <arg type="u" name="printer_state" /> |
473 | + <arg type="s" name="printer_state_reasons" /> |
474 | + <arg type="b" name="printer_is_accepting_jobs" /> |
475 | + </signal> |
476 | + |
477 | + <signal name="PrinterRestarted"> |
478 | + <arg type="s" name="text" /> |
479 | + <arg type="s" name="printer_uri" /> |
480 | + <arg type="s" name="printer_name" /> |
481 | + <arg type="u" name="printer_state" /> |
482 | + <arg type="s" name="printer_state_reasons" /> |
483 | + <arg type="b" name="printer_is_accepting_jobs" /> |
484 | + </signal> |
485 | + |
486 | + <signal name="PrinterStopped"> |
487 | + <arg type="s" name="text" /> |
488 | + <arg type="s" name="printer_uri" /> |
489 | + <arg type="s" name="printer_name" /> |
490 | + <arg type="u" name="printer_state" /> |
491 | + <arg type="s" name="printer_state_reasons" /> |
492 | + <arg type="b" name="printer_is_accepting_jobs" /> |
493 | + </signal> |
494 | + |
495 | + <signal name="PrinterShutdown"> |
496 | + <arg type="s" name="text" /> |
497 | + <arg type="s" name="printer_uri" /> |
498 | + <arg type="s" name="printer_name" /> |
499 | + <arg type="u" name="printer_state" /> |
500 | + <arg type="s" name="printer_state_reasons" /> |
501 | + <arg type="b" name="printer_is_accepting_jobs" /> |
502 | + </signal> |
503 | + |
504 | + <signal name="PrinterStateChanged"> |
505 | + <arg type="s" name="text" /> |
506 | + <arg type="s" name="printer_uri" /> |
507 | + <arg type="s" name="printer_name" /> |
508 | + <arg type="u" name="printer_state" /> |
509 | + <arg type="s" name="printer_state_reasons" /> |
510 | + <arg type="b" name="printer_is_accepting_jobs" /> |
511 | + </signal> |
512 | + |
513 | + <signal name="PrinterFinishingsChanged"> |
514 | + <arg type="s" name="text" /> |
515 | + <arg type="s" name="printer_uri" /> |
516 | + <arg type="s" name="printer_name" /> |
517 | + <arg type="u" name="printer_state" /> |
518 | + <arg type="s" name="printer_state_reasons" /> |
519 | + <arg type="b" name="printer_is_accepting_jobs" /> |
520 | + </signal> |
521 | + |
522 | + <signal name="PrinterMediaChanged"> |
523 | + <arg type="s" name="text" /> |
524 | + <arg type="s" name="printer_uri" /> |
525 | + <arg type="s" name="printer_name" /> |
526 | + <arg type="u" name="printer_state" /> |
527 | + <arg type="s" name="printer_state_reasons" /> |
528 | + <arg type="b" name="printer_is_accepting_jobs" /> |
529 | + </signal> |
530 | + |
531 | + <signal name="JobCreated"> |
532 | + <arg type="s" name="text" /> |
533 | + <arg type="s" name="printer_uri" /> |
534 | + <arg type="s" name="printer_name" /> |
535 | + <arg type="u" name="printer_state" /> |
536 | + <arg type="s" name="printer_state_reasons" /> |
537 | + <arg type="b" name="printer_is_accepting_jobs" /> |
538 | + <arg type="u" name="job_id" /> |
539 | + <arg type="u" name="job_state" /> |
540 | + <arg type="s" name="job_state_reasons" /> |
541 | + <arg type="s" name="job_name" /> |
542 | + <arg type="u" name="job_impressions_completed" /> |
543 | + </signal> |
544 | + |
545 | + <signal name="JobCompleted"> |
546 | + <arg type="s" name="text" /> |
547 | + <arg type="s" name="printer_uri" /> |
548 | + <arg type="s" name="printer_name" /> |
549 | + <arg type="u" name="printer_state" /> |
550 | + <arg type="s" name="printer_state_reasons" /> |
551 | + <arg type="b" name="printer_is_accepting_jobs" /> |
552 | + <arg type="u" name="job_id" /> |
553 | + <arg type="u" name="job_state" /> |
554 | + <arg type="s" name="job_state_reasons" /> |
555 | + <arg type="s" name="job_name" /> |
556 | + <arg type="u" name="job_impressions_completed" /> |
557 | + </signal> |
558 | + |
559 | + <signal name="JobState"> |
560 | + <arg type="s" name="text" /> |
561 | + <arg type="s" name="printer_uri" /> |
562 | + <arg type="s" name="printer_name" /> |
563 | + <arg type="u" name="printer_state" /> |
564 | + <arg type="s" name="printer_state_reasons" /> |
565 | + <arg type="b" name="printer_is_accepting_jobs" /> |
566 | + <arg type="u" name="job_id" /> |
567 | + <arg type="u" name="job_state" /> |
568 | + <arg type="s" name="job_state_reasons" /> |
569 | + <arg type="s" name="job_name" /> |
570 | + <arg type="u" name="job_impressions_completed" /> |
571 | + </signal> |
572 | + |
573 | + </interface> |
574 | + |
575 | +</node> |
576 | |
577 | === modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.cpp' |
578 | --- plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-02-01 14:56:58 +0000 |
579 | +++ plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-02-03 12:26:13 +0000 |
580 | @@ -19,17 +19,15 @@ |
581 | |
582 | #include <QQmlEngine> |
583 | |
584 | -Printers::Printers(int printerUpdateIntervalMSecs, QObject *parent) |
585 | - : Printers(new PrinterCupsBackend, printerUpdateIntervalMSecs, parent) |
586 | +Printers::Printers(QObject *parent) : Printers(new PrinterCupsBackend, parent) |
587 | { |
588 | } |
589 | |
590 | -Printers::Printers(PrinterBackend *backend, int printerUpdateIntervalMSecs, |
591 | - QObject *parent) |
592 | +Printers::Printers(PrinterBackend *backend, QObject *parent) |
593 | : QObject(parent) |
594 | , m_backend(backend) |
595 | , m_drivers(backend) |
596 | - , m_model(backend, printerUpdateIntervalMSecs) |
597 | + , m_model(backend) |
598 | { |
599 | m_allPrinters.setSourceModel(&m_model); |
600 | m_allPrinters.setSortRole(PrinterModel::Roles::DefaultPrinterRole); |
601 | @@ -45,6 +43,10 @@ |
602 | |
603 | connect(&m_drivers, SIGNAL(filterComplete()), |
604 | this, SIGNAL(driverFilterChanged())); |
605 | + |
606 | + if (m_backend->backendType() == PrinterBackend::BackendType::CupsType) { |
607 | + ((PrinterCupsBackend*) m_backend)->createSubscription(); |
608 | + } |
609 | } |
610 | |
611 | Printers::~Printers() |
612 | |
613 | === modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.h' |
614 | --- plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-02-01 14:56:58 +0000 |
615 | +++ plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-02-03 12:26:13 +0000 |
616 | @@ -43,12 +43,10 @@ |
617 | Q_PROPERTY(QString lastMessage READ lastMessage CONSTANT) |
618 | |
619 | public: |
620 | - explicit Printers(int printerUpdateIntervalMSecs = 5000, QObject *parent = nullptr); |
621 | + explicit Printers(QObject *parent = Q_NULLPTR); |
622 | |
623 | // Note: Printers takes ownership of backend. |
624 | - explicit Printers(PrinterBackend *backend, |
625 | - int printerUpdateIntervalMSecs = 5000, |
626 | - QObject *parent = nullptr); |
627 | + explicit Printers(PrinterBackend *backend, QObject *parent = Q_NULLPTR); |
628 | ~Printers(); |
629 | |
630 | QAbstractItemModel* allPrinters(); |
631 | |
632 | === modified file 'tests/unittests/Printers/mockbackend.h' |
633 | --- tests/unittests/Printers/mockbackend.h 2017-02-02 17:22:55 +0000 |
634 | +++ tests/unittests/Printers/mockbackend.h 2017-02-03 12:26:13 +0000 |
635 | @@ -224,10 +224,9 @@ |
636 | |
637 | virtual QList<QSharedPointer<PrinterJob>> printerGetJobs(const QString &name) override |
638 | { |
639 | - |
640 | + return QList<QSharedPointer<PrinterJob>>(); |
641 | } |
642 | |
643 | - |
644 | virtual QString printerName() const override |
645 | { |
646 | return m_printerName; |
647 | @@ -329,24 +328,40 @@ |
648 | } |
649 | |
650 | |
651 | - void mockPrinterAdded(const QString &name) |
652 | - { |
653 | - Q_EMIT printerAdded(name); |
654 | - } |
655 | - |
656 | - void mockPrinterModified(const QString &name, const bool ppdChanged) |
657 | - { |
658 | - Q_EMIT printerModified(name, ppdChanged); |
659 | - } |
660 | - |
661 | - void mockPrinterDeleted(const QString &name) |
662 | - { |
663 | - Q_EMIT printerDeleted(name); |
664 | - } |
665 | - |
666 | - void mockPrinterStateChanged(const QString &name) |
667 | - { |
668 | - Q_EMIT printerStateChanged(name); |
669 | + void mockPrinterAdded( |
670 | + const QString &text, |
671 | + const QString &printerUri, |
672 | + const QString &printerName, |
673 | + uint printerState, |
674 | + const QString &printerStateReason, |
675 | + bool acceptingJobs |
676 | + ) |
677 | + { |
678 | + Q_EMIT printerAdded(text, printerUri, printerName, printerState, printerStateReason, acceptingJobs); |
679 | + } |
680 | + |
681 | + void mockPrinterModified( |
682 | + const QString &text, |
683 | + const QString &printerUri, |
684 | + const QString &printerName, |
685 | + uint printerState, |
686 | + const QString &printerStateReason, |
687 | + bool acceptingJobs |
688 | + ) |
689 | + { |
690 | + Q_EMIT printerModified(text, printerUri, printerName, printerState, printerStateReason, acceptingJobs); |
691 | + } |
692 | + |
693 | + void mockPrinterDeleted( |
694 | + const QString &text, |
695 | + const QString &printerUri, |
696 | + const QString &printerName, |
697 | + uint printerState, |
698 | + const QString &printerStateReason, |
699 | + bool acceptingJobs |
700 | + ) |
701 | + { |
702 | + Q_EMIT printerDeleted(text, printerUri, printerName, printerState, printerStateReason, acceptingJobs); |
703 | } |
704 | |
705 | void mockDriversLoaded(const QList<PrinterDriver> &drivers) |
706 | |
707 | === modified file 'tests/unittests/Printers/tst_printerfilter.cpp' |
708 | --- tests/unittests/Printers/tst_printerfilter.cpp 2017-01-22 14:21:11 +0000 |
709 | +++ tests/unittests/Printers/tst_printerfilter.cpp 2017-02-03 12:26:13 +0000 |
710 | @@ -33,7 +33,7 @@ |
711 | void testEmptyCount() |
712 | { |
713 | QScopedPointer<PrinterBackend> backend(new MockPrinterBackend); |
714 | - PrinterModel model(backend.data(), 100); |
715 | + PrinterModel model(backend.data()); |
716 | |
717 | PrinterFilter filter; |
718 | filter.setSourceModel(&model); |
719 | @@ -42,7 +42,7 @@ |
720 | void testNonEmptyCount() |
721 | { |
722 | QScopedPointer<PrinterBackend> backend(new MockPrinterBackend); |
723 | - PrinterModel model(backend.data(), 100); |
724 | + PrinterModel model(backend.data()); |
725 | |
726 | PrinterBackend* printerABackend = new MockPrinterBackend("a-printer"); |
727 | PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer"); |
728 | @@ -53,13 +53,14 @@ |
729 | |
730 | PrinterFilter filter; |
731 | filter.setSourceModel(&model); |
732 | + ((MockPrinterBackend*) backend.data())->mockPrinterAdded("Test added printer", "", printerA.name(), 0, "", true); |
733 | |
734 | - QTRY_COMPARE_WITH_TIMEOUT(filter.count(), 2, 101); |
735 | + QCOMPARE(filter.count(), 2); |
736 | } |
737 | void testCountChanged() |
738 | { |
739 | QScopedPointer<PrinterBackend> backend(new MockPrinterBackend); |
740 | - PrinterModel model(backend.data(), 100); |
741 | + PrinterModel model(backend.data()); |
742 | |
743 | PrinterBackend* printerABackend = new MockPrinterBackend("a-printer"); |
744 | PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer"); |
745 | @@ -73,8 +74,9 @@ |
746 | |
747 | QSignalSpy modelCountSpy(&model, SIGNAL(countChanged())); |
748 | QSignalSpy filterCountSpy(&filter, SIGNAL(countChanged())); |
749 | - QTRY_COMPARE_WITH_TIMEOUT(modelCountSpy.count(), 1, 101); |
750 | - QTRY_COMPARE_WITH_TIMEOUT(filterCountSpy.count(), 1, 101); |
751 | + ((MockPrinterBackend*) backend.data())->mockPrinterAdded("Test added printer", "", printerA.name(), 0, "", true); |
752 | + QCOMPARE(modelCountSpy.count(), 1); |
753 | + QCOMPARE(filterCountSpy.count(), 1); |
754 | } |
755 | }; |
756 | |
757 | |
758 | === modified file 'tests/unittests/Printers/tst_printermodel.cpp' |
759 | --- tests/unittests/Printers/tst_printermodel.cpp 2017-01-22 14:21:11 +0000 |
760 | +++ tests/unittests/Printers/tst_printermodel.cpp 2017-02-03 12:26:13 +0000 |
761 | @@ -36,7 +36,7 @@ |
762 | void init() |
763 | { |
764 | m_backend = new MockPrinterBackend; |
765 | - m_model = new PrinterModel(m_backend, 100); |
766 | + m_model = new PrinterModel(m_backend); |
767 | } |
768 | void cleanup() |
769 | { |
770 | @@ -80,9 +80,10 @@ |
771 | |
772 | PrinterBackend* printerABackend = new MockPrinterBackend("a-printer"); |
773 | Printer* printerA = new Printer(printerABackend); |
774 | - ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA; |
775 | + getBackend()->m_availablePrinters << printerA; |
776 | + getBackend()->mockPrinterAdded("Test added printer", "", printerA->name(), 0, "", true); |
777 | |
778 | - QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 1, 500); |
779 | + QCOMPARE(m_model->count(), 1); |
780 | QCOMPARE(countSpy.count(), 1); |
781 | QCOMPARE(insertSpy.count(), 1); |
782 | |
783 | @@ -99,8 +100,10 @@ |
784 | PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer"); |
785 | Printer* printerB = new Printer(printerBBackend); |
786 | ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB; |
787 | + getBackend()->mockPrinterAdded("Test added printer", "", printerA->name(), 0, "", true); |
788 | + getBackend()->mockPrinterAdded("Test added printer", "", printerB->name(), 0, "", true); |
789 | |
790 | - QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 2, 500); |
791 | + QCOMPARE(m_model->count(), 2); |
792 | |
793 | // Setup spy and move a printer |
794 | int from = 1; |
795 | @@ -109,7 +112,10 @@ |
796 | |
797 | // Check signals were fired |
798 | QSignalSpy moveSpy(m_model, SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int))); |
799 | - QTRY_COMPARE_WITH_TIMEOUT(moveSpy.count(), 1, 500); |
800 | + |
801 | + getBackend()->mockPrinterModified("Test e.g. renamed printer", "", printerA->name(), 0, "", true); |
802 | + |
803 | + QCOMPARE(moveSpy.count(), 1); |
804 | QCOMPARE(m_model->count(), 2); |
805 | |
806 | // Check item was moved from -> to |
807 | @@ -127,14 +133,18 @@ |
808 | Printer* printerB = new Printer(printerBBackend); |
809 | ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB; |
810 | |
811 | - QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 2, 500); |
812 | + getBackend()->mockPrinterAdded("Test added printer", "", printerA->name(), 0, "", true); |
813 | + getBackend()->mockPrinterAdded("Test added printer", "", printerB->name(), 0, "", true); |
814 | + |
815 | + QCOMPARE(m_model->count(), 2); |
816 | |
817 | // Setup spy and remove a printer |
818 | QSignalSpy countSpy(m_model, SIGNAL(countChanged())); |
819 | QSignalSpy removeSpy(m_model, SIGNAL(rowsRemoved(const QModelIndex&, int, int))); |
820 | ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeLast(); |
821 | + getBackend()->mockPrinterDeleted("Test deleted printer", "", printerB->name(), 0, "", false); |
822 | |
823 | - QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 1, 500); |
824 | + QCOMPARE(m_model->count(), 1); |
825 | QCOMPARE(countSpy.count(), 1); |
826 | QCOMPARE(removeSpy.count(), 1); |
827 | |
828 | @@ -156,17 +166,20 @@ |
829 | Printer* printerD = new Printer(printerDBackend); |
830 | ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB << printerC << printerD; |
831 | |
832 | - QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 4, 500); |
833 | + getBackend()->mockPrinterAdded("Test added printer", "", printerA->name(), 0, "", true); |
834 | + |
835 | + QCOMPARE(m_model->count(), 4); |
836 | |
837 | // Setup spy and remove middle two printers |
838 | QSignalSpy countSpy(m_model, SIGNAL(countChanged())); |
839 | QSignalSpy removeSpy(m_model, SIGNAL(rowsRemoved(const QModelIndex&, int, int))); |
840 | + |
841 | ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeAt(2); |
842 | ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeAt(1); |
843 | |
844 | - // Wait until one count signal has been fired |
845 | - // (to ensure this is only one iteration of update) |
846 | - QTRY_COMPARE_WITH_TIMEOUT(countSpy.count(), 1, 500); |
847 | + getBackend()->mockPrinterDeleted("Test deleted printer", "", printerB->name(), 0, "", false); |
848 | + |
849 | + QCOMPARE(countSpy.count(), 1); |
850 | QCOMPARE(m_model->count(), 2); |
851 | QCOMPARE(removeSpy.count(), 2); |
852 | |
853 | @@ -181,6 +194,10 @@ |
854 | QCOMPARE(args.at(2).toInt(), 1); |
855 | } |
856 | private: |
857 | + MockPrinterBackend* getBackend() |
858 | + { |
859 | + return (MockPrinterBackend*) m_backend; |
860 | + } |
861 | PrinterBackend *m_backend; |
862 | PrinterModel *m_model; |
863 | }; |
864 | |
865 | === modified file 'tests/unittests/Printers/tst_printers.cpp' |
866 | --- tests/unittests/Printers/tst_printers.cpp 2017-01-27 13:52:47 +0000 |
867 | +++ tests/unittests/Printers/tst_printers.cpp 2017-02-03 12:26:13 +0000 |
868 | @@ -88,10 +88,10 @@ |
869 | PrinterBackend* backend = new MockPrinterBackend; |
870 | ((MockPrinterBackend*) backend)->m_availablePrinters = in; |
871 | |
872 | - Printers printers(backend, 100); |
873 | + Printers printers(backend); |
874 | auto all = printers.allPrinters(); |
875 | |
876 | - QTRY_COMPARE_WITH_TIMEOUT(all->rowCount(), out.size(), 101); |
877 | + QCOMPARE(all->rowCount(), out.size()); |
878 | for (int i = 0; i < all->rowCount(); i++) { |
879 | QCOMPARE( |
880 | all->data(all->index(i, 0)).toString(), |
http:// bazaar. launchpad. net/~jonas- drange/ ubuntu- settings- components/ cups-notificati ons/revision/ 223 is the revision where ALL signals are in PrinterBackend.