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
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-02-23 14:04:26 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-02-24 12:53:52 +0000
@@ -613,6 +613,10 @@
613613
614void PrinterCupsBackend::requestPrinter(const QString &printerName)614void PrinterCupsBackend::requestPrinter(const QString &printerName)
615{615{
616 if (m_activeRequests.contains(printerName)) {
617 return;
618 }
619
616 auto thread = new QThread;620 auto thread = new QThread;
617 auto loader = new PrinterLoader(printerName, m_client, m_notifier);621 auto loader = new PrinterLoader(printerName, m_client, m_notifier);
618 loader->moveToThread(thread);622 loader->moveToThread(thread);
@@ -621,8 +625,12 @@
621 connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater()));625 connect(loader, SIGNAL(finished()), loader, SLOT(deleteLater()));
622 connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)),626 connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)),
623 this, SIGNAL(printerLoaded(QSharedPointer<Printer>)));627 this, SIGNAL(printerLoaded(QSharedPointer<Printer>)));
628 connect(loader, SIGNAL(loaded(QSharedPointer<Printer>)),
629 this, SLOT(onPrinterLoaded(QSharedPointer<Printer>)));
624 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));630 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
625 thread->start();631 thread->start();
632
633 m_activeRequests << printerName;
626}634}
627635
628void PrinterCupsBackend::requestPrinterDrivers()636void PrinterCupsBackend::requestPrinterDrivers()
@@ -707,3 +715,8 @@
707 return m_ppds[name];715 return m_ppds[name];
708 }716 }
709}717}
718
719void PrinterCupsBackend::onPrinterLoaded(QSharedPointer<Printer> printer)
720{
721 m_activeRequests.remove(printer->name());
722}
710723
=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h'
--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-02-23 14:04:26 +0000
+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.h 2017-02-24 12:53:52 +0000
@@ -24,6 +24,7 @@
24#include <cups/cups.h>24#include <cups/cups.h>
2525
26#include <QPrinterInfo>26#include <QPrinterInfo>
27#include <QSet>
2728
28class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend29class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend
29{30{
@@ -126,6 +127,10 @@
126 int m_cupsSubscriptionId;127 int m_cupsSubscriptionId;
127 mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest.128 mutable QMap<QString, cups_dest_t*> m_dests; // Printer name, dest.
128 mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd.129 mutable QMap<QString, ppd_file_t*> m_ppds; // Printer name, ppd.
130 QSet<QString> m_activeRequests;
131
132private Q_SLOTS:
133 void onPrinterLoaded(QSharedPointer<Printer> printer);
129};134};
130135
131#endif // USC_PRINTERS_CUPS_BACKEND_H136#endif // USC_PRINTERS_CUPS_BACKEND_H
132137
=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp'
--- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-02-23 14:04:26 +0000
+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-02-24 12:53:52 +0000
@@ -159,7 +159,9 @@
159159
160void Printers::prepareToAddPrinter()160void Printers::prepareToAddPrinter()
161{161{
162 m_drivers.load();162 if (m_drivers.rowCount() == 0) {
163 m_drivers.load();
164 }
163}165}
164166
165bool Printers::addPrinter(const QString &name, const QString &ppd,167bool Printers::addPrinter(const QString &name, const QString &ppd,

Subscribers

People subscribed via source and target branches