Merge lp:~ahayzen/ubuntu-ui-extras/fix-colorModel-no-update into lp:ubuntu-ui-extras/staging

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 135
Merged at revision: 134
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/fix-colorModel-no-update
Merge into: lp:ubuntu-ui-extras/staging
Diff against target: 99 lines (+46/-8)
3 files modified
modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp (+6/-7)
modules/Ubuntu/Components/Extras/Printers/structs.h (+3/-1)
tests/unittests/Printers/tst_printerjob.cpp (+37/-0)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/fix-colorModel-no-update
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Approve
Jonas G. Drange (community) Approve
Review via email: mp+321681@code.launchpad.net

Commit message

* Fix changing of printer not loading defaults and add a test
* Improve colorModel struct to != when name or colorModelType are different

Description of the change

* Fix changing of printer not loading defaults and add a test
* Improve colorModel struct to != when name or colorModelType are different

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

Could you clarify “loaded job” on L15?

review: Needs Information
135. By Andrew Hayzen

* Update comments

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

Updated the comment :-)

Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

This makes good sense now, and thanks for updating the comment. Also, +1 for the tests!

review: Approve
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/8/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2380
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2380
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2193/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2193/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2193/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2193/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2193/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2193
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2193/artifact/output/*zip*/output.zip

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

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/printer/printerjob.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-03-16 15:47:11 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-04-03 11:59:25 +0000
4@@ -215,13 +215,9 @@
5 return;
6 }
7
8- if (jobId() > 0) {
9- loadAttributes(
10- m_backend->printerGetJobAttributes(
11- printerName(), jobId()
12- )
13- );
14- } else {
15+ // Only load the defaults if this isn't a job in the queue (one which has a
16+ // jobId) as this is when user is making a job and has changed the printer
17+ if (jobId() <= 0) {
18 setColorModel(m_printer->supportedColorModels().indexOf(m_printer->defaultColorModel()));
19 setDuplexMode(m_printer->supportedDuplexModes().indexOf(m_printer->defaultDuplexMode()));
20 setQuality(m_printer->supportedPrintQualities().indexOf(m_printer->defaultPrintQuality()));
21@@ -401,6 +397,9 @@
22 Q_EMIT printerNameChanged();
23 }
24
25+ // When the printer changes ensure we update any defaults
26+ loadDefaults();
27+
28 Q_EMIT printerChanged();
29 }
30 }
31
32=== modified file 'modules/Ubuntu/Components/Extras/Printers/structs.h'
33--- modules/Ubuntu/Components/Extras/Printers/structs.h 2017-03-16 15:34:02 +0000
34+++ modules/Ubuntu/Components/Extras/Printers/structs.h 2017-04-03 11:59:25 +0000
35@@ -36,13 +36,15 @@
36
37 bool operator==(const ColorModel& a) const
38 {
39- return (name == a.name && originalOption == a.originalOption);
40+ return (name == a.name && originalOption == a.originalOption
41+ && text == a.text && colorType == a.colorType);
42 }
43 bool operator!=(const ColorModel& a) const
44 {
45 return !(*this == a);
46 }
47 void operator=(const ColorModel &m) {
48+ colorType = m.colorType;
49 name = m.name;
50 text = m.text;
51 originalOption = m.originalOption;
52
53=== modified file 'tests/unittests/Printers/tst_printerjob.cpp'
54--- tests/unittests/Printers/tst_printerjob.cpp 2017-03-14 14:47:54 +0000
55+++ tests/unittests/Printers/tst_printerjob.cpp 2017-04-03 11:59:25 +0000
56@@ -304,6 +304,43 @@
57 QCOMPARE(m_instance->title(), title);
58 }
59
60+ void testSetPrinterLoadDefaults()
61+ {
62+ ColorModel a;
63+ a.colorType = PrinterEnum::ColorModelType::GrayType;
64+ a.text = "Gray";
65+
66+ ColorModel b;
67+ b.colorType = PrinterEnum::ColorModelType::ColorType;
68+ b.text = "RGB";
69+ QList<ColorModel> models({a, b});
70+
71+
72+ MockPrinterBackend *backend1 = new MockPrinterBackend("printer1");
73+ backend1->printerOptions["printer1"].insert("SupportedColorModels", QVariant::fromValue(models));
74+ backend1->printerOptions["printer1"].insert("DefaultColorModel", QVariant::fromValue(a));
75+ QSharedPointer<Printer> printer1 = QSharedPointer<Printer>(new Printer(backend1));
76+
77+ MockPrinterBackend *backend2 = new MockPrinterBackend("printer2");
78+ backend2->printerOptions["printer2"].insert("SupportedColorModels", QVariant::fromValue(models));
79+ backend2->printerOptions["printer2"].insert("DefaultColorModel", QVariant::fromValue(b));
80+ QSharedPointer<Printer> printer2 = QSharedPointer<Printer>(new Printer(backend2));
81+
82+ // Base case
83+ m_instance->setPrinter(printer1);
84+ qDebug() << m_instance->colorModel() << models.indexOf(a);
85+ QCOMPARE(m_instance->colorModel(), models.indexOf(a));
86+ QCOMPARE(m_instance->getColorModel().text, a.text);
87+ QCOMPARE(m_instance->colorModelType(), a.colorType);
88+
89+ // Change to a different printer and check the default updates
90+ m_instance->setPrinter(printer2);
91+ qDebug() << m_instance->colorModel() << models.indexOf(b);
92+ QCOMPARE(m_instance->colorModel(), models.indexOf(b));
93+ QCOMPARE(m_instance->getColorModel().text, b.text);
94+ QCOMPARE(m_instance->colorModelType(), b.colorType);
95+ }
96+
97 void testState()
98 {
99 QCOMPARE(m_instance->state(), PrinterEnum::JobState::Pending);

Subscribers

People subscribed via source and target branches