Merge lp:~ahayzen/ubuntu-ui-extras/printer-added-ensure-proxy-printer into lp:~phablet-team/ubuntu-ui-extras/printer-staging

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 152
Merged at revision: 153
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/printer-added-ensure-proxy-printer
Merge into: lp:~phablet-team/ubuntu-ui-extras/printer-staging
Diff against target: 45 lines (+15/-11)
1 file modified
modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+15/-11)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/printer-added-ensure-proxy-printer
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+320353@code.launchpad.net

Commit message

* If printerAdded is called ensure there is always a proxy printer
* Update printerLoaded to use getPrinterByName to improve DRY

Description of the change

* If printerAdded is called ensure there is always a proxy printer
* Update printerLoaded to use getPrinterByName to improve DRY

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

This fixes the crash, and it makes sense to use a proxyprinter. Thanks!

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/models/printermodel.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-14 16:04:49 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-20 13:06:03 +0000
4@@ -64,20 +64,18 @@
5
6 void PrinterModel::printerLoaded(QSharedPointer<Printer> printer)
7 {
8- // Find and possibly replace an old printer.
9- for (int i=0; i < m_printers.count(); i++) {
10- auto oldPrinter = m_printers.at(i);
11- if (printer->name() == oldPrinter->name()) {
12- if (!oldPrinter->deepCompare(printer)) {
13- updatePrinter(oldPrinter, printer);
14- }
15+ // If there is an existing printer then get it
16+ QSharedPointer<Printer> oldPrinter = getPrinterByName(printer->name());
17
18- // We're done.
19- return;
20+ if (oldPrinter) {
21+ // Check if the existing printer needs updating
22+ if (!oldPrinter->deepCompare(printer)) {
23+ updatePrinter(oldPrinter, printer);
24 }
25+ } else {
26+ // There isn't an existing printer so add it
27+ addPrinter(printer, CountChangeSignal::Emit);
28 }
29-
30- addPrinter(printer, CountChangeSignal::Emit);
31 }
32
33 void PrinterModel::printerModified(const QString &printerName)
34@@ -98,6 +96,12 @@
35 Q_UNUSED(printerStateReason);
36 Q_UNUSED(acceptingJobs);
37
38+ // If there isn't an existing printer then add a proxy printer
39+ if (!getPrinterByName(printerName)) {
40+ auto p = QSharedPointer<Printer>(new Printer(new PrinterBackend(printerName)));
41+ addPrinter(p);
42+ }
43+
44 m_backend->requestPrinter(printerName);
45 }
46

Subscribers

People subscribed via source and target branches