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

Proposed by Jonas G. Drange
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 151
Merged at revision: 152
Proposed branch: lp:~jonas-drange/ubuntu-ui-extras/printerloader-thread-affinity
Merge into: lp:~phablet-team/ubuntu-ui-extras/printer-staging
Diff against target: 65 lines (+26/-0)
3 files modified
modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp (+3/-0)
modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+1/-0)
tests/unittests/Printers/tst_printer.cpp (+22/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-ui-extras/printerloader-thread-affinity
Reviewer Review Type Date Requested Status
Andrew Hayzen (community) Approve
Review via email: mp+320355@code.launchpad.net

Commit message

corrects thread affinity for printerloaded printers, as well as any qobject children it might have

Description of the change

corrects thread affinity for printerloaded printers, as well as any qobject children it might have

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

LGTM, fixes the issue when applying the patch [0], to the examples and the tests still pass :-)

0 - http://pastebin.ubuntu.com/24214888/

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/Printers/cups/printerloader.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp 2017-02-21 10:46:29 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/cups/printerloader.cpp 2017-03-20 13:33:08 +0000
4@@ -18,6 +18,7 @@
5 #include "backend/backend_cups.h"
6 #include "printerloader.h"
7
8+#include <QApplication>
9 #include <QPrinterInfo>
10
11 class PrinterCupsBackend;
12@@ -48,6 +49,8 @@
13
14 auto p = QSharedPointer<Printer>(new Printer(backend));
15
16+ p->moveToThread(QApplication::instance()->thread());
17+
18 Q_EMIT loaded(p);
19 Q_EMIT finished();
20 }
21
22=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp'
23--- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-14 14:47:54 +0000
24+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-20 13:33:08 +0000
25@@ -29,6 +29,7 @@
26 {
27 loadAttributes();
28
29+ m_jobs.setParent(this);
30 m_jobs.filterOnPrinterName(name());
31
32 QObject::connect(m_backend, &PrinterBackend::printerStateChanged,
33
34=== modified file 'tests/unittests/Printers/tst_printer.cpp'
35--- tests/unittests/Printers/tst_printer.cpp 2017-03-10 13:15:27 +0000
36+++ tests/unittests/Printers/tst_printer.cpp 2017-03-20 13:33:08 +0000
37@@ -348,6 +348,28 @@
38 );
39 QCOMPARE(proxy->sourceModel()->objectName(), jobs.objectName());
40 }
41+
42+ /* There was a bug causing QML thread assertion to fail. The assertion
43+ requires all QObjects accessed from QML to be in the same thread as QML.
44+ For newly loaded non-proxy printers, this was not the case. This test
45+ serves as a regression test, as well as a place where we can make sure
46+ every QObject of the Printer API moves thread when the printer itself
47+ moves.
48+
49+ For POD, this is inconsequential. */
50+ void testPrinterMovesProperlyFromThread()
51+ {
52+ MockPrinterBackend *backend = new MockPrinterBackend(m_printerName);
53+
54+ Printer p(backend);
55+ QThread thread;
56+ p.moveToThread(&thread);
57+
58+ QCOMPARE(p.thread(), &thread);
59+
60+ // Ideally, all QObjects in the Printer API needs to be tested here.
61+ QCOMPARE(p.jobs()->thread(), &thread);
62+ }
63 private:
64 QString m_printerName = "my-printer";
65 MockPrinterBackend *m_backend = nullptr;

Subscribers

People subscribed via source and target branches