Merge lp:~ahayzen/ubuntu-settings-components/add-fake-pdf-mode-and-other-fixes into lp:~phablet-team/ubuntu-settings-components/printer-components

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 212
Merged at revision: 209
Proposed branch: lp:~ahayzen/ubuntu-settings-components/add-fake-pdf-mode-and-other-fixes
Merge into: lp:~phablet-team/ubuntu-settings-components/printer-components
Diff against target: 716 lines (+365/-31)
19 files modified
examples/Printers.qml (+6/-2)
plugins/Ubuntu/Settings/Printers/CMakeLists.txt (+3/-0)
plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+28/-3)
plugins/Ubuntu/Settings/Printers/models/printermodel.h (+4/-0)
plugins/Ubuntu/Settings/Printers/printer/printer.cpp (+27/-14)
plugins/Ubuntu/Settings/Printers/printer/printer.h (+1/-1)
plugins/Ubuntu/Settings/Printers/printer/printerinfo.h (+2/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp (+39/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h (+58/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp (+5/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h (+2/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp (+91/-0)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h (+55/-0)
plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+17/-5)
plugins/Ubuntu/Settings/Printers/printers/printers.cpp (+15/-2)
plugins/Ubuntu/Settings/Printers/printers/printers.h (+2/-0)
plugins/Ubuntu/Settings/Printers/printers/printers_p.h (+1/-0)
plugins/Ubuntu/Settings/Printers/utils.h (+4/-4)
tests/unittests/Printers/mockprinterinfo.h (+5/-0)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-settings-components/add-fake-pdf-mode-and-other-fixes
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+315169@code.launchpad.net

Commit message

* Fix colorModelType not emitting when it may have changed, causing QML to get out of sync
* Add a Printers::allPrintersWithPdf option which includes a fake pdf at the bottom
* Add a PrinterInfoAllImpl which combines PrinterInfoPdfImpl and PrinterInfoImpl for listing
* Add a PrinterInfoPdfImpl which implements a fake pdf printer (just a name in the list)
* Add isPdf role to PrinterModel
* Add filterOnPdf to PrinterModel to allow for only showing pdf printers
* Force pdf printers to bottom of the PrinterModel
* Inject a fake ColorModel in PrinterPrivate::loadColorModel for pdf printers
* Change PrinterJob::setPrinterName to use PrinterInfoAllImpl for retreiving the PrinterInfo
* Improve the UI names for the Duplex modes
* Improve detection of color models so that "black" is a greyscale type
* In the example disable duplex mode when there is only None

Description of the change

* Fix colorModelType not emitting when it may have changed, causing QML to get out of sync
* Add a Printers::allPrintersWithPdf option which includes a fake pdf at the bottom
* Add a PrinterInfoAllImpl which combines PrinterInfoPdfImpl and PrinterInfoImpl for listing
* Add a PrinterInfoPdfImpl which implements a fake pdf printer (just a name in the list)
* Add isPdf role to PrinterModel
* Add filterOnPdf to PrinterModel to allow for only showing pdf printers
* Force pdf printers to bottom of the PrinterModel
* Inject a fake ColorModel in PrinterPrivate::loadColorModel for pdf printers
* Change PrinterJob::setPrinterName to use PrinterInfoAllImpl for retreiving the PrinterInfo
* Improve the UI names for the Duplex modes
* Improve detection of color models so that "black" is a greyscale type
* In the example disable duplex mode when there is only None

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

looks good, minor comment!

review: Needs Fixing
212. By Andrew Hayzen

* FIx for comment on filterOnPdf

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

Great stuff!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/Printers.qml'
2--- examples/Printers.qml 2017-01-18 16:25:02 +0000
3+++ examples/Printers.qml 2017-01-19 20:06:10 +0000
4@@ -85,11 +85,15 @@
5 left: parent.left
6 right: parent.right
7 }
8+ enabled: values.length > 1
9 text: "Duplex"
10 values: printer.supportedDuplexModes
11 onSelectedIndexChanged: printer.duplexMode = selectedIndex
12- Component.onCompleted: selectedIndex = printer.duplexMode
13- // TODO: should be disabled when duplex isn't supported
14+ Component.onCompleted: {
15+ if (enabled) {
16+ selectedIndex = printer.duplexMode
17+ }
18+ }
19 }
20
21 ListItems.ValueSelector {
22
23=== modified file 'plugins/Ubuntu/Settings/Printers/CMakeLists.txt'
24--- plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-01-17 13:57:10 +0000
25+++ plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-01-19 20:06:10 +0000
26@@ -15,10 +15,13 @@
27 cups/cupspkhelper.cpp
28 models/printermodel.cpp
29 printer/printer.cpp
30+ printer/printerinfo_allimpl.cpp
31+ printer/printerinfo_pdfimpl.cpp
32 printer/printerinfo_impl.cpp
33 printer/printerjob.cpp
34 printers/printers.cpp
35 plugin.cpp
36+ utils.h
37 )
38
39 target_link_libraries(UbuntuSettingsPrintersQml
40
41=== modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp'
42--- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-19 13:56:37 +0000
43+++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-19 20:06:10 +0000
44@@ -19,7 +19,7 @@
45 #include "cups/cupsfacade_impl.h"
46 #include "models/printermodel.h"
47 #include "models/printermodel_p.h"
48-#include "printer/printerinfo_impl.h"
49+#include "printer/printerinfo_allimpl.h"
50
51 #include <QDebug>
52
53@@ -41,7 +41,7 @@
54
55 PrinterModelPrivate::PrinterModelPrivate(PrinterModel *q)
56 {
57- this->info = new PrinterInfoImpl;
58+ this->info = new PrinterInfoAllImpl;
59 this->cups = new CupsFacadeImpl;
60 }
61
62@@ -225,6 +225,9 @@
63 // TODO: figure out how crazy this is...
64 ret = QVariant::fromValue(printer.data());
65 break;
66+ case IsPdfRole:
67+ ret = printer->isPdf();
68+ break;
69 // case LastStateMessageRole:
70 // ret = printer->lastStateMessage();
71 // break;
72@@ -301,6 +304,7 @@
73 names[UsersRole] = "users";
74 names[StateRole] = "state";
75 names[PrinterRole] = "printer";
76+ names[IsPdfRole] = "isPdf";
77 names[LastStateMessageRole] = "lastStateMessage";
78 }
79
80@@ -379,6 +383,12 @@
81 Q_UNUSED(recent);
82 }
83
84+void PrinterFilter::filterOnPdf(const bool pdf)
85+{
86+ m_pdfEnabled = true;
87+ m_pdf = pdf;
88+}
89+
90 bool PrinterFilter::filterAcceptsRow(int sourceRow,
91 const QModelIndex &sourceParent) const
92 {
93@@ -389,6 +399,13 @@
94 // TODO: implement recent
95 }
96
97+ // If pdfEnabled is false we only want real printers
98+ if (accepts && m_pdfEnabled) {
99+ bool isPdf = (bool) childIndex.model()->data(
100+ childIndex, PrinterModel::IsPdfRole).toBool();
101+ accepts = isPdf == m_pdf;
102+ }
103+
104 if (accepts && m_stateEnabled) {
105 const PrinterEnum::State state =
106 (PrinterEnum::State) childIndex.model()->data(
107@@ -405,7 +422,15 @@
108 QVariant leftData = sourceModel()->data(left, sortRole());
109 QVariant rightData = sourceModel()->data(right, sortRole());
110 if ((QMetaType::Type) leftData.type() == QMetaType::Bool) {
111- return leftData.toInt() < rightData.toInt();
112+ // FIXME: hack to put Pdf printer at the bottom
113+ if (leftData.toInt() == rightData.toInt()) {
114+ int leftPdf = sourceModel()->data(left, PrinterModel::IsPdfRole).toInt();
115+ int rightPdf = sourceModel()->data(right, PrinterModel::IsPdfRole).toInt();
116+
117+ return leftPdf > rightPdf;
118+ } else {
119+ return leftData.toInt() < rightData.toInt();
120+ }
121 } else {
122 return leftData < rightData;
123 }
124
125=== modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.h'
126--- plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-19 13:56:37 +0000
127+++ plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-19 20:06:10 +0000
128@@ -63,6 +63,7 @@
129 StateRole,
130 PrinterRole,
131 LastStateMessageRole,
132+ IsPdfRole,
133 LastRole = LastStateMessageRole,
134 };
135
136@@ -100,6 +101,7 @@
137
138 void filterOnState(const PrinterEnum::State &state);
139 void filterOnRecent(const bool recent);
140+ void filterOnPdf(const bool pdf);
141
142 int count() const;
143 protected:
144@@ -120,6 +122,8 @@
145 bool m_stateEnabled = false;
146 bool m_recent = false;
147 bool m_recentEnabled = false;
148+ bool m_pdfEnabled = false;
149+ bool m_pdf = false;
150 };
151
152 #endif // USC_PRINTER_MODEL_H
153
154=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.cpp'
155--- plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-19 11:42:11 +0000
156+++ plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-19 20:06:10 +0000
157@@ -58,15 +58,27 @@
158
159 void PrinterPrivate::loadColorModel()
160 {
161- QStringList opts({"DefaultColorModel"});
162- auto name = this->info->printerName();
163- auto vals = this->cups->printerGetOptions(name, opts);
164- m_defaultColorModel = vals["DefaultColorModel"].value<ColorModel>();
165-
166- m_supportedColorModels = this->cups->printerGetSupportedColorModels(name);
167-
168- if (m_supportedColorModels.size() == 0) {
169- m_supportedColorModels.append(m_defaultColorModel);
170+ if (!this->info->isPdf()) {
171+ QStringList opts({"DefaultColorModel"});
172+ auto name = this->info->printerName();
173+ auto vals = this->cups->printerGetOptions(name, opts);
174+ m_defaultColorModel = vals["DefaultColorModel"].value<ColorModel>();
175+
176+ m_supportedColorModels = this->cups->printerGetSupportedColorModels(name);
177+
178+ if (m_supportedColorModels.size() == 0) {
179+ m_supportedColorModels.append(m_defaultColorModel);
180+ }
181+ } else {
182+ ColorModel rgb = ColorModel();
183+ rgb.colorOrganization = PrinterEnum::ColorOrganization::UnknownOrganization;
184+ rgb.colorSpace = PrinterEnum::ColorSpace::RGBSpace;
185+ rgb.colorType = PrinterEnum::ColorModelType::ColorType;
186+ rgb.name = "RGB";
187+ rgb.text = "Color";
188+
189+ m_defaultColorModel = rgb;
190+ m_supportedColorModels = QList<ColorModel>{rgb};
191 }
192 }
193
194@@ -82,11 +94,6 @@
195 return d->m_supportedColorModels;
196 }
197
198-int Printer::copies() const
199-{
200-
201-}
202-
203 QList<PrinterEnum::DuplexMode> Printer::supportedDuplexModes() const
204 {
205 Q_D(const Printer);
206@@ -190,6 +197,12 @@
207 return name() == d->info->defaultPrinterName();
208 }
209
210+bool Printer::isPdf()
211+{
212+ Q_D(Printer);
213+ return d->info->isPdf();
214+}
215+
216 void Printer::setDefaultColorModel(const ColorModel &colorModel)
217 {
218 Q_D(Printer);
219
220=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.h'
221--- plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-19 11:42:11 +0000
222+++ plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-19 20:06:10 +0000
223@@ -64,7 +64,6 @@
224 bool enabled() const;
225 ColorModel defaultColorModel() const;
226 QList<ColorModel> supportedColorModels() const;
227- int copies() const;
228 QList<PrinterEnum::DuplexMode> supportedDuplexModes() const;
229 QStringList supportedDuplexStrings() const;
230 PrinterEnum::DuplexMode defaultDuplexMode() const;
231@@ -79,6 +78,7 @@
232 PrinterEnum::State state() const;
233 QString lastStateMessage() const;
234 bool isDefault();
235+ bool isPdf();
236
237 void setAccessControl(const PrinterEnum::AccessControl &accessControl);
238 void setDefaultColorModel(const ColorModel &colorModel);
239
240=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo.h'
241--- plugins/Ubuntu/Settings/Printers/printer/printerinfo.h 2017-01-19 11:42:11 +0000
242+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo.h 2017-01-19 20:06:10 +0000
243@@ -54,6 +54,8 @@
244 virtual PrinterInfo* printerInfo(const QString &printerName) = 0;
245 virtual QString defaultPrinterName() = 0;
246
247+ virtual bool isPdf() const = 0;
248+
249 virtual void refresh() = 0;
250 protected:
251 const QString m_printerName;
252
253=== added file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp'
254--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp 1970-01-01 00:00:00 +0000
255+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp 2017-01-19 20:06:10 +0000
256@@ -0,0 +1,39 @@
257+/*
258+ * Copyright (C) 2017 Canonical, Ltd.
259+ *
260+ * This program is free software; you can redistribute it and/or modify
261+ * it under the terms of the GNU Lesser General Public License as published by
262+ * the Free Software Foundation; version 3.
263+ *
264+ * This program is distributed in the hope that it will be useful,
265+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
266+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
267+ * GNU Lesser General Public License for more details.
268+ *
269+ * You should have received a copy of the GNU Lesser General Public License
270+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
271+ */
272+
273+#include "printer/printerinfo_allimpl.h"
274+
275+#include "printer/printerinfo_impl.h"
276+#include "printer/printerinfo_pdfimpl.h"
277+
278+PrinterInfoAllImpl::PrinterInfoAllImpl(const QString &name) : PrinterInfo(name)
279+{
280+ m_pdf_printers = new PrinterInfoPdfImpl();
281+ m_qt_printers = new PrinterInfoImpl();
282+}
283+
284+PrinterInfoAllImpl::~PrinterInfoAllImpl()
285+{
286+
287+}
288+
289+QList<PrinterInfo*> PrinterInfoAllImpl::availablePrinters()
290+{
291+ QList<PrinterInfo*> list;
292+ list += m_pdf_printers->availablePrinters();
293+ list += m_qt_printers->availablePrinters();
294+ return list;
295+}
296
297=== added file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h'
298--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h 1970-01-01 00:00:00 +0000
299+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h 2017-01-19 20:06:10 +0000
300@@ -0,0 +1,58 @@
301+/*
302+ * Copyright (C) 2017 Canonical, Ltd.
303+ *
304+ * This program is free software; you can redistribute it and/or modify
305+ * it under the terms of the GNU Lesser General Public License as published by
306+ * the Free Software Foundation; version 3.
307+ *
308+ * This program is distributed in the hope that it will be useful,
309+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
310+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
311+ * GNU Lesser General Public License for more details.
312+ *
313+ * You should have received a copy of the GNU Lesser General Public License
314+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
315+ */
316+
317+#ifndef USC_PRINTERS_PRINTERINFO_ALLIMPL_H
318+#define USC_PRINTERS_PRINTERINFO_ALLIMPL_H
319+
320+#include "printer/printerinfo.h"
321+
322+class PrinterInfoAllImpl : public PrinterInfo
323+{
324+public:
325+ explicit PrinterInfoAllImpl(const QString &name = QString::null);
326+ virtual ~PrinterInfoAllImpl() override;
327+
328+ virtual bool holdsDefinition() const override {}
329+
330+ virtual QString printerName() const override {}
331+ virtual QString description() const override {}
332+ virtual QString location() const override {}
333+ virtual QString makeAndModel() const override {}
334+
335+ virtual PrinterEnum::State state() const override {}
336+ virtual QList<QPageSize> supportedPageSizes() const override {}
337+ virtual QPageSize defaultPageSize() const override {}
338+ virtual bool supportsCustomPageSizes() const override {}
339+
340+ virtual QPageSize minimumPhysicalPageSize() const override {}
341+ virtual QPageSize maximumPhysicalPageSize() const override {}
342+ virtual QList<int> supportedResolutions() const override {}
343+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const override {}
344+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override {}
345+ virtual QList<PrinterInfo*> availablePrinters() override;
346+ virtual QStringList availablePrinterNames() override {}
347+ virtual PrinterInfo* printerInfo(const QString &printerName) override {}
348+ virtual QString defaultPrinterName() override {}
349+
350+ virtual bool isPdf() const override {}
351+
352+ virtual void refresh() override {}
353+private:
354+ PrinterInfo *m_pdf_printers;
355+ PrinterInfo *m_qt_printers;
356+};
357+
358+#endif // USC_PRINTERS_PRINTERINFO_ALLIMPL_H
359
360=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp'
361--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp 2017-01-19 12:36:39 +0000
362+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp 2017-01-19 20:06:10 +0000
363@@ -137,6 +137,11 @@
364 return QPrinterInfo::defaultPrinterName();
365 }
366
367+bool PrinterInfoImpl::isPdf() const
368+{
369+ return false;
370+}
371+
372 void PrinterInfoImpl::refresh()
373 {
374 if (m_printerName.isEmpty()) {
375
376=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h'
377--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h 2017-01-19 11:42:11 +0000
378+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h 2017-01-19 20:06:10 +0000
379@@ -51,6 +51,8 @@
380 virtual PrinterInfo* printerInfo(const QString &printerName) override;
381 virtual QString defaultPrinterName() override;
382
383+ virtual bool isPdf() const override;
384+
385 virtual void refresh() override;
386
387 private:
388
389=== added file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp'
390--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp 1970-01-01 00:00:00 +0000
391+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp 2017-01-19 20:06:10 +0000
392@@ -0,0 +1,91 @@
393+/*
394+ * Copyright (C) 2017 Canonical, Ltd.
395+ *
396+ * This program is free software; you can redistribute it and/or modify
397+ * it under the terms of the GNU Lesser General Public License as published by
398+ * the Free Software Foundation; version 3.
399+ *
400+ * This program is distributed in the hope that it will be useful,
401+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
402+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
403+ * GNU Lesser General Public License for more details.
404+ *
405+ * You should have received a copy of the GNU Lesser General Public License
406+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
407+ */
408+
409+#include "printer/printerinfo_pdfimpl.h"
410+
411+#include <QPageSize>
412+
413+PrinterInfoPdfImpl::PrinterInfoPdfImpl(const QString &name) : PrinterInfo(name)
414+{
415+
416+}
417+
418+PrinterInfoPdfImpl::~PrinterInfoPdfImpl()
419+{
420+
421+}
422+
423+QList<PrinterInfo*> PrinterInfoPdfImpl::availablePrinters()
424+{
425+ QList<PrinterInfo*> list;
426+ list.append(new PrinterInfoPdfImpl("Create PDF"));
427+ return list;
428+}
429+
430+PrinterEnum::DuplexMode PrinterInfoPdfImpl::defaultDuplexMode() const
431+{
432+ return PrinterEnum::DuplexMode::DuplexNone;
433+}
434+
435+QPageSize PrinterInfoPdfImpl::defaultPageSize() const
436+{
437+ return QPageSize(QPageSize::A4);
438+}
439+
440+QString PrinterInfoPdfImpl::defaultPrinterName()
441+{
442+ return "";
443+}
444+
445+QString PrinterInfoPdfImpl::description() const
446+{
447+ return QStringLiteral("");
448+}
449+
450+bool PrinterInfoPdfImpl::holdsDefinition() const
451+{
452+ return true;
453+}
454+
455+bool PrinterInfoPdfImpl::isPdf() const
456+{
457+ return true;
458+}
459+
460+QString PrinterInfoPdfImpl::location() const
461+{
462+ return QStringLiteral("");
463+}
464+
465+QString PrinterInfoPdfImpl::makeAndModel() const
466+{
467+ return QStringLiteral("");
468+}
469+
470+QString PrinterInfoPdfImpl::printerName() const
471+{
472+ return m_printerName;
473+}
474+
475+QList<PrinterEnum::DuplexMode> PrinterInfoPdfImpl::supportedDuplexModes() const
476+{
477+ return QList<PrinterEnum::DuplexMode>{PrinterEnum::DuplexMode::DuplexNone};
478+}
479+
480+QList<QPageSize> PrinterInfoPdfImpl::supportedPageSizes() const
481+{
482+ return QList<QPageSize>{QPageSize(QPageSize::A4)};
483+}
484
485=== added file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h'
486--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h 1970-01-01 00:00:00 +0000
487+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h 2017-01-19 20:06:10 +0000
488@@ -0,0 +1,55 @@
489+/*
490+ * Copyright (C) 2017 Canonical, Ltd.
491+ *
492+ * This program is free software; you can redistribute it and/or modify
493+ * it under the terms of the GNU Lesser General Public License as published by
494+ * the Free Software Foundation; version 3.
495+ *
496+ * This program is distributed in the hope that it will be useful,
497+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
498+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
499+ * GNU Lesser General Public License for more details.
500+ *
501+ * You should have received a copy of the GNU Lesser General Public License
502+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
503+ */
504+
505+#ifndef USC_PRINTERS_PRINTERINFO_PDFIMPL_H
506+#define USC_PRINTERS_PRINTERINFO_PDFIMPL_H
507+
508+#include "printer/printerinfo.h"
509+
510+class PrinterInfoPdfImpl : public PrinterInfo
511+{
512+public:
513+ explicit PrinterInfoPdfImpl(const QString &name = QString::null);
514+ virtual ~PrinterInfoPdfImpl() override;
515+
516+ virtual bool holdsDefinition() const override;
517+
518+ virtual QString printerName() const override;
519+ virtual QString description() const override;
520+ virtual QString location() const override;
521+ virtual QString makeAndModel() const override;
522+
523+ virtual PrinterEnum::State state() const override {}
524+ virtual QList<QPageSize> supportedPageSizes() const override;
525+ virtual QPageSize defaultPageSize() const override;
526+ virtual bool supportsCustomPageSizes() const override {}
527+
528+ virtual QPageSize minimumPhysicalPageSize() const override {}
529+ virtual QPageSize maximumPhysicalPageSize() const override {}
530+ virtual QList<int> supportedResolutions() const override {}
531+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const override;
532+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override;
533+ virtual QList<PrinterInfo*> availablePrinters() override;
534+ virtual QStringList availablePrinterNames() override {}
535+ virtual PrinterInfo* printerInfo(const QString &printerName) override {}
536+ virtual QString defaultPrinterName() override;
537+
538+ virtual bool isPdf() const override;
539+
540+ virtual void refresh() override {}
541+};
542+
543+#endif // USC_PRINTERS_PRINTERINFO_PDFIMPL_H
544
545=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp'
546--- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-18 14:35:30 +0000
547+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-19 20:06:10 +0000
548@@ -19,7 +19,7 @@
549 #include "cups/cupsfacade_impl.h"
550 #include "models/printermodel.h"
551 #include "printer/printerjob.h"
552-#include "printer/printerinfo_impl.h"
553+#include "printer/printerinfo_allimpl.h"
554
555 PrinterJob::PrinterJob(QObject *parent)
556 : QObject(parent)
557@@ -168,8 +168,13 @@
558 m_color_model = colorModel;
559
560 Q_EMIT colorModelChanged();
561- Q_EMIT colorModelTypeChanged();
562 }
563+
564+ // Always emit colorModeType changed, as the underlying model could have
565+ // changed but the int maybe the same
566+ // eg if it was RGB, KGray and m_color_model was 1, then changing to
567+ // KGray, RGB with m_color_model as 1, results in no change but colorModelType does.
568+ Q_EMIT colorModelTypeChanged();
569 }
570
571 void PrinterJob::setCopies(const int copies)
572@@ -217,9 +222,16 @@
573 void PrinterJob::setPrinterName(const QString &printerName)
574 {
575 if (m_printer_name != printerName) {
576- PrinterInfo *info = new PrinterInfoImpl(printerName);
577-
578- if (info->holdsDefinition()) {
579+ PrinterInfo *printers = new PrinterInfoAllImpl();
580+ PrinterInfo *info = Q_NULLPTR;
581+
582+ Q_FOREACH(PrinterInfo *printer, printers->availablePrinters()) {
583+ if (printer->printerName() == printerName) {
584+ info = printer;
585+ }
586+ }
587+
588+ if (info && info->holdsDefinition()) {
589 m_printer_name = printerName;
590 m_printer = new Printer(info, m_cups);
591 loadDefaults();
592
593=== modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.cpp'
594--- plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-01-18 16:18:40 +0000
595+++ plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-01-19 20:06:10 +0000
596@@ -15,7 +15,7 @@
597 */
598
599 #include "cups/cupsfacade_impl.h"
600-#include "printer/printerinfo_impl.h"
601+#include "printer/printerinfo_allimpl.h"
602 #include "printers/printers.h"
603 #include "printers/printers_p.h"
604
605@@ -39,7 +39,7 @@
606 }
607
608 PrintersPrivate::PrintersPrivate(Printers *q, int printerUpdateIntervalMSecs)
609- : PrintersPrivate(q, new PrinterInfoImpl, new CupsFacadeImpl,
610+ : PrintersPrivate(q, new PrinterInfoAllImpl, new CupsFacadeImpl,
611 printerUpdateIntervalMSecs)
612 {
613 }
614@@ -54,7 +54,12 @@
615
616 allPrinters.setSourceModel(&model);
617 allPrinters.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
618+ allPrinters.filterOnPdf(false);
619 allPrinters.sort(0, Qt::DescendingOrder);
620+
621+ allPrintersWithPdf.setSourceModel(&model);
622+ allPrintersWithPdf.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
623+ allPrintersWithPdf.sort(0, Qt::DescendingOrder);
624 }
625
626 PrintersPrivate::~PrintersPrivate()
627@@ -71,6 +76,14 @@
628 return ret;
629 }
630
631+QAbstractItemModel* Printers::allPrintersWithPdf()
632+{
633+ Q_D(Printers);
634+ auto ret = &d->allPrintersWithPdf;
635+ QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
636+ return ret;
637+}
638+
639 QAbstractItemModel* Printers::recentPrinters()
640 {
641
642
643=== modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.h'
644--- plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-01-18 16:18:40 +0000
645+++ plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-01-19 20:06:10 +0000
646@@ -37,6 +37,7 @@
647 Q_OBJECT
648 Q_DECLARE_PRIVATE(Printers)
649 Q_PROPERTY(QAbstractItemModel* allPrinters READ allPrinters CONSTANT)
650+ Q_PROPERTY(QAbstractItemModel* allPrintersWithPdf READ allPrintersWithPdf CONSTANT)
651 Q_PROPERTY(QAbstractItemModel* recentPrinters READ recentPrinters CONSTANT)
652 Q_PROPERTY(QAbstractItemModel* printJobs READ printJobs CONSTANT)
653 Q_PROPERTY(QString defaultPrinterName READ defaultPrinterName WRITE setDefaultPrinterName NOTIFY defaultPrinterNameChanged)
654@@ -53,6 +54,7 @@
655 ~Printers();
656
657 QAbstractItemModel* allPrinters();
658+ QAbstractItemModel* allPrintersWithPdf();
659 QAbstractItemModel* recentPrinters();
660 QAbstractItemModel* printJobs();
661 QString defaultPrinterName() const;
662
663=== modified file 'plugins/Ubuntu/Settings/Printers/printers/printers_p.h'
664--- plugins/Ubuntu/Settings/Printers/printers/printers_p.h 2017-01-18 16:18:40 +0000
665+++ plugins/Ubuntu/Settings/Printers/printers/printers_p.h 2017-01-19 20:06:10 +0000
666@@ -32,6 +32,7 @@
667 PrinterInfo *info;
668 PrinterModel model;
669 PrinterFilter allPrinters;
670+ PrinterFilter allPrintersWithPdf;
671 PrinterFilter recentPrinters;
672 };
673
674
675=== modified file 'plugins/Ubuntu/Settings/Printers/utils.h'
676--- plugins/Ubuntu/Settings/Printers/utils.h 2017-01-18 15:22:02 +0000
677+++ plugins/Ubuntu/Settings/Printers/utils.h 2017-01-19 20:06:10 +0000
678@@ -55,11 +55,11 @@
679 // TODO: translate
680 switch (mode) {
681 case PrinterEnum::DuplexMode::DuplexNone:
682- return "None";
683+ return "One Sided";
684 case PrinterEnum::DuplexMode::DuplexShortSide:
685- return "Short edge (flip)";
686+ return "Short Edge (Flip)";
687 case PrinterEnum::DuplexMode::DuplexLongSide:
688- return "Long edge (standard)";
689+ return "Long Edge (Standard)";
690 }
691 }
692
693@@ -111,7 +111,7 @@
694 }
695 }
696
697- if (ret.name.contains("Gray")) {
698+ if (ret.name.contains("Gray") || ret.name.contains("Black")) {
699 ret.colorType = PrinterEnum::ColorModelType::GrayType;
700 } else {
701 ret.colorType = PrinterEnum::ColorModelType::ColorType;
702
703=== modified file 'tests/unittests/Printers/mockprinterinfo.h'
704--- tests/unittests/Printers/mockprinterinfo.h 2017-01-19 11:42:11 +0000
705+++ tests/unittests/Printers/mockprinterinfo.h 2017-01-19 20:06:10 +0000
706@@ -129,6 +129,11 @@
707 return m_defaultPrinterName;
708 }
709
710+ virtual bool isPdf() const override
711+ {
712+ return false;
713+ }
714+
715 virtual void refresh() override
716 {
717

Subscribers

People subscribed via source and target branches