Merge lp:~jonas-drange/ubuntu-ui-extras/dedupe-requests into lp:~phablet-team/ubuntu-ui-extras/printer-components

Proposed by Jonas G. Drange
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 135
Merged at revision: 134
Proposed branch: lp:~jonas-drange/ubuntu-ui-extras/dedupe-requests
Merge into: lp:~phablet-team/ubuntu-ui-extras/printer-components
Diff against target: 74 lines (+21/-1)
3 files modified
modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+13/-0)
modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h (+5/-0)
modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+3/-1)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-ui-extras/dedupe-requests
Reviewer Review Type Date Requested Status
Andrew Hayzen (community) Approve
Review via email: mp+318218@code.launchpad.net

Commit message

guards against excessive loading of printers and drivers

Description of the change

guards against excessive loading of printers and drivers

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

Looks good, one inline comment.

1) As there is only ever going to be one instance of each printerName in the list, can this not be a QSet ?

review: Needs Information
135. By Jonas G. Drange

qlist->qset

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

LGTM, prevents multiple threads loading the same printer :-)

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/backend/backend_cups.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-02-23 14:04:26 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-02-24 12:53:52 +0000
4@@ -613,6 +613,10 @@
5
6 void PrinterCupsBackend::requestPrinter(const QString &printerName)
7 {
8+ if (m_activeRequests.contains(printerName)) {
9+ return;
10+ }
11+
12 auto thread = new QThread;
13 auto loader = new PrinterLoader(printerName, m_client, m_notifier);
14 loader->moveToThread(thread);
15@@ -621,8 +625,12 @@
16 connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater()));
17 connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)),
18 this, SIGNAL(printerLoaded(QSharedPointer<Printer>)));
19+ connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)),
20+ this, SLOT(onPrinterLoaded(QSharedPointer<Printer>)));
21 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
22 thread->start();
23+
24+ m_activeRequests << printerName;
25 }
26
27 void PrinterCupsBackend::requestPrinterDrivers()
28@@ -707,3 +715,8 @@
29 return m_ppds[name];
30 }
31 }
32+
33+void PrinterCupsBackend::onPrinterLoaded(QSharedPointer<Printer> printer)
34+{
35+ m_activeRequests.remove(printer->name());
36+}
37
38=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h'
39--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-02-23 14:04:26 +0000
40+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-02-24 12:53:52 +0000
41@@ -24,6 +24,7 @@
42 #include <cups/cups.h>
43
44 #include <QPrinterInfo>
45+#include <QSet>
46
47 class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend
48 {
49@@ -126,6 +127,10 @@
50 int m_cupsSubscriptionId;
51 mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest.
52 mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd.
53+ QSet<QString> m_activeRequests;
54+
55+private Q_SLOTS:
56+ void onPrinterLoaded(QSharedPointer<Printer> printer);
57 };
58
59 #endif // USC_PRINTERS_CUPS_BACKEND_H
60
61=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp'
62--- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-02-23 14:04:26 +0000
63+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-02-24 12:53:52 +0000
64@@ -159,7 +159,9 @@
65
66 void Printers::prepareToAddPrinter()
67 {
68- m_drivers.load();
69+ if (m_drivers.rowCount() == 0) {
70+ m_drivers.load();
71+ }
72 }
73
74 bool Printers::addPrinter(const QString &name, const QString &ppd,

Subscribers

People subscribed via source and target branches