Merge lp:~jonas-drange/ubuntu-ui-extras/set-first-printer-as-default into lp:ubuntu-ui-extras/staging

Proposed by Jonas G. Drange
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 135
Merged at revision: 135
Proposed branch: lp:~jonas-drange/ubuntu-ui-extras/set-first-printer-as-default
Merge into: lp:ubuntu-ui-extras/staging
Diff against target: 123 lines (+38/-6)
4 files modified
modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+11/-3)
modules/Ubuntu/Components/Extras/Printers/printers/printers.h (+1/-1)
po/ubuntu-ui-extras.pot (+2/-2)
tests/unittests/Printers/tst_printers.cpp (+24/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-ui-extras/set-first-printer-as-default
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Approve
Andrew Hayzen (community) Approve
Review via email: mp+321700@code.launchpad.net

Commit message

sets a default printer on provisioning if there is none

Description of the change

sets a default printer on provisioning if there is none

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:134
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-ui-extras-staging-ci/9/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2388
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2388
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2201/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2201/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2201/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2201/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2201/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2201
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2201/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-ui-extras-staging-ci/9/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

LGTM :-)

review: Approve
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-ui-extras-staging-autoland/16/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/2403/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2403
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2215
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2215/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2215
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2215/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2215/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2215/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2215
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2215/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2215
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2215/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
135. By Jonas G. Drange

ensures that there are no races in provisioning a printer

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

The further changes LGTM :-)

review: Approve
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) :
review: Approve (continuous-integration)

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/printers/printers.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-21 14:51:38 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-04-04 10:59:10 +0000
4@@ -263,6 +263,8 @@
5 const QString &device, const QString &description,
6 const QString &location)
7 {
8+ bool setAsDefault = m_allPrinters.count() == 0;
9+
10 QString reply = m_backend->printerAdd(name, device, ppd, description,
11 location);
12 if (!reply.isEmpty()) {
13@@ -270,7 +272,7 @@
14 return false;
15 }
16
17- provisionPrinter(name);
18+ provisionPrinter(name, setAsDefault);
19
20 return true;
21 }
22@@ -281,6 +283,8 @@
23 const QString &description,
24 const QString &location)
25 {
26+ bool setAsDefault = m_allPrinters.count() == 0;
27+
28 QString reply = m_backend->printerAddWithPpd(name, device, ppdFileName,
29 description, location);
30 if (!reply.isEmpty()) {
31@@ -288,16 +292,20 @@
32 return false;
33 }
34
35- provisionPrinter(name);
36+ provisionPrinter(name, setAsDefault);
37
38 return true;
39 }
40
41-void Printers::provisionPrinter(const QString &name)
42+void Printers::provisionPrinter(const QString &name, const bool setAsDefault)
43 {
44 // We mimic what System Config Printer does here.
45 m_backend->printerSetEnabled(name, true);
46 m_backend->printerSetAcceptJobs(name, true);
47+
48+ if (setAsDefault) {
49+ setDefaultPrinterName(name);
50+ }
51 }
52
53 bool Printers::removePrinter(const QString &name)
54
55=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.h'
56--- modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-03-21 14:51:38 +0000
57+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-04-04 10:59:10 +0000
58@@ -108,7 +108,7 @@
59 void driverFilterChanged();
60
61 private:
62- void provisionPrinter(const QString &name);
63+ void provisionPrinter(const QString &name, const bool setAsDefault);
64 PrinterBackend *m_backend;
65 DeviceModel m_devices;
66 DriverModel m_drivers;
67
68=== modified file 'po/ubuntu-ui-extras.pot'
69--- po/ubuntu-ui-extras.pot 2017-03-21 14:51:38 +0000
70+++ po/ubuntu-ui-extras.pot 2017-04-04 10:59:10 +0000
71@@ -8,7 +8,7 @@
72 msgstr ""
73 "Project-Id-Version: ubuntu-ui-extras\n"
74 "Report-Msgid-Bugs-To: \n"
75-"POT-Creation-Date: 2017-03-21 15:33+0100\n"
76+"POT-Creation-Date: 2017-04-04 12:56+0200\n"
77 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
78 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
79 "Language-Team: LANGUAGE <LL@li.org>\n"
80@@ -99,7 +99,7 @@
81 msgid "Stopped"
82 msgstr ""
83
84-#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:387
85+#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:395
86 msgid "Test page"
87 msgstr ""
88
89
90=== modified file 'tests/unittests/Printers/tst_printers.cpp'
91--- tests/unittests/Printers/tst_printers.cpp 2017-03-15 17:30:21 +0000
92+++ tests/unittests/Printers/tst_printers.cpp 2017-04-04 10:59:10 +0000
93@@ -327,6 +327,30 @@
94 QList<QVariant> args = printFileSpy.takeFirst();
95 QCOMPARE(args.at(0).toString(), target);
96 }
97+
98+ /* Test that a printer is 1) enabled and 2) set to accepting jobs upon
99+ creation. Also, if the printer is the only printer, make it the default. */
100+ void testPrinterProvisioning()
101+ {
102+ MockPrinterBackend *backend = new MockPrinterBackend;
103+ Printers p(backend);
104+ p.addPrinter("printer-a", "some-ppd", "ipp://foo/bar", "", "");
105+
106+ // Create the printer, and make it appear in the printer model.
107+ MockPrinterBackend *printerBackend = new MockPrinterBackend("printer-a");
108+ auto printer = QSharedPointer<Printer>(new Printer(printerBackend));
109+ backend->mockPrinterLoaded(printer);
110+ p.loadPrinter("printer-a");
111+
112+ QVERIFY(backend->enableds.contains("printer-a"));
113+ QVERIFY(backend->printerOptions["printer-a"].value("AcceptJobs").toBool());
114+ QCOMPARE(backend->m_defaultPrinterName, (QString) "printer-a");
115+
116+ p.addPrinter("printer-b", "some-ppd", "ipp://bar/baz", "", "");
117+ QVERIFY(backend->enableds.contains("printer-b"));
118+ QVERIFY(backend->printerOptions["printer-b"].value("AcceptJobs").toBool());
119+ QCOMPARE(backend->m_defaultPrinterName, (QString) "printer-a");
120+ }
121 };
122
123 QTEST_GUILESS_MAIN(TestPrinters)

Subscribers

People subscribed via source and target branches