Merge lp:~fboucault/ubuntu-ui-extras/current_tab_visible_startup into lp:ubuntu-ui-extras

Proposed by Florian Boucault
Status: Superseded
Proposed branch: lp:~fboucault/ubuntu-ui-extras/current_tab_visible_startup
Merge into: lp:ubuntu-ui-extras
Diff against target: 366 lines (+175/-19)
10 files modified
modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+1/-0)
modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp (+6/-7)
modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+11/-3)
modules/Ubuntu/Components/Extras/Printers/printers/printers.h (+1/-1)
modules/Ubuntu/Components/Extras/Printers/structs.h (+3/-1)
modules/Ubuntu/Components/Extras/TabsBar.qml (+2/-0)
po/ubuntu-ui-extras.pot (+2/-2)
tests/unittests/Printers/tst_printer.cpp (+88/-5)
tests/unittests/Printers/tst_printerjob.cpp (+37/-0)
tests/unittests/Printers/tst_printers.cpp (+24/-0)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-extras/current_tab_visible_startup
Reviewer Review Type Date Requested Status
Andrew Hayzen Pending
Review via email: mp+321987@code.launchpad.net

This proposal has been superseded by a proposal from 2017-04-05.

Commit message

TabsBar: ensure selected tab is always visible when width changes, including at startup.

Description of the change

TabsBar: ensure selected tab is always visible when width changes, including at startup.

To post a comment you must log in.

Unmerged revisions

136. By Florian Boucault

TabsBar: ensure selected tab is always visible when width changes, including at startup.

135. By Jonas G. Drange

* sets a default printer on provisioning if there is none

134. By Andrew Hayzen

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

133. By Andrew Hayzen

* Set m_copies when using updateFrom and add test for updateFrom

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/printer.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-21 13:01:42 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-04-05 13:31:06 +0000
4@@ -410,6 +410,7 @@
5 // Note: do not use loadAttributes otherwise can cause UI block
6 m_acceptJobs = other->m_acceptJobs;
7 m_backend = other->m_backend;
8+ m_copies = other->m_copies;
9 m_defaultColorModel = other->m_defaultColorModel;
10 m_defaultPrintQuality = other->m_defaultPrintQuality;
11 m_deviceUri = other->m_deviceUri;
12
13=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp'
14--- modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-03-16 15:47:11 +0000
15+++ modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-04-05 13:31:06 +0000
16@@ -215,13 +215,9 @@
17 return;
18 }
19
20- if (jobId() > 0) {
21- loadAttributes(
22- m_backend->printerGetJobAttributes(
23- printerName(), jobId()
24- )
25- );
26- } else {
27+ // Only load the defaults if this isn't a job in the queue (one which has a
28+ // jobId) as this is when user is making a job and has changed the printer
29+ if (jobId() <= 0) {
30 setColorModel(m_printer->supportedColorModels().indexOf(m_printer->defaultColorModel()));
31 setDuplexMode(m_printer->supportedDuplexModes().indexOf(m_printer->defaultDuplexMode()));
32 setQuality(m_printer->supportedPrintQualities().indexOf(m_printer->defaultPrintQuality()));
33@@ -401,6 +397,9 @@
34 Q_EMIT printerNameChanged();
35 }
36
37+ // When the printer changes ensure we update any defaults
38+ loadDefaults();
39+
40 Q_EMIT printerChanged();
41 }
42 }
43
44=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp'
45--- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-21 14:51:38 +0000
46+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-04-05 13:31:06 +0000
47@@ -263,6 +263,8 @@
48 const QString &device, const QString &description,
49 const QString &location)
50 {
51+ bool setAsDefault = m_allPrinters.count() == 0;
52+
53 QString reply = m_backend->printerAdd(name, device, ppd, description,
54 location);
55 if (!reply.isEmpty()) {
56@@ -270,7 +272,7 @@
57 return false;
58 }
59
60- provisionPrinter(name);
61+ provisionPrinter(name, setAsDefault);
62
63 return true;
64 }
65@@ -281,6 +283,8 @@
66 const QString &description,
67 const QString &location)
68 {
69+ bool setAsDefault = m_allPrinters.count() == 0;
70+
71 QString reply = m_backend->printerAddWithPpd(name, device, ppdFileName,
72 description, location);
73 if (!reply.isEmpty()) {
74@@ -288,16 +292,20 @@
75 return false;
76 }
77
78- provisionPrinter(name);
79+ provisionPrinter(name, setAsDefault);
80
81 return true;
82 }
83
84-void Printers::provisionPrinter(const QString &name)
85+void Printers::provisionPrinter(const QString &name, const bool setAsDefault)
86 {
87 // We mimic what System Config Printer does here.
88 m_backend->printerSetEnabled(name, true);
89 m_backend->printerSetAcceptJobs(name, true);
90+
91+ if (setAsDefault) {
92+ setDefaultPrinterName(name);
93+ }
94 }
95
96 bool Printers::removePrinter(const QString &name)
97
98=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.h'
99--- modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-03-21 14:51:38 +0000
100+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.h 2017-04-05 13:31:06 +0000
101@@ -108,7 +108,7 @@
102 void driverFilterChanged();
103
104 private:
105- void provisionPrinter(const QString &name);
106+ void provisionPrinter(const QString &name, const bool setAsDefault);
107 PrinterBackend *m_backend;
108 DeviceModel m_devices;
109 DriverModel m_drivers;
110
111=== modified file 'modules/Ubuntu/Components/Extras/Printers/structs.h'
112--- modules/Ubuntu/Components/Extras/Printers/structs.h 2017-03-16 15:34:02 +0000
113+++ modules/Ubuntu/Components/Extras/Printers/structs.h 2017-04-05 13:31:06 +0000
114@@ -36,13 +36,15 @@
115
116 bool operator==(const ColorModel& a) const
117 {
118- return (name == a.name && originalOption == a.originalOption);
119+ return (name == a.name && originalOption == a.originalOption
120+ && text == a.text && colorType == a.colorType);
121 }
122 bool operator!=(const ColorModel& a) const
123 {
124 return !(*this == a);
125 }
126 void operator=(const ColorModel &m) {
127+ colorType = m.colorType;
128 name = m.name;
129 text = m.text;
130 originalOption = m.originalOption;
131
132=== modified file 'modules/Ubuntu/Components/Extras/TabsBar.qml'
133--- modules/Ubuntu/Components/Extras/TabsBar.qml 2017-01-16 15:31:24 +0000
134+++ modules/Ubuntu/Components/Extras/TabsBar.qml 2017-04-05 13:31:06 +0000
135@@ -186,6 +186,8 @@
136 UbuntuNumberAnimation { property: "x" }
137 }
138
139+ // Ensures current item stays visible when width changes
140+ onWidthChanged: tabs.positionViewAtIndex(currentIndex, ListView.Contain)
141 currentIndex: tabsBar.model.selectedIndex
142 model: tabsBar.model
143 delegate: MouseArea {
144
145=== modified file 'po/ubuntu-ui-extras.pot'
146--- po/ubuntu-ui-extras.pot 2017-03-21 14:51:38 +0000
147+++ po/ubuntu-ui-extras.pot 2017-04-05 13:31:06 +0000
148@@ -8,7 +8,7 @@
149 msgstr ""
150 "Project-Id-Version: ubuntu-ui-extras\n"
151 "Report-Msgid-Bugs-To: \n"
152-"POT-Creation-Date: 2017-03-21 15:33+0100\n"
153+"POT-Creation-Date: 2017-04-04 12:56+0200\n"
154 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
155 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
156 "Language-Team: LANGUAGE <LL@li.org>\n"
157@@ -99,7 +99,7 @@
158 msgid "Stopped"
159 msgstr ""
160
161-#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:387
162+#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:395
163 msgid "Test page"
164 msgstr ""
165
166
167=== modified file 'tests/unittests/Printers/tst_printer.cpp'
168--- tests/unittests/Printers/tst_printer.cpp 2017-03-20 13:31:55 +0000
169+++ tests/unittests/Printers/tst_printer.cpp 2017-04-05 13:31:06 +0000
170@@ -36,14 +36,17 @@
171 void init()
172 {
173 m_backend = new MockPrinterBackend(m_printerName);
174- m_instance = new Printer(m_backend);
175+ m_instance = QSharedPointer<Printer>(new Printer(m_backend));
176 }
177 void cleanup()
178 {
179- QSignalSpy destroyedSpy(m_instance, SIGNAL(destroyed(QObject*)));
180- m_instance->deleteLater();
181+ QSignalSpy destroyedSpy(m_instance.data(), SIGNAL(destroyed(QObject*)));
182+ m_instance.clear();
183 QTRY_COMPARE(destroyedSpy.count(), 1);
184- delete m_backend;
185+
186+ if (m_backend) {
187+ delete m_backend;
188+ }
189 }
190 void testName()
191 {
192@@ -370,10 +373,90 @@
193 // Ideally, all QObjects in the Printer API needs to be tested here.
194 QCOMPARE(p.jobs()->thread(), &thread);
195 }
196+
197+ void testUpdateFrom()
198+ {
199+ // Setup any variables for flipped values
200+ bool newAcceptJobs = !m_instance->acceptJobs();
201+ int newCopies = m_instance->copies() + 1;
202+ QString newDeviceUri = m_instance->deviceUri() + "/test";
203+ bool newShared = !m_instance->shared();
204+ QString newLastMessage = m_instance->lastMessage() + "test";
205+
206+ // Setup color model and quality models
207+ ColorModel colorA;
208+ colorA.text = "ColorA";
209+
210+ ColorModel defaultColorModel;
211+ defaultColorModel.text = "ColorB";
212+ QList<ColorModel> colorModels({colorA, defaultColorModel});
213+
214+ PrintQuality qualityA;
215+ qualityA.name = "QualityA";
216+
217+ PrintQuality defaultPrintQuality;
218+ defaultPrintQuality.name = "QualityB";
219+ QList<PrintQuality> qualities({qualityA, defaultPrintQuality});
220+
221+ QList<PrinterEnum::DuplexMode> duplexModes({
222+ PrinterEnum::DuplexMode::DuplexNone,
223+ PrinterEnum::DuplexMode::DuplexLongSide,
224+ PrinterEnum::DuplexMode::DuplexShortSide,
225+ PrinterEnum::DuplexMode::DuplexShortSide
226+ });
227+
228+ auto newDefaultDuplexMode = m_instance->defaultDuplexMode() == PrinterEnum::DuplexMode::DuplexNone
229+ ? PrinterEnum::DuplexMode::DuplexShortSide
230+ : PrinterEnum::DuplexMode::DuplexNone;
231+
232+ // Create a printer that has different settings to the default
233+ QString printerName = "test-printer-b";
234+
235+ MockPrinterBackend *backend = new MockPrinterBackend(printerName);
236+ backend->printerOptions[printerName].insert("AcceptJobs", newAcceptJobs);
237+ backend->printerOptions[printerName].insert("Copies", QString::number(newCopies));
238+ backend->printerOptions[printerName].insert("DefaultColorModel", QVariant::fromValue(defaultColorModel));
239+ backend->printerOptions[printerName].insert("DefaultPrintQuality", QVariant::fromValue(defaultPrintQuality));
240+ backend->printerOptions[printerName].insert(
241+ "DeviceUri", newDeviceUri);
242+ backend->printerOptions[printerName].insert("Shared", newShared);
243+ backend->printerOptions[printerName].insert(
244+ "StateMessage", newLastMessage);
245+ backend->printerOptions[printerName].insert(
246+ "SupportedColorModels", QVariant::fromValue(colorModels));
247+ backend->printerOptions[printerName].insert(
248+ "SupportedPrintQualities", QVariant::fromValue(qualities));
249+
250+ backend->m_supportedDuplexModes = duplexModes;
251+ backend->printerOptions[printerName].insert(
252+ "Duplex", Utils::duplexModeToPpdChoice(newDefaultDuplexMode));
253+
254+ QSharedPointer<Printer> p = QSharedPointer<Printer>(new Printer(backend));
255+
256+ // Update the default printer from this
257+ m_instance->updateFrom(p);
258+
259+ // Check we have the new values
260+ QCOMPARE(m_instance->acceptJobs(), newAcceptJobs);
261+ QCOMPARE(m_instance->copies(), newCopies);
262+ QCOMPARE(m_instance->defaultColorModel(), defaultColorModel);
263+ QCOMPARE(m_instance->defaultPrintQuality(), defaultPrintQuality);
264+ QCOMPARE(m_instance->deviceUri(), newDeviceUri);
265+ QCOMPARE(m_instance->shared(), newShared);
266+ QCOMPARE(m_instance->lastMessage(), newLastMessage);
267+ QCOMPARE(m_instance->supportedColorModels(), colorModels);
268+ QCOMPARE(m_instance->supportedPrintQualities(), qualities);
269+
270+ // We test that the duplexModes have changed to check that the backend
271+ // has changed, as m_backend is private we can't check directly
272+ QCOMPARE(m_instance->defaultDuplexMode(), newDefaultDuplexMode);
273+ QCOMPARE(m_instance->supportedDuplexModes(), duplexModes);
274+ }
275+
276 private:
277 QString m_printerName = "my-printer";
278 MockPrinterBackend *m_backend = nullptr;
279- Printer *m_instance = nullptr;
280+ QSharedPointer<Printer> m_instance;
281 };
282
283 QTEST_GUILESS_MAIN(TestPrinter)
284
285=== modified file 'tests/unittests/Printers/tst_printerjob.cpp'
286--- tests/unittests/Printers/tst_printerjob.cpp 2017-03-14 14:47:54 +0000
287+++ tests/unittests/Printers/tst_printerjob.cpp 2017-04-05 13:31:06 +0000
288@@ -304,6 +304,43 @@
289 QCOMPARE(m_instance->title(), title);
290 }
291
292+ void testSetPrinterLoadDefaults()
293+ {
294+ ColorModel a;
295+ a.colorType = PrinterEnum::ColorModelType::GrayType;
296+ a.text = "Gray";
297+
298+ ColorModel b;
299+ b.colorType = PrinterEnum::ColorModelType::ColorType;
300+ b.text = "RGB";
301+ QList<ColorModel> models({a, b});
302+
303+
304+ MockPrinterBackend *backend1 = new MockPrinterBackend("printer1");
305+ backend1->printerOptions["printer1"].insert("SupportedColorModels", QVariant::fromValue(models));
306+ backend1->printerOptions["printer1"].insert("DefaultColorModel", QVariant::fromValue(a));
307+ QSharedPointer<Printer> printer1 = QSharedPointer<Printer>(new Printer(backend1));
308+
309+ MockPrinterBackend *backend2 = new MockPrinterBackend("printer2");
310+ backend2->printerOptions["printer2"].insert("SupportedColorModels", QVariant::fromValue(models));
311+ backend2->printerOptions["printer2"].insert("DefaultColorModel", QVariant::fromValue(b));
312+ QSharedPointer<Printer> printer2 = QSharedPointer<Printer>(new Printer(backend2));
313+
314+ // Base case
315+ m_instance->setPrinter(printer1);
316+ qDebug() << m_instance->colorModel() << models.indexOf(a);
317+ QCOMPARE(m_instance->colorModel(), models.indexOf(a));
318+ QCOMPARE(m_instance->getColorModel().text, a.text);
319+ QCOMPARE(m_instance->colorModelType(), a.colorType);
320+
321+ // Change to a different printer and check the default updates
322+ m_instance->setPrinter(printer2);
323+ qDebug() << m_instance->colorModel() << models.indexOf(b);
324+ QCOMPARE(m_instance->colorModel(), models.indexOf(b));
325+ QCOMPARE(m_instance->getColorModel().text, b.text);
326+ QCOMPARE(m_instance->colorModelType(), b.colorType);
327+ }
328+
329 void testState()
330 {
331 QCOMPARE(m_instance->state(), PrinterEnum::JobState::Pending);
332
333=== modified file 'tests/unittests/Printers/tst_printers.cpp'
334--- tests/unittests/Printers/tst_printers.cpp 2017-03-15 17:30:21 +0000
335+++ tests/unittests/Printers/tst_printers.cpp 2017-04-05 13:31:06 +0000
336@@ -327,6 +327,30 @@
337 QList<QVariant> args = printFileSpy.takeFirst();
338 QCOMPARE(args.at(0).toString(), target);
339 }
340+
341+ /* Test that a printer is 1) enabled and 2) set to accepting jobs upon
342+ creation. Also, if the printer is the only printer, make it the default. */
343+ void testPrinterProvisioning()
344+ {
345+ MockPrinterBackend *backend = new MockPrinterBackend;
346+ Printers p(backend);
347+ p.addPrinter("printer-a", "some-ppd", "ipp://foo/bar", "", "");
348+
349+ // Create the printer, and make it appear in the printer model.
350+ MockPrinterBackend *printerBackend = new MockPrinterBackend("printer-a");
351+ auto printer = QSharedPointer<Printer>(new Printer(printerBackend));
352+ backend->mockPrinterLoaded(printer);
353+ p.loadPrinter("printer-a");
354+
355+ QVERIFY(backend->enableds.contains("printer-a"));
356+ QVERIFY(backend->printerOptions["printer-a"].value("AcceptJobs").toBool());
357+ QCOMPARE(backend->m_defaultPrinterName, (QString) "printer-a");
358+
359+ p.addPrinter("printer-b", "some-ppd", "ipp://bar/baz", "", "");
360+ QVERIFY(backend->enableds.contains("printer-b"));
361+ QVERIFY(backend->printerOptions["printer-b"].value("AcceptJobs").toBool());
362+ QCOMPARE(backend->m_defaultPrinterName, (QString) "printer-a");
363+ }
364 };
365
366 QTEST_GUILESS_MAIN(TestPrinters)

Subscribers

People subscribed via source and target branches