Merge lp:~jonas-drange/ubuntu-settings-components/printerbackend into lp:~phablet-team/ubuntu-settings-components/printer-components

Proposed by Jonas G. Drange
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 221
Merged at revision: 212
Proposed branch: lp:~jonas-drange/ubuntu-settings-components/printerbackend
Merge into: lp:~phablet-team/ubuntu-settings-components/printer-components
Diff against target: 4434 lines (+1938/-1352)
36 files modified
examples/Printers.qml (+1/-1)
plugins/Ubuntu/Settings/Printers/CMakeLists.txt (+5/-6)
plugins/Ubuntu/Settings/Printers/backend/backend.cpp (+291/-0)
plugins/Ubuntu/Settings/Printers/backend/backend.h (+153/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp (+317/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_cups.h (+130/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_pdf.cpp (+124/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_pdf.h (+53/-0)
plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp (+82/-86)
plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h (+59/-61)
plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h (+0/-98)
plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+52/-62)
plugins/Ubuntu/Settings/Printers/models/printermodel.h (+10/-7)
plugins/Ubuntu/Settings/Printers/models/printermodel_p.h (+0/-35)
plugins/Ubuntu/Settings/Printers/printer/printer.cpp (+49/-113)
plugins/Ubuntu/Settings/Printers/printer/printer.h (+13/-22)
plugins/Ubuntu/Settings/Printers/printer/printer_p.h (+0/-41)
plugins/Ubuntu/Settings/Printers/printer/printerinfo.h (+0/-67)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp (+0/-39)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h (+0/-58)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp (+0/-152)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h (+0/-62)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp (+0/-91)
plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h (+0/-55)
plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+27/-40)
plugins/Ubuntu/Settings/Printers/printer/printerjob.h (+5/-3)
plugins/Ubuntu/Settings/Printers/printers/printers.cpp (+19/-42)
plugins/Ubuntu/Settings/Printers/printers/printers.h (+9/-7)
plugins/Ubuntu/Settings/Printers/printers/printers_p.h (+0/-39)
tests/unittests/Printers/CMakeLists.txt (+1/-2)
tests/unittests/Printers/mockbackend.h (+375/-0)
tests/unittests/Printers/tst_printer.cpp (+52/-43)
tests/unittests/Printers/tst_printerfilter.cpp (+22/-23)
tests/unittests/Printers/tst_printerjob.cpp (+11/-14)
tests/unittests/Printers/tst_printermodel.cpp (+46/-47)
tests/unittests/Printers/tst_printers.cpp (+32/-36)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-settings-components/printerbackend
Reviewer Review Type Date Requested Status
Andrew Hayzen (community) Approve
Review via email: mp+315317@code.launchpad.net

Commit message

* Rewrites Printer, PrinterJob, PrinterModel to all use a new backend.
* Adds new backend that bridges PDF and Cups implementations.
* Drops PIMPL idiom since we're not going to export C++ headers anyway.
* Drops most bridge patterns in classes that are now implementation details (QPrinterInfo, CupsFacade).
* Tries to deal with some RAII issues.

To post a comment you must log in.
220. By Jonas G. Drange

improves RAII story

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

Seems the ColorModelType in PrinterJob was broken in a previous branch.

Could you update PrinterJob::getColorModel() to this http://pastebin.ubuntu.com/23851653/ otherwise I've found that the ColorModeType remains UnknownType.

Other than this, I've not found any other regressions in the printing-app yet.

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

3 minor inline comments from QtCreator

1x Q_ENUMS had a trailing semi-colon
2x Q_SLOT instead of Q_SLOTS

review: Needs Fixing
221. By Jonas G. Drange

addresses all of Andrew's comments

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

LGTM, fixes the issues I was having. As discussed we may split up the PrinterBackend later, but it is fine for now.

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-20 12:08:00 +0000
3+++ examples/Printers.qml 2017-01-23 14:09:24 +0000
4@@ -159,7 +159,7 @@
5 ListView {
6 id: printerList
7 anchors { fill: parent }
8- model: Printers.allPrinters
9+ model: Printers.allPrintersWithPdf
10 delegate: ListItem {
11 height: modelLayout.height + (divider.visible ? divider.height : 0)
12 ListItemLayout {
13
14=== modified file 'plugins/Ubuntu/Settings/Printers/CMakeLists.txt'
15--- plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-01-19 17:59:17 +0000
16+++ plugins/Ubuntu/Settings/Printers/CMakeLists.txt 2017-01-23 14:09:24 +0000
17@@ -9,15 +9,14 @@
18 find_package(Qt5Qml REQUIRED)
19
20 add_library(UbuntuSettingsPrintersQml SHARED
21+ backend/backend.cpp
22+ backend/backend_cups.cpp
23+ backend/backend_pdf.cpp
24+ cups/cupsfacade.cpp
25+ cups/cupspkhelper.cpp
26 enums.h
27- cups/cupsfacade.h
28- cups/cupsfacade_impl.cpp
29- cups/cupspkhelper.cpp
30 models/printermodel.cpp
31 printer/printer.cpp
32- printer/printerinfo_allimpl.cpp
33- printer/printerinfo_pdfimpl.cpp
34- printer/printerinfo_impl.cpp
35 printer/printerjob.cpp
36 printers/printers.cpp
37 plugin.cpp
38
39=== added directory 'plugins/Ubuntu/Settings/Printers/backend'
40=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend.cpp'
41--- plugins/Ubuntu/Settings/Printers/backend/backend.cpp 1970-01-01 00:00:00 +0000
42+++ plugins/Ubuntu/Settings/Printers/backend/backend.cpp 2017-01-23 14:09:24 +0000
43@@ -0,0 +1,291 @@
44+/*
45+ * Copyright (C) 2017 Canonical, Ltd.
46+ *
47+ * This program is free software; you can redistribute it and/or modify
48+ * it under the terms of the GNU Lesser General Public License as published by
49+ * the Free Software Foundation; version 3.
50+ *
51+ * This program is distributed in the hope that it will be useful,
52+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
53+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+ * GNU Lesser General Public License for more details.
55+ *
56+ * You should have received a copy of the GNU Lesser General Public License
57+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
58+ */
59+
60+#include "backend/backend.h"
61+
62+PrinterBackend::PrinterBackend(QObject *parent)
63+ : QObject(parent)
64+{
65+}
66+
67+PrinterBackend::PrinterBackend(const QString &printerName, QObject *parent)
68+ : QObject(parent)
69+ , m_printerName(printerName)
70+{
71+}
72+
73+PrinterBackend::~PrinterBackend()
74+{
75+}
76+
77+bool PrinterBackend::holdsDefinition() const
78+{
79+ return false;
80+}
81+
82+QString PrinterBackend::printerAdd(const QString &name,
83+ const QUrl &uri,
84+ const QUrl &ppdFile,
85+ const QString &info,
86+ const QString &location)
87+{
88+ return QString();
89+}
90+
91+QString PrinterBackend::printerAddWithPpd(const QString &name,
92+ const QUrl &uri,
93+ const QString &ppdFileName,
94+ const QString &info,
95+ const QString &location)
96+{
97+ return QString();
98+}
99+
100+QString PrinterBackend::printerDelete(const QString &name)
101+{
102+ return QString();
103+}
104+
105+QString PrinterBackend::printerSetEnabled(const QString &name,
106+ const bool enabled)
107+{
108+ return QString();
109+}
110+
111+QString PrinterBackend::printerSetAcceptJobs(
112+ const QString &name,
113+ const bool enabled,
114+ const QString &reason)
115+{
116+ return QString();
117+}
118+
119+QString PrinterBackend::printerSetInfo(const QString &name,
120+ const QString &info)
121+{
122+ return QString();
123+}
124+
125+QString PrinterBackend::printerSetLocation(const QString &name,
126+ const QString &location)
127+{
128+ return QString();
129+}
130+
131+QString PrinterBackend::printerSetShared(const QString &name,
132+ const bool shared)
133+{
134+ return QString();
135+}
136+
137+QString PrinterBackend::printerSetJobSheets(const QString &name,
138+ const QString &start,
139+ const QString &end)
140+{
141+ return QString();
142+}
143+
144+QString PrinterBackend::printerSetErrorPolicy(const QString &name,
145+ const PrinterEnum::ErrorPolicy &policy)
146+{
147+ return QString();
148+}
149+
150+
151+QString PrinterBackend::printerSetOpPolicy(const QString &name,
152+ const PrinterEnum::OperationPolicy &policy)
153+{
154+ return QString();
155+}
156+
157+QString PrinterBackend::printerSetUsersAllowed(const QString &name,
158+ const QStringList &users)
159+{
160+ return QString();
161+}
162+
163+QString PrinterBackend::printerSetUsersDenied(const QString &name,
164+ const QStringList &users)
165+{
166+ return QString();
167+}
168+
169+QString PrinterBackend::printerAddOptionDefault(const QString &name,
170+ const QString &option,
171+ const QStringList &values)
172+{
173+ return QString();
174+}
175+
176+QString PrinterBackend::printerDeleteOptionDefault(const QString &name,
177+ const QString &value)
178+{
179+ return QString();
180+}
181+
182+QString PrinterBackend::printerAddOption(const QString &name,
183+ const QString &option,
184+ const QStringList &values)
185+{
186+ return QString();
187+}
188+
189+QVariant PrinterBackend::printerGetOption(const QString &name,
190+ const QString &option) const
191+{
192+ return QVariant();
193+}
194+
195+QMap<QString, QVariant> PrinterBackend::printerGetOptions(
196+ const QString &name, const QStringList &options
197+)
198+{
199+ return QMap<QString, QVariant>();
200+}
201+
202+// FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
203+cups_dest_t* PrinterBackend::makeDest(const QString &name,
204+ const PrinterJob *options)
205+{
206+ return Q_NULLPTR;
207+}
208+
209+QList<ColorModel> PrinterBackend::printerGetSupportedColorModels(
210+ const QString &name) const
211+{
212+ return QList<ColorModel>();
213+}
214+
215+ColorModel PrinterBackend::printerGetDefaultColorModel(
216+ const QString &name) const
217+{
218+ Q_UNUSED(name);
219+ return ColorModel();
220+}
221+
222+QList<PrintQuality> PrinterBackend::printerGetSupportedQualities(
223+ const QString &name) const
224+{
225+ return QList<PrintQuality>();
226+}
227+
228+PrintQuality PrinterBackend::printerGetDefaultQuality(
229+ const QString &name) const
230+{
231+ Q_UNUSED(name);
232+ return PrintQuality();
233+}
234+
235+int PrinterBackend::printFileToDest(const QString &filepath,
236+ const QString &title,
237+ const cups_dest_t *dest)
238+{
239+ return -1;
240+}
241+
242+QString PrinterBackend::printerName() const
243+{
244+ return QString();
245+}
246+
247+QString PrinterBackend::description() const
248+{
249+ return QString();
250+}
251+
252+QString PrinterBackend::location() const
253+{
254+ return QString();
255+}
256+
257+QString PrinterBackend::makeAndModel() const
258+{
259+ return QString();
260+}
261+
262+PrinterEnum::State PrinterBackend::state() const
263+{
264+ return PrinterEnum::State::IdleState;
265+}
266+
267+QList<QPageSize> PrinterBackend::supportedPageSizes() const
268+{
269+ return QList<QPageSize>();
270+}
271+
272+QPageSize PrinterBackend::defaultPageSize() const
273+{
274+
275+}
276+
277+bool PrinterBackend::supportsCustomPageSizes() const
278+{
279+ return false;
280+}
281+
282+QPageSize PrinterBackend::minimumPhysicalPageSize() const
283+{
284+ return QPageSize();
285+}
286+
287+QPageSize PrinterBackend::maximumPhysicalPageSize() const
288+{
289+ return QPageSize();
290+}
291+
292+QList<int> PrinterBackend::supportedResolutions() const
293+{
294+ return QList<int>();
295+}
296+
297+PrinterEnum::DuplexMode PrinterBackend::defaultDuplexMode() const
298+{
299+ return PrinterEnum::DuplexMode::DuplexNone;
300+}
301+
302+QList<PrinterEnum::DuplexMode> PrinterBackend::supportedDuplexModes() const
303+{
304+ return QList<PrinterEnum::DuplexMode>();
305+}
306+
307+QList<Printer*> PrinterBackend::availablePrinters()
308+{
309+ return QList<Printer*>();
310+}
311+
312+QStringList PrinterBackend::availablePrinterNames()
313+{
314+ return QStringList();
315+}
316+
317+Printer* PrinterBackend::getPrinter(const QString &printerName)
318+{
319+ return Q_NULLPTR;
320+}
321+
322+QString PrinterBackend::defaultPrinterName()
323+{
324+ return QString();
325+}
326+
327+PrinterBackend::BackendType PrinterBackend::backendType() const
328+{
329+ return BackendType::DefaultType;
330+}
331+
332+void PrinterBackend::refresh()
333+{
334+}
335
336=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend.h'
337--- plugins/Ubuntu/Settings/Printers/backend/backend.h 1970-01-01 00:00:00 +0000
338+++ plugins/Ubuntu/Settings/Printers/backend/backend.h 2017-01-23 14:09:24 +0000
339@@ -0,0 +1,153 @@
340+/*
341+ * Copyright (C) 2017 Canonical, Ltd.
342+ *
343+ * This program is free software; you can redistribute it and/or modify
344+ * it under the terms of the GNU Lesser General Public License as published by
345+ * the Free Software Foundation; version 3.
346+ *
347+ * This program is distributed in the hope that it will be useful,
348+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
349+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
350+ * GNU Lesser General Public License for more details.
351+ *
352+ * You should have received a copy of the GNU Lesser General Public License
353+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
354+ */
355+
356+#ifndef USC_PRINTERS_BACKEND_H
357+#define USC_PRINTERS_BACKEND_H
358+
359+#include "printer/printer.h"
360+#include "printer/printerjob.h"
361+
362+// TODO: remove cups specific things from this API
363+#include <cups/cups.h>
364+
365+#include <QObject>
366+#include <QPageSize>
367+#include <QList>
368+#include <QString>
369+#include <QStringList>
370+
371+class Printer;
372+class PrinterJob;
373+class PRINTERS_DECL_EXPORT PrinterBackend : public QObject
374+{
375+ Q_OBJECT
376+public:
377+ explicit PrinterBackend(QObject *parent = Q_NULLPTR);
378+ explicit PrinterBackend(const QString &printerName,
379+ QObject *parent = Q_NULLPTR);
380+ virtual ~PrinterBackend();
381+
382+ enum class BackendType
383+ {
384+ DefaultType = 0,
385+ CupsType,
386+ PdfType,
387+ };
388+ Q_ENUM(BackendType)
389+
390+ virtual bool holdsDefinition() const;
391+
392+ virtual QString printerAdd(const QString &name,
393+ const QUrl &uri,
394+ const QUrl &ppdFile,
395+ const QString &info,
396+ const QString &location);
397+ virtual QString printerAddWithPpd(const QString &name,
398+ const QUrl &uri,
399+ const QString &ppdFileName,
400+ const QString &info,
401+ const QString &location);
402+ virtual QString printerDelete(const QString &name);
403+ virtual QString printerSetEnabled(const QString &name,
404+ const bool enabled);
405+ virtual QString printerSetAcceptJobs(
406+ const QString &name,
407+ const bool enabled,
408+ const QString &reason = QString::null);
409+ virtual QString printerSetInfo(const QString &name,
410+ const QString &info);
411+ virtual QString printerSetLocation(const QString &name,
412+ const QString &location);
413+ virtual QString printerSetShared(const QString &name,
414+ const bool shared);
415+ virtual QString printerSetJobSheets(const QString &name,
416+ const QString &start,
417+ const QString &end);
418+ virtual QString printerSetErrorPolicy(const QString &name,
419+ const PrinterEnum::ErrorPolicy &policy);
420+
421+ virtual QString printerSetOpPolicy(const QString &name,
422+ const PrinterEnum::OperationPolicy &policy);
423+ virtual QString printerSetUsersAllowed(const QString &name,
424+ const QStringList &users);
425+ virtual QString printerSetUsersDenied(const QString &name,
426+ const QStringList &users);
427+ virtual QString printerAddOptionDefault(const QString &name,
428+ const QString &option,
429+ const QStringList &values);
430+ virtual QString printerDeleteOptionDefault(const QString &name,
431+ const QString &value);
432+ virtual QString printerAddOption(const QString &name,
433+ const QString &option,
434+ const QStringList &values);
435+
436+ // TODO: const for both these getters (if possible)!
437+ virtual QVariant printerGetOption(const QString &name,
438+ const QString &option) const;
439+ virtual QMap<QString, QVariant> printerGetOptions(
440+ const QString &name, const QStringList &options
441+ );
442+ // FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
443+ virtual cups_dest_t* makeDest(const QString &name,
444+ const PrinterJob *options);
445+
446+ virtual QList<ColorModel> printerGetSupportedColorModels(
447+ const QString &name) const;
448+ virtual ColorModel printerGetDefaultColorModel(const QString &name) const;
449+ virtual QList<PrintQuality> printerGetSupportedQualities(
450+ const QString &name) const;
451+ virtual PrintQuality printerGetDefaultQuality(const QString &name) const;
452+ virtual int printFileToDest(const QString &filepath,
453+ const QString &title,
454+ const cups_dest_t *dest);
455+
456+ virtual QString printerName() const;
457+ virtual QString description() const;
458+ virtual QString location() const;
459+ virtual QString makeAndModel() const;
460+
461+ virtual PrinterEnum::State state() const;
462+ virtual QList<QPageSize> supportedPageSizes() const;
463+ virtual QPageSize defaultPageSize() const;
464+ virtual bool supportsCustomPageSizes() const;
465+
466+ virtual QPageSize minimumPhysicalPageSize() const;
467+ virtual QPageSize maximumPhysicalPageSize() const;
468+ virtual QList<int> supportedResolutions() const;
469+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const;
470+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const;
471+
472+ virtual QList<Printer*> availablePrinters();
473+ virtual QStringList availablePrinterNames();
474+ virtual Printer* getPrinter(const QString &printerName);
475+ virtual QString defaultPrinterName();
476+
477+ virtual BackendType backendType() const;
478+
479+public Q_SLOTS:
480+ virtual void refresh();
481+
482+Q_SIGNALS:
483+ void printerAdded(const QString &name);
484+ void printerModified(const QString &name, const bool ppdChanged);
485+ void printerDeleted(const QString &name);
486+ void printerStateChanged(const QString &name);
487+
488+protected:
489+ const QString m_printerName;
490+};
491+
492+#endif // USC_PRINTERS_BACKEND_H
493
494=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp'
495--- plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 1970-01-01 00:00:00 +0000
496+++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-01-23 14:09:24 +0000
497@@ -0,0 +1,317 @@
498+/*
499+ * Copyright (C) 2017 Canonical, Ltd.
500+ *
501+ * This program is free software; you can redistribute it and/or modify
502+ * it under the terms of the GNU Lesser General Public License as published by
503+ * the Free Software Foundation; version 3.
504+ *
505+ * This program is distributed in the hope that it will be useful,
506+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
507+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
508+ * GNU Lesser General Public License for more details.
509+ *
510+ * You should have received a copy of the GNU Lesser General Public License
511+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
512+ */
513+
514+#include "backend/backend_cups.h"
515+#include "backend/backend_pdf.h"
516+#include "utils.h"
517+
518+#include <exception>
519+#include <stdexcept>
520+
521+PrinterCupsBackend::PrinterCupsBackend(QObject *parent)
522+ : PrinterCupsBackend(new CupsFacade(), QPrinterInfo(), parent)
523+{
524+ // If we create the CupsFacade, we're in charge of RAII.
525+ m_cups->setParent(this);
526+}
527+
528+PrinterCupsBackend::PrinterCupsBackend(CupsFacade *cups, QPrinterInfo info,
529+ QObject *parent)
530+ : PrinterBackend(info.printerName(), parent)
531+ , m_cups(cups)
532+ , m_info(info)
533+{
534+}
535+
536+PrinterCupsBackend::~PrinterCupsBackend()
537+{
538+
539+}
540+
541+QString PrinterCupsBackend::printerAdd(const QString &name,
542+ const QUrl &uri,
543+ const QUrl &ppdFile,
544+ const QString &info,
545+ const QString &location)
546+{
547+
548+}
549+
550+QString PrinterCupsBackend::printerAddWithPpd(const QString &name,
551+ const QUrl &uri,
552+ const QString &ppdFileName,
553+ const QString &info,
554+ const QString &location)
555+{
556+
557+}
558+
559+bool PrinterCupsBackend::holdsDefinition() const
560+{
561+ return !m_info.isNull();
562+}
563+
564+QString PrinterCupsBackend::printerDelete(const QString &name)
565+{
566+
567+}
568+
569+QString PrinterCupsBackend::printerSetEnabled(const QString &name,
570+ const bool enabled)
571+{
572+
573+}
574+
575+QString PrinterCupsBackend::printerSetAcceptJobs(
576+ const QString &name,
577+ const bool enabled,
578+ const QString &reason)
579+{
580+
581+}
582+
583+QString PrinterCupsBackend::printerSetInfo(const QString &name,
584+ const QString &info)
585+{
586+ return m_cups->printerSetInfo(name, info);
587+}
588+
589+QString PrinterCupsBackend::printerSetLocation(const QString &name,
590+ const QString &location)
591+{
592+ return m_cups->printerSetLocation(name, location);
593+}
594+
595+QString PrinterCupsBackend::printerSetShared(const QString &name,
596+ const bool shared)
597+{
598+ return m_cups->printerSetShared(name, shared);
599+}
600+
601+QString PrinterCupsBackend::printerSetJobSheets(const QString &name,
602+ const QString &start,
603+ const QString &end)
604+{
605+ return m_cups->printerSetJobSheets(name, start, end);
606+}
607+
608+QString PrinterCupsBackend::printerSetErrorPolicy(const QString &name,
609+ const PrinterEnum::ErrorPolicy &policy)
610+{
611+ return m_cups->printerSetErrorPolicy(name, policy);
612+}
613+
614+QString PrinterCupsBackend::printerSetOpPolicy(const QString &name,
615+ const PrinterEnum::OperationPolicy &policy)
616+{
617+ return m_cups->printerSetOpPolicy(name, policy);
618+}
619+
620+QString PrinterCupsBackend::printerSetUsersAllowed(const QString &name,
621+ const QStringList &users)
622+{
623+ return m_cups->printerSetUsersAllowed(name, users);
624+}
625+
626+QString PrinterCupsBackend::printerSetUsersDenied(const QString &name,
627+ const QStringList &users)
628+{
629+ return m_cups->printerSetUsersDenied(name, users);
630+}
631+
632+QString PrinterCupsBackend::printerAddOptionDefault(const QString &name,
633+ const QString &option,
634+ const QStringList &values)
635+{
636+ return m_cups->printerAddOptionDefault(name, option, values);
637+}
638+
639+QString PrinterCupsBackend::printerDeleteOptionDefault(const QString &name,
640+ const QString &value)
641+{
642+ return m_cups->printerDeleteOptionDefault(name, value);
643+}
644+
645+QString PrinterCupsBackend::printerAddOption(const QString &name,
646+ const QString &option,
647+ const QStringList &values)
648+{
649+ return m_cups->printerAddOption(name, option, values);
650+}
651+
652+ // TODO: const for both these getters (if possible)!
653+QVariant PrinterCupsBackend::printerGetOption(const QString &name,
654+ const QString &option) const
655+{
656+ return m_cups->printerGetOption(name, option);
657+}
658+QMap<QString, QVariant> PrinterCupsBackend::printerGetOptions(
659+ const QString &name, const QStringList &options)
660+{
661+ return m_cups->printerGetOptions(name, options);
662+}
663+
664+// FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
665+cups_dest_t* PrinterCupsBackend::makeDest(const QString &name,
666+ const PrinterJob *options)
667+{
668+ return m_cups->makeDest(name, options);
669+}
670+
671+QList<ColorModel> PrinterCupsBackend::printerGetSupportedColorModels(
672+ const QString &name) const
673+{
674+ return m_cups->printerGetSupportedColorModels(name);
675+}
676+
677+ColorModel PrinterCupsBackend::printerGetDefaultColorModel(
678+ const QString &name) const
679+{
680+ return printerGetOption(name, "DefaultColorModel").value<ColorModel>();
681+}
682+
683+QList<PrintQuality> PrinterCupsBackend::printerGetSupportedQualities(
684+ const QString &name) const
685+{
686+ return m_cups->printerGetSupportedQualities(name);
687+}
688+
689+PrintQuality PrinterCupsBackend::printerGetDefaultQuality(
690+ const QString &name) const
691+{
692+ return printerGetOption(name, "DefaultPrintQuality").value<PrintQuality>();
693+}
694+
695+int PrinterCupsBackend::printFileToDest(const QString &filepath,
696+ const QString &title,
697+ const cups_dest_t *dest)
698+{
699+ return m_cups->printFileToDest(filepath, title, dest);
700+}
701+
702+QString PrinterCupsBackend::printerName() const
703+{
704+ return m_info.printerName();
705+}
706+
707+QString PrinterCupsBackend::description() const
708+{
709+ return m_info.description();
710+}
711+
712+QString PrinterCupsBackend::location() const
713+{
714+
715+}
716+
717+QString PrinterCupsBackend::makeAndModel() const
718+{
719+
720+}
721+
722+PrinterEnum::State PrinterCupsBackend::state() const
723+{
724+
725+}
726+
727+QList<QPageSize> PrinterCupsBackend::supportedPageSizes() const
728+{
729+ return m_info.supportedPageSizes();
730+}
731+
732+QPageSize PrinterCupsBackend::defaultPageSize() const
733+{
734+ return m_info.defaultPageSize();
735+}
736+
737+bool PrinterCupsBackend::supportsCustomPageSizes() const
738+{
739+
740+}
741+
742+QPageSize PrinterCupsBackend::minimumPhysicalPageSize() const
743+{
744+
745+}
746+
747+QPageSize PrinterCupsBackend::maximumPhysicalPageSize() const
748+{
749+
750+}
751+
752+QList<int> PrinterCupsBackend::supportedResolutions() const
753+{
754+
755+}
756+
757+PrinterEnum::DuplexMode PrinterCupsBackend::defaultDuplexMode() const
758+{
759+ return Utils::qDuplexModeToDuplexMode(m_info.defaultDuplexMode());
760+}
761+
762+QList<PrinterEnum::DuplexMode> PrinterCupsBackend::supportedDuplexModes() const
763+{
764+ QList<PrinterEnum::DuplexMode> list;
765+ Q_FOREACH(const QPrinter::DuplexMode mode, m_info.supportedDuplexModes()) {
766+ if (mode != QPrinter::DuplexAuto) {
767+ list.append(Utils::qDuplexModeToDuplexMode(mode));
768+ }
769+ }
770+ return list;
771+}
772+
773+QList<Printer*> PrinterCupsBackend::availablePrinters()
774+{
775+ QList<Printer*> list;
776+ Q_FOREACH(QPrinterInfo info, QPrinterInfo::availablePrinters()) {
777+ list.append(new Printer(new PrinterCupsBackend(m_cups, info)));
778+ }
779+
780+ // Cups allows a faux PDF printer.
781+ // TODO: Translate.
782+ list.append(new Printer(new PrinterPdfBackend("Create PDF")));
783+
784+ return list;
785+}
786+
787+QStringList PrinterCupsBackend::availablePrinterNames()
788+{
789+ return QPrinterInfo::availablePrinterNames();
790+}
791+
792+Printer* PrinterCupsBackend::getPrinter(const QString &printerName)
793+{
794+
795+}
796+
797+QString PrinterCupsBackend::defaultPrinterName()
798+{
799+ return QPrinterInfo::defaultPrinterName();
800+}
801+
802+PrinterBackend::BackendType PrinterCupsBackend::backendType() const
803+{
804+ return PrinterBackend::BackendType::CupsType;
805+}
806+
807+void PrinterCupsBackend::refresh()
808+{
809+ if (m_printerName.isEmpty()) {
810+ throw std::invalid_argument("Trying to refresh unnamed printer.");
811+ } else {
812+ m_info = QPrinterInfo::printerInfo(m_printerName);
813+ }
814+}
815
816=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.h'
817--- plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 1970-01-01 00:00:00 +0000
818+++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.h 2017-01-23 14:09:24 +0000
819@@ -0,0 +1,130 @@
820+/*
821+ * Copyright (C) 2017 Canonical, Ltd.
822+ *
823+ * This program is free software; you can redistribute it and/or modify
824+ * it under the terms of the GNU Lesser General Public License as published by
825+ * the Free Software Foundation; version 3.
826+ *
827+ * This program is distributed in the hope that it will be useful,
828+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
829+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
830+ * GNU Lesser General Public License for more details.
831+ *
832+ * You should have received a copy of the GNU Lesser General Public License
833+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
834+ */
835+
836+#ifndef USC_PRINTERS_CUPS_BACKEND_H
837+#define USC_PRINTERS_CUPS_BACKEND_H
838+
839+#include "backend/backend.h"
840+#include "cups/cupsfacade.h"
841+
842+#include <QPrinterInfo>
843+
844+class PRINTERS_DECL_EXPORT PrinterCupsBackend : public PrinterBackend
845+{
846+public:
847+ explicit PrinterCupsBackend(QObject *parent = Q_NULLPTR);
848+ explicit PrinterCupsBackend(CupsFacade *cups, QPrinterInfo info,
849+ QObject *parent = Q_NULLPTR);
850+ virtual ~PrinterCupsBackend() override;
851+
852+ virtual bool holdsDefinition() const override;
853+
854+ virtual QString printerAdd(const QString &name,
855+ const QUrl &uri,
856+ const QUrl &ppdFile,
857+ const QString &info,
858+ const QString &location) override;
859+ virtual QString printerAddWithPpd(const QString &name,
860+ const QUrl &uri,
861+ const QString &ppdFileName,
862+ const QString &info,
863+ const QString &location) override;
864+ virtual QString printerDelete(const QString &name) override;
865+ virtual QString printerSetEnabled(const QString &name,
866+ const bool enabled) override;
867+ virtual QString printerSetAcceptJobs(
868+ const QString &name,
869+ const bool enabled,
870+ const QString &reason = QString::null) override;
871+ virtual QString printerSetInfo(const QString &name,
872+ const QString &info) override;
873+ virtual QString printerSetLocation(const QString &name,
874+ const QString &location) override;
875+ virtual QString printerSetShared(const QString &name,
876+ const bool shared) override;
877+ virtual QString printerSetJobSheets(const QString &name,
878+ const QString &start,
879+ const QString &end) override;
880+ virtual QString printerSetErrorPolicy(const QString &name,
881+ const PrinterEnum::ErrorPolicy &policy) override;
882+
883+ virtual QString printerSetOpPolicy(const QString &name,
884+ const PrinterEnum::OperationPolicy &policy) override;
885+ virtual QString printerSetUsersAllowed(const QString &name,
886+ const QStringList &users) override;
887+ virtual QString printerSetUsersDenied(const QString &name,
888+ const QStringList &users) override;
889+ virtual QString printerAddOptionDefault(const QString &name,
890+ const QString &option,
891+ const QStringList &values) override;
892+ virtual QString printerDeleteOptionDefault(const QString &name,
893+ const QString &value) override;
894+ virtual QString printerAddOption(const QString &name,
895+ const QString &option,
896+ const QStringList &values) override;
897+
898+ // TODO: const for both these getters (if possible)!
899+ virtual QVariant printerGetOption(const QString &name,
900+ const QString &option) const override;
901+ virtual QMap<QString, QVariant> printerGetOptions(
902+ const QString &name, const QStringList &options
903+ ) override;
904+ // FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
905+ virtual cups_dest_t* makeDest(const QString &name,
906+ const PrinterJob *options) override;
907+
908+ virtual QList<ColorModel> printerGetSupportedColorModels(
909+ const QString &name) const override;
910+ virtual ColorModel printerGetDefaultColorModel(const QString &name) const;
911+ virtual QList<PrintQuality> printerGetSupportedQualities(
912+ const QString &name) const override;
913+ virtual PrintQuality printerGetDefaultQuality(const QString &name) const;
914+ virtual int printFileToDest(const QString &filepath,
915+ const QString &title,
916+ const cups_dest_t *dest) override;
917+
918+ virtual QString printerName() const override;
919+ virtual QString description() const override;
920+ virtual QString location() const override;
921+ virtual QString makeAndModel() const override;
922+
923+ virtual PrinterEnum::State state() const override;
924+ virtual QList<QPageSize> supportedPageSizes() const override;
925+ virtual QPageSize defaultPageSize() const override;
926+ virtual bool supportsCustomPageSizes() const override;
927+
928+ virtual QPageSize minimumPhysicalPageSize() const override;
929+ virtual QPageSize maximumPhysicalPageSize() const override;
930+ virtual QList<int> supportedResolutions() const override;
931+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const override;
932+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override;
933+
934+ virtual QList<Printer*> availablePrinters() override;
935+ virtual QStringList availablePrinterNames() override;
936+ virtual Printer* getPrinter(const QString &printerName) override;
937+ virtual QString defaultPrinterName() override;
938+
939+ virtual PrinterBackend::BackendType backendType() const override;
940+
941+public Q_SLOTS:
942+ virtual void refresh() override;
943+
944+private:
945+ CupsFacade *m_cups;
946+ QPrinterInfo m_info;
947+};
948+
949+#endif // USC_PRINTERS_CUPS_BACKEND_H
950
951=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend_pdf.cpp'
952--- plugins/Ubuntu/Settings/Printers/backend/backend_pdf.cpp 1970-01-01 00:00:00 +0000
953+++ plugins/Ubuntu/Settings/Printers/backend/backend_pdf.cpp 2017-01-23 14:09:24 +0000
954@@ -0,0 +1,124 @@
955+/*
956+ * Copyright (C) 2017 Canonical, Ltd.
957+ *
958+ * This program is free software; you can redistribute it and/or modify
959+ * it under the terms of the GNU Lesser General Public License as published by
960+ * the Free Software Foundation; version 3.
961+ *
962+ * This program is distributed in the hope that it will be useful,
963+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
964+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
965+ * GNU Lesser General Public License for more details.
966+ *
967+ * You should have received a copy of the GNU Lesser General Public License
968+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
969+ */
970+
971+#include "backend/backend_pdf.h"
972+
973+PrinterPdfBackend::PrinterPdfBackend(const QString &printerName,
974+ QObject *parent)
975+ : PrinterBackend(printerName, parent)
976+{
977+}
978+
979+QList<ColorModel> PrinterPdfBackend::printerGetSupportedColorModels(
980+ const QString &name) const
981+{
982+ return QList<ColorModel>{printerGetDefaultColorModel(name)};
983+}
984+
985+ColorModel PrinterPdfBackend::printerGetDefaultColorModel(
986+ const QString &name) const
987+{
988+ Q_UNUSED(name);
989+ ColorModel rgb;
990+ rgb.colorType = PrinterEnum::ColorModelType::ColorType;
991+ rgb.name = "RGB";
992+ rgb.text = "Color"; // TODO: translate
993+ return rgb;
994+}
995+
996+QList<PrintQuality> PrinterPdfBackend::printerGetSupportedQualities(
997+ const QString &name) const
998+{
999+ return QList<PrintQuality>({printerGetDefaultQuality(name)});
1000+}
1001+
1002+PrintQuality PrinterPdfBackend::printerGetDefaultQuality(
1003+ const QString &name) const
1004+{
1005+ Q_UNUSED(name);
1006+ return PrintQuality();
1007+}
1008+
1009+QString PrinterPdfBackend::printerName() const
1010+{
1011+ return m_printerName;
1012+}
1013+
1014+QString PrinterPdfBackend::description() const
1015+{
1016+ return QStringLiteral("");
1017+}
1018+
1019+QString PrinterPdfBackend::location() const
1020+{
1021+ return QStringLiteral("");
1022+}
1023+
1024+QString PrinterPdfBackend::makeAndModel() const
1025+{
1026+ return QStringLiteral("");
1027+}
1028+
1029+PrinterEnum::State PrinterPdfBackend::state() const
1030+{
1031+ return PrinterEnum::State::IdleState;
1032+}
1033+
1034+QList<QPageSize> PrinterPdfBackend::supportedPageSizes() const
1035+{
1036+ return QList<QPageSize>{QPageSize(QPageSize::A4)};
1037+}
1038+
1039+QPageSize PrinterPdfBackend::defaultPageSize() const
1040+{
1041+ return QPageSize(QPageSize::A4);
1042+}
1043+
1044+bool PrinterPdfBackend::supportsCustomPageSizes() const
1045+{
1046+ return false;
1047+}
1048+
1049+
1050+QPageSize PrinterPdfBackend::minimumPhysicalPageSize() const
1051+{
1052+ return QPageSize(QPageSize::A4);
1053+}
1054+
1055+QPageSize PrinterPdfBackend::maximumPhysicalPageSize() const
1056+{
1057+ return QPageSize(QPageSize::A4);
1058+}
1059+
1060+QList<int> PrinterPdfBackend::supportedResolutions() const
1061+{
1062+
1063+}
1064+
1065+PrinterEnum::DuplexMode PrinterPdfBackend::defaultDuplexMode() const
1066+{
1067+ return PrinterEnum::DuplexMode::DuplexNone;
1068+}
1069+
1070+QList<PrinterEnum::DuplexMode> PrinterPdfBackend::supportedDuplexModes() const
1071+{
1072+ return QList<PrinterEnum::DuplexMode>{PrinterEnum::DuplexMode::DuplexNone};
1073+}
1074+
1075+PrinterBackend::BackendType PrinterPdfBackend::backendType() const
1076+{
1077+ return PrinterBackend::BackendType::PdfType;
1078+}
1079
1080=== added file 'plugins/Ubuntu/Settings/Printers/backend/backend_pdf.h'
1081--- plugins/Ubuntu/Settings/Printers/backend/backend_pdf.h 1970-01-01 00:00:00 +0000
1082+++ plugins/Ubuntu/Settings/Printers/backend/backend_pdf.h 2017-01-23 14:09:24 +0000
1083@@ -0,0 +1,53 @@
1084+/*
1085+ * Copyright (C) 2017 Canonical, Ltd.
1086+ *
1087+ * This program is free software; you can redistribute it and/or modify
1088+ * it under the terms of the GNU Lesser General Public License as published by
1089+ * the Free Software Foundation; version 3.
1090+ *
1091+ * This program is distributed in the hope that it will be useful,
1092+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1093+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1094+ * GNU Lesser General Public License for more details.
1095+ *
1096+ * You should have received a copy of the GNU Lesser General Public License
1097+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1098+ */
1099+
1100+#ifndef USC_PRINTERS_PDF_BACKEND_H
1101+#define USC_PRINTERS_PDF_BACKEND_H
1102+
1103+#include "backend/backend.h"
1104+
1105+class PRINTERS_DECL_EXPORT PrinterPdfBackend : public PrinterBackend
1106+{
1107+public:
1108+ explicit PrinterPdfBackend(const QString &printerName,
1109+ QObject *parent = Q_NULLPTR);
1110+ virtual QList<ColorModel> printerGetSupportedColorModels(
1111+ const QString &name) const override;
1112+ virtual ColorModel printerGetDefaultColorModel(const QString &name) const;
1113+ virtual QList<PrintQuality> printerGetSupportedQualities(
1114+ const QString &name) const override;
1115+ virtual PrintQuality printerGetDefaultQuality(const QString &name) const;
1116+
1117+ virtual QString printerName() const override;
1118+ virtual QString description() const override;
1119+ virtual QString location() const override;
1120+ virtual QString makeAndModel() const override;
1121+
1122+ virtual PrinterEnum::State state() const override;
1123+ virtual QList<QPageSize> supportedPageSizes() const override;
1124+ virtual QPageSize defaultPageSize() const override;
1125+ virtual bool supportsCustomPageSizes() const override;
1126+
1127+ virtual QPageSize minimumPhysicalPageSize() const override;
1128+ virtual QPageSize maximumPhysicalPageSize() const override;
1129+ virtual QList<int> supportedResolutions() const override;
1130+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const override;
1131+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override;
1132+
1133+ virtual PrinterBackend::BackendType backendType() const override;
1134+};
1135+
1136+#endif // USC_PRINTERS_PDF_BACKEND_H
1137
1138=== renamed file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp' => 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp'
1139--- plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp 2017-01-20 11:44:54 +0000
1140+++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-01-23 14:09:24 +0000
1141@@ -16,7 +16,7 @@
1142
1143 #include "utils.h"
1144
1145-#include "cups/cupsfacade_impl.h"
1146+#include "cups/cupsfacade.h"
1147
1148 #include <cups/http.h>
1149 #include <cups/ipp.h>
1150@@ -27,21 +27,20 @@
1151 #define __CUPS_ADD_OPTION(dest, name, value) dest->num_options = \
1152 cupsAddOption(name, value, dest->num_options, &dest->options);
1153
1154-CupsFacadeImpl::CupsFacadeImpl(QObject *parent) : CupsFacade(parent)
1155-{
1156-
1157-}
1158-
1159-CupsFacadeImpl::~CupsFacadeImpl()
1160-{
1161-
1162-}
1163-
1164-QString CupsFacadeImpl::printerAdd(const QString &name,
1165- const QUrl &uri,
1166- const QUrl &ppdFile,
1167- const QString &info,
1168- const QString &location)
1169+CupsFacade::CupsFacade(QObject *parent) : QObject(parent)
1170+{
1171+}
1172+
1173+CupsFacade::~CupsFacade()
1174+{
1175+
1176+}
1177+
1178+QString CupsFacade::printerAdd(const QString &name,
1179+ const QUrl &uri,
1180+ const QUrl &ppdFile,
1181+ const QString &info,
1182+ const QString &location)
1183 {
1184 Q_UNUSED(name);
1185 Q_UNUSED(uri);
1186@@ -51,11 +50,11 @@
1187 return QString();
1188 }
1189
1190-QString CupsFacadeImpl::printerAddWithPpd(const QString &name,
1191- const QUrl &uri,
1192- const QString &ppdFileName,
1193- const QString &info,
1194- const QString &location)
1195+QString CupsFacade::printerAddWithPpd(const QString &name,
1196+ const QUrl &uri,
1197+ const QString &ppdFileName,
1198+ const QString &info,
1199+ const QString &location)
1200 {
1201 Q_UNUSED(name);
1202 Q_UNUSED(uri);
1203@@ -65,21 +64,20 @@
1204 return QString();
1205 }
1206
1207-QString CupsFacadeImpl::printerDelete(const QString &name)
1208+QString CupsFacade::printerDelete(const QString &name)
1209 {
1210 Q_UNUSED(name);
1211 return QString();
1212 }
1213
1214-QString CupsFacadeImpl::printerSetEnabled(const QString &name,
1215- const bool enabled)
1216+QString CupsFacade::printerSetEnabled(const QString &name, const bool enabled)
1217 {
1218 Q_UNUSED(name);
1219 Q_UNUSED(enabled);
1220 return QString();
1221 }
1222
1223-QString CupsFacadeImpl::printerSetAcceptJobs(
1224+QString CupsFacade::printerSetAcceptJobs(
1225 const QString &name,
1226 const bool enabled,
1227 const QString &reason)
1228@@ -90,8 +88,7 @@
1229 return QString();
1230 }
1231
1232-QString CupsFacadeImpl::printerSetInfo(const QString &name,
1233- const QString &info)
1234+QString CupsFacade::printerSetInfo(const QString &name, const QString &info)
1235 {
1236 if (!helper.printerClassSetInfo(name, info)) {
1237 return helper.getLastError();
1238@@ -99,25 +96,24 @@
1239 return QString();
1240 }
1241
1242-QString CupsFacadeImpl::printerSetLocation(const QString &name,
1243- const QString &location)
1244+QString CupsFacade::printerSetLocation(const QString &name,
1245+ const QString &location)
1246 {
1247 Q_UNUSED(name);
1248 Q_UNUSED(location);
1249 return QString();
1250 }
1251
1252-QString CupsFacadeImpl::printerSetShared(const QString &name,
1253- const bool shared)
1254+QString CupsFacade::printerSetShared(const QString &name, const bool shared)
1255 {
1256 Q_UNUSED(name);
1257 Q_UNUSED(shared);
1258 return QString();
1259 }
1260
1261-QString CupsFacadeImpl::printerSetJobSheets(const QString &name,
1262- const QString &start,
1263- const QString &end)
1264+QString CupsFacade::printerSetJobSheets(const QString &name,
1265+ const QString &start,
1266+ const QString &end)
1267 {
1268 Q_UNUSED(name);
1269 Q_UNUSED(start);
1270@@ -125,41 +121,41 @@
1271 return QString();
1272 }
1273
1274-QString CupsFacadeImpl::printerSetErrorPolicy(const QString &name,
1275- const PrinterEnum::ErrorPolicy &policy)
1276-{
1277- Q_UNUSED(name);
1278- Q_UNUSED(policy);
1279- return QString();
1280-}
1281-
1282-QString CupsFacadeImpl::printerSetOpPolicy(const QString &name,
1283- const PrinterEnum::OperationPolicy &policy)
1284-{
1285- Q_UNUSED(name);
1286- Q_UNUSED(policy);
1287- return QString();
1288-}
1289-
1290-QString CupsFacadeImpl::printerSetUsersAllowed(const QString &name,
1291- const QStringList &users)
1292-{
1293- Q_UNUSED(name);
1294- Q_UNUSED(users);
1295- return QString();
1296-}
1297-
1298-QString CupsFacadeImpl::printerSetUsersDenied(const QString &name,
1299- const QStringList &users)
1300-{
1301- Q_UNUSED(name);
1302- Q_UNUSED(users);
1303- return QString();
1304-}
1305-
1306-QString CupsFacadeImpl::printerAddOptionDefault(const QString &name,
1307- const QString &option,
1308- const QStringList &values)
1309+QString CupsFacade::printerSetErrorPolicy(const QString &name,
1310+ const PrinterEnum::ErrorPolicy &policy)
1311+{
1312+ Q_UNUSED(name);
1313+ Q_UNUSED(policy);
1314+ return QString();
1315+}
1316+
1317+QString CupsFacade::printerSetOpPolicy(const QString &name,
1318+ const PrinterEnum::OperationPolicy &policy)
1319+{
1320+ Q_UNUSED(name);
1321+ Q_UNUSED(policy);
1322+ return QString();
1323+}
1324+
1325+QString CupsFacade::printerSetUsersAllowed(const QString &name,
1326+ const QStringList &users)
1327+{
1328+ Q_UNUSED(name);
1329+ Q_UNUSED(users);
1330+ return QString();
1331+}
1332+
1333+QString CupsFacade::printerSetUsersDenied(const QString &name,
1334+ const QStringList &users)
1335+{
1336+ Q_UNUSED(name);
1337+ Q_UNUSED(users);
1338+ return QString();
1339+}
1340+
1341+QString CupsFacade::printerAddOptionDefault(const QString &name,
1342+ const QString &option,
1343+ const QStringList &values)
1344 {
1345 Q_UNUSED(name);
1346 Q_UNUSED(option);
1347@@ -167,17 +163,17 @@
1348 return QString();
1349 }
1350
1351-QString CupsFacadeImpl::printerDeleteOptionDefault(const QString &name,
1352- const QString &value)
1353+QString CupsFacade::printerDeleteOptionDefault(const QString &name,
1354+ const QString &value)
1355 {
1356 Q_UNUSED(name);
1357 Q_UNUSED(value);
1358 return QString();
1359 }
1360
1361-QString CupsFacadeImpl::printerAddOption(const QString &name,
1362- const QString &option,
1363- const QStringList &values)
1364+QString CupsFacade::printerAddOption(const QString &name,
1365+ const QString &option,
1366+ const QStringList &values)
1367 {
1368 if (!helper.printerClassSetOption(name, option, values)) {
1369 return helper.getLastError();
1370@@ -187,15 +183,15 @@
1371 return QString();
1372 }
1373
1374-QVariant CupsFacadeImpl::printerGetOption(const QString &name,
1375- const QString &option)
1376+QVariant CupsFacade::printerGetOption(const QString &name,
1377+ const QString &option)
1378 {
1379 QStringList opts({option});
1380 auto res = printerGetOptions(name, opts);
1381 return res[option];
1382 }
1383
1384-QMap<QString, QVariant> CupsFacadeImpl::printerGetOptions(
1385+QMap<QString, QVariant> CupsFacade::printerGetOptions(
1386 const QString &name, const QStringList &options)
1387 {
1388 QMap<QString, QVariant> ret;
1389@@ -263,7 +259,7 @@
1390 return ret;
1391 }
1392
1393-QList<ColorModel> CupsFacadeImpl::printerGetSupportedColorModels(
1394+QList<ColorModel> CupsFacade::printerGetSupportedColorModels(
1395 const QString &name) const
1396 {
1397 QList<ColorModel> ret;
1398@@ -288,7 +284,8 @@
1399 return ret;
1400 }
1401
1402-QList<PrintQuality> CupsFacadeImpl::printerGetSupportedQualities(const QString &name) const
1403+QList<PrintQuality> CupsFacade::printerGetSupportedQualities(
1404+ const QString &name) const
1405 {
1406 QList<PrintQuality> ret;
1407 ppd_file_t* ppd;
1408@@ -313,13 +310,13 @@
1409 return ret;
1410 }
1411
1412-QString CupsFacadeImpl::getPrinterName(const QString &name) const
1413+QString CupsFacade::getPrinterName(const QString &name) const
1414 {
1415 const auto parts = name.splitRef(QLatin1Char('/'));
1416 return parts.at(0).toString();
1417 }
1418
1419-QString CupsFacadeImpl::getPrinterInstance(const QString &name) const
1420+QString CupsFacade::getPrinterInstance(const QString &name) const
1421 {
1422 const auto parts = name.splitRef(QLatin1Char('/'));
1423 QString instance;
1424@@ -329,8 +326,8 @@
1425 return instance;
1426 }
1427
1428-cups_dest_t* CupsFacadeImpl::makeDest(const QString &name,
1429- const PrinterJob *options)
1430+cups_dest_t* CupsFacade::makeDest(const QString &name,
1431+ const PrinterJob *options)
1432 {
1433 // Get the cups dest
1434 cups_dest_t *dest = helper.getDest(getPrinterName(name), getPrinterInstance(name));
1435@@ -358,9 +355,8 @@
1436 return dest;
1437 }
1438
1439-int CupsFacadeImpl::printFileToDest(const QString &filepath,
1440- const QString &title,
1441- const cups_dest_t *dest)
1442+int CupsFacade::printFileToDest(const QString &filepath, const QString &title,
1443+ const cups_dest_t *dest)
1444 {
1445 qDebug() << "Printing:" << filepath << title << dest->name << dest->num_options;
1446 return cupsPrintFile(dest->name,
1447
1448=== modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h'
1449--- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-01-19 21:00:28 +0000
1450+++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-01-23 14:09:24 +0000
1451@@ -17,11 +17,10 @@
1452 #ifndef USC_PRINTERS_CUPSFACADE_H
1453 #define USC_PRINTERS_CUPSFACADE_H
1454
1455-#include "printers_global.h"
1456-
1457 #include "enums.h"
1458 #include "structs.h"
1459
1460+#include "cups/cupspkhelper.h"
1461 #include "printer/printerjob.h"
1462
1463 #include <cups/cups.h>
1464@@ -34,79 +33,78 @@
1465 #include <QUrl>
1466 #include <QVariant>
1467
1468-class PRINTERS_DECL_EXPORT CupsFacade : public QObject
1469+class PrinterJob;
1470+class CupsFacade : public QObject
1471 {
1472 Q_OBJECT
1473 public:
1474- explicit CupsFacade(QObject *parent = nullptr) : QObject(parent) {};
1475- virtual ~CupsFacade() {};
1476- virtual QString printerAdd(const QString &name,
1477- const QUrl &uri,
1478- const QUrl &ppdFile,
1479- const QString &info,
1480- const QString &location) = 0;
1481- virtual QString printerAddWithPpd(const QString &name,
1482- const QUrl &uri,
1483- const QString &ppdFileName,
1484- const QString &info,
1485- const QString &location) = 0;
1486- virtual QString printerDelete(const QString &name) = 0;
1487- virtual QString printerSetEnabled(const QString &name,
1488- const bool enabled) = 0;
1489- virtual QString printerSetAcceptJobs(
1490+ explicit CupsFacade(QObject *parent = Q_NULLPTR);
1491+ ~CupsFacade();
1492+ QString printerAdd(const QString &name,
1493+ const QUrl &uri,
1494+ const QUrl &ppdFile,
1495+ const QString &info,
1496+ const QString &location);
1497+ QString printerAddWithPpd(const QString &name,
1498+ const QUrl &uri,
1499+ const QString &ppdFileName,
1500+ const QString &info,
1501+ const QString &location);
1502+ QString printerDelete(const QString &name);
1503+ QString printerSetEnabled(const QString &name, const bool enabled);
1504+ QString printerSetAcceptJobs(
1505 const QString &name,
1506 const bool enabled,
1507- const QString &reason = QString::null) = 0;
1508- virtual QString printerSetInfo(const QString &name,
1509- const QString &info) = 0;
1510- virtual QString printerSetLocation(const QString &name,
1511- const QString &location) = 0;
1512- virtual QString printerSetShared(const QString &name,
1513- const bool shared) = 0;
1514- virtual QString printerSetJobSheets(const QString &name,
1515- const QString &start,
1516- const QString &end) = 0;
1517- virtual QString printerSetErrorPolicy(const QString &name,
1518- const PrinterEnum::ErrorPolicy &policy) = 0;
1519+ const QString &reason = QString::null);
1520+ QString printerSetInfo(const QString &name, const QString &info);
1521+ QString printerSetLocation(const QString &name, const QString &location);
1522+ QString printerSetShared(const QString &name, const bool shared);
1523+ QString printerSetJobSheets(const QString &name, const QString &start,
1524+ const QString &end);
1525+ QString printerSetErrorPolicy(const QString &name,
1526+ const PrinterEnum::ErrorPolicy &policy);
1527
1528- virtual QString printerSetOpPolicy(const QString &name,
1529- const PrinterEnum::OperationPolicy &policy) = 0;
1530- virtual QString printerSetUsersAllowed(const QString &name,
1531- const QStringList &users) = 0;
1532- virtual QString printerSetUsersDenied(const QString &name,
1533- const QStringList &users) = 0;
1534- virtual QString printerAddOptionDefault(const QString &name,
1535- const QString &option,
1536- const QStringList &values) = 0;
1537- virtual QString printerDeleteOptionDefault(const QString &name,
1538- const QString &value) = 0;
1539- virtual QString printerAddOption(const QString &name,
1540- const QString &option,
1541- const QStringList &values) = 0;
1542+ QString printerSetOpPolicy(const QString &name,
1543+ const PrinterEnum::OperationPolicy &policy);
1544+ QString printerSetUsersAllowed(const QString &name,
1545+ const QStringList &users);
1546+ QString printerSetUsersDenied(const QString &name,
1547+ const QStringList &users);
1548+ QString printerAddOptionDefault(const QString &name,
1549+ const QString &option,
1550+ const QStringList &values);
1551+ QString printerDeleteOptionDefault(const QString &name,
1552+ const QString &value);
1553+ QString printerAddOption(const QString &name,
1554+ const QString &option,
1555+ const QStringList &values);
1556
1557 // TODO: const for both these getters (if possible)!
1558- virtual QVariant printerGetOption(const QString &name,
1559- const QString &option) = 0;
1560- virtual QMap<QString, QVariant> printerGetOptions(
1561- const QString &name, const QStringList &options
1562- ) = 0;
1563+ QVariant printerGetOption(const QString &name, const QString &option);
1564+ QMap<QString, QVariant> printerGetOptions(const QString &name,
1565+ const QStringList &options);
1566 // FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
1567- virtual cups_dest_t* makeDest(const QString &name,
1568- const PrinterJob *options) = 0;
1569-
1570- virtual QList<ColorModel> printerGetSupportedColorModels(
1571- const QString &name) const = 0;
1572- virtual QList<PrintQuality> printerGetSupportedQualities(
1573- const QString &name) const = 0;
1574- virtual int printFileToDest(const QString &filepath,
1575- const QString &title,
1576- const cups_dest_t *dest) = 0;
1577-
1578+ cups_dest_t* makeDest(const QString &name, const PrinterJob *options);
1579+
1580+ QList<ColorModel> printerGetSupportedColorModels(const QString &name) const;
1581+ QList<PrintQuality> printerGetSupportedQualities(const QString &name) const;
1582+ int printFileToDest(const QString &filepath, const QString &title,
1583+ const cups_dest_t *dest);
1584 Q_SIGNALS:
1585 void printerAdded(const QString &name);
1586 void printerModified(const QString &name, const bool ppdChanged);
1587 void printerDeleted(const QString &name);
1588 void printerStateChanged(const QString &name);
1589+
1590+private:
1591+ QString getPrinterName(const QString &name) const;
1592+ QString getPrinterInstance(const QString &name) const;
1593+ QStringList parsePpdColorModel(const QString &colorModel);
1594+ const QStringList m_knownQualityOptions = QStringList({
1595+ "Quality", "PrintQuality", "HPPrintQuality", "StpQuality",
1596+ "OutputMode",
1597+ });
1598+ CupsPkHelper helper;
1599 };
1600
1601 #endif // USC_PRINTERS_CUPSFACADE_H
1602
1603=== removed file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h'
1604--- plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h 2017-01-20 11:44:54 +0000
1605+++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h 1970-01-01 00:00:00 +0000
1606@@ -1,98 +0,0 @@
1607-/*
1608- * Copyright (C) 2017 Canonical, Ltd.
1609- *
1610- * This program is free software; you can redistribute it and/or modify
1611- * it under the terms of the GNU Lesser General Public License as published by
1612- * the Free Software Foundation; version 3.
1613- *
1614- * This program is distributed in the hope that it will be useful,
1615- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1616- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1617- * GNU Lesser General Public License for more details.
1618- *
1619- * You should have received a copy of the GNU Lesser General Public License
1620- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1621- */
1622-
1623-#ifndef USC_PRINTERS_CUPSFACADE_IMPL_H
1624-#define USC_PRINTERS_CUPSFACADE_IMPL_H
1625-
1626-#include "cups/cupsfacade.h"
1627-#include "cups/cupspkhelper.h"
1628-
1629-class CupsFacadeImpl : public CupsFacade
1630-{
1631- Q_OBJECT
1632-public:
1633- explicit CupsFacadeImpl(QObject *parent = nullptr);
1634- virtual ~CupsFacadeImpl() override;
1635- virtual QString printerAdd(const QString &name,
1636- const QUrl &uri,
1637- const QUrl &ppdFile,
1638- const QString &info,
1639- const QString &location) override;
1640- virtual QString printerAddWithPpd(const QString &name,
1641- const QUrl &uri,
1642- const QString &ppdFileName,
1643- const QString &info,
1644- const QString &location) override;
1645- virtual QString printerDelete(const QString &name) override;
1646- virtual QString printerSetEnabled(const QString &name,
1647- const bool enabled) override;
1648- virtual QString printerSetAcceptJobs(
1649- const QString &name,
1650- const bool enabled,
1651- const QString &reason = QString::null) override;
1652- virtual QString printerSetInfo(const QString &name,
1653- const QString &info) override;
1654- virtual QString printerSetLocation(const QString &name,
1655- const QString &location) override;
1656- virtual QString printerSetShared(const QString &name,
1657- const bool shared) override;
1658- virtual QString printerSetJobSheets(const QString &name,
1659- const QString &start,
1660- const QString &end) override;
1661- virtual QString printerSetErrorPolicy(const QString &name,
1662- const PrinterEnum::ErrorPolicy &policy) override;
1663-
1664- virtual QString printerSetOpPolicy(const QString &name,
1665- const PrinterEnum::OperationPolicy &policy) override;
1666- virtual QString printerSetUsersAllowed(const QString &name,
1667- const QStringList &users) override;
1668- virtual QString printerSetUsersDenied(const QString &name,
1669- const QStringList &users) override;
1670- virtual QString printerAddOptionDefault(const QString &name,
1671- const QString &option,
1672- const QStringList &values) override;
1673- virtual QString printerDeleteOptionDefault(const QString &name,
1674- const QString &value) override;
1675- virtual QString printerAddOption(const QString &name,
1676- const QString &option,
1677- const QStringList &values) override;
1678- virtual QVariant printerGetOption(const QString &name,
1679- const QString &option) override;
1680- virtual QMap<QString, QVariant> printerGetOptions(
1681- const QString &name, const QStringList &options
1682- ) override;
1683- virtual QList<ColorModel> printerGetSupportedColorModels(
1684- const QString &name) const override;
1685- virtual QList<PrintQuality> printerGetSupportedQualities(
1686- const QString &name) const override;
1687- virtual cups_dest_t* makeDest(const QString &name,
1688- const PrinterJob *options) override;
1689-
1690- virtual int printFileToDest(const QString &filepath,
1691- const QString &title,
1692- const cups_dest_t *dest) override;
1693-private:
1694- QString getPrinterName(const QString &name) const;
1695- QString getPrinterInstance(const QString &name) const;
1696- QStringList parsePpdColorModel(const QString &colorModel);
1697- const QStringList m_knownQualityOptions = QStringList({
1698- "Quality", "PrintQuality", "HPPrintQuality", "StpQuality",
1699- "OutputMode",
1700- });
1701- CupsPkHelper helper;
1702-};
1703-
1704-#endif // USC_PRINTERS_CUPSFACADE_IMPL_H
1705
1706=== modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp'
1707--- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-19 21:02:07 +0000
1708+++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-23 14:09:24 +0000
1709@@ -16,47 +16,32 @@
1710
1711 #include "utils.h"
1712
1713-#include "cups/cupsfacade_impl.h"
1714+#include "backend/backend_cups.h"
1715+#include "cups/cupsfacade.h"
1716 #include "models/printermodel.h"
1717-#include "models/printermodel_p.h"
1718-#include "printer/printerinfo_allimpl.h"
1719
1720 #include <QDebug>
1721
1722-PrinterModel::PrinterModel(int timerMsec, QObject *parent)
1723- : QAbstractListModel(parent)
1724- , d_ptr(new PrinterModelPrivate(this))
1725-{
1726- update();
1727- startUpdateTimer(timerMsec);
1728-}
1729-
1730-PrinterModel::PrinterModel(PrinterInfo *info, CupsFacade *cups, int timerMsec, QObject *parent)
1731- : QAbstractListModel(parent)
1732- , d_ptr(new PrinterModelPrivate(this, info, cups))
1733-{
1734- update();
1735- startUpdateTimer(timerMsec);
1736-}
1737-
1738-PrinterModelPrivate::PrinterModelPrivate(PrinterModel *q)
1739-{
1740- this->info = new PrinterInfoAllImpl;
1741- this->cups = new CupsFacadeImpl;
1742-}
1743-
1744-PrinterModelPrivate::PrinterModelPrivate(PrinterModel *q, PrinterInfo *info, CupsFacade *cups)
1745-{
1746- this->info = info;
1747- this->cups = cups;
1748+PrinterModel::PrinterModel(const int updateIntervalMSecs, QObject *parent)
1749+ : PrinterModel(new PrinterCupsBackend, updateIntervalMSecs, parent)
1750+{
1751+}
1752+
1753+PrinterModel::PrinterModel(PrinterBackend *backend,
1754+ const int updateIntervalMSecs,
1755+ QObject *parent)
1756+ : QAbstractListModel(parent)
1757+ , m_backend(backend)
1758+{
1759+ update();
1760+ startUpdateTimer(updateIntervalMSecs);
1761 }
1762
1763 PrinterModel::~PrinterModel()
1764 {
1765-
1766 }
1767
1768-void PrinterModel::startUpdateTimer(int msecs)
1769+void PrinterModel::startUpdateTimer(const int &msecs)
1770 {
1771 // Start a timer to poll for changes in the printers
1772 m_update_timer.setParent(this);
1773@@ -66,19 +51,22 @@
1774
1775 void PrinterModel::update()
1776 {
1777- Q_D(PrinterModel);
1778-
1779 // Store the old count and get the new printers
1780- int oldCount = d->printers.size();
1781- QList<PrinterInfo *> newPrinters = d->info->availablePrinters();
1782+ int oldCount = m_printers.size();
1783+ QList<Printer*> newPrinters = m_backend->availablePrinters();
1784+
1785+ /* If any printers returned from the backend are irrelevant, we delete
1786+ them. This a list of indices that corresponds to printers scheduled for
1787+ deletion in newPrinters. */
1788+ QList<uint> forDeletion;
1789
1790 // Go through the old model
1791- for (int i=0; i < d->printers.count(); i++) {
1792+ for (int i=0; i < m_printers.count(); i++) {
1793 // Determine if the old printer exists in the new model
1794 bool exists = false;
1795
1796- Q_FOREACH(PrinterInfo *p, newPrinters) {
1797- if (p->printerName() == d->printers.at(i)->name()) {
1798+ Q_FOREACH(Printer *p, newPrinters) {
1799+ if (p->name() == m_printers.at(i)->name()) {
1800 exists = true;
1801 break;
1802 }
1803@@ -87,7 +75,8 @@
1804 // If it doesn't exist then remove it from the old model
1805 if (!exists) {
1806 beginRemoveRows(QModelIndex(), i, i);
1807- d->printers.removeAt(i);
1808+ Printer *p = m_printers.takeAt(i);
1809+ p->deleteLater();
1810 endRemoveRows();
1811
1812 i--; // as we have removed an item decrement
1813@@ -100,9 +89,10 @@
1814 bool exists = false;
1815 int j;
1816
1817- for (j=0; j < d->printers.count(); j++) {
1818- if (d->printers.at(j)->name() == newPrinters.at(i)->printerName()) {
1819+ for (j=0; j < m_printers.count(); j++) {
1820+ if (m_printers.at(j)->name() == newPrinters.at(i)->name()) {
1821 exists = true;
1822+ forDeletion << i;
1823 break;
1824 }
1825 }
1826@@ -113,21 +103,25 @@
1827 } else {
1828 // New printer does exist but needs to be moved in old model
1829 beginMoveRows(QModelIndex(), j, 1, QModelIndex(), i);
1830- d->printers.move(j, i);
1831+ m_printers.move(j, i);
1832 endMoveRows();
1833 }
1834+
1835+ // We can safely delete the newPrinter as it already exists.
1836+ forDeletion << i;
1837 } else {
1838 // New printer does not exist insert into model
1839 beginInsertRows(QModelIndex(), i, i);
1840- QSharedPointer<Printer> printer = QSharedPointer<Printer>(
1841- new Printer(newPrinters.at(i), d->cups)
1842- );
1843- d->printers.insert(i, printer);
1844+ m_printers.insert(i, newPrinters.at(i));
1845 endInsertRows();
1846 }
1847 }
1848
1849- if (oldCount != d->printers.size()) {
1850+ Q_FOREACH(const int &index, forDeletion) {
1851+ newPrinters.at(index)->deleteLater();
1852+ }
1853+
1854+ if (oldCount != m_printers.size()) {
1855 Q_EMIT countChanged();
1856 }
1857 }
1858@@ -135,8 +129,7 @@
1859 int PrinterModel::rowCount(const QModelIndex &parent) const
1860 {
1861 Q_UNUSED(parent);
1862- Q_D(const PrinterModel);
1863- return d->printers.size();
1864+ return m_printers.size();
1865 }
1866
1867 int PrinterModel::count() const
1868@@ -146,12 +139,11 @@
1869
1870 QVariant PrinterModel::data(const QModelIndex &index, int role) const
1871 {
1872- Q_D(const PrinterModel);
1873 QVariant ret;
1874
1875- if ((0<=index.row()) && (index.row()<d->printers.size())) {
1876+ if ((0<=index.row()) && (index.row()<m_printers.size())) {
1877
1878- auto printer = d->printers[index.row()];
1879+ auto printer = m_printers[index.row()];
1880
1881 switch (role) {
1882 case NameRole:
1883@@ -229,8 +221,7 @@
1884 // ret = printer->state();
1885 // break;
1886 case PrinterRole:
1887- // TODO: figure out how crazy this is...
1888- ret = QVariant::fromValue(printer.data());
1889+ ret = QVariant::fromValue(printer);
1890 break;
1891 case IsPdfRole:
1892 ret = printer->isPdf();
1893@@ -244,13 +235,12 @@
1894 return ret;
1895 }
1896
1897-bool PrinterModel::setData(const QModelIndex &index, const QVariant &value, int role)
1898+bool PrinterModel::setData(const QModelIndex &index,
1899+ const QVariant &value, int role)
1900 {
1901- Q_D(const PrinterModel);
1902-
1903- if ((0<=index.row()) && (index.row()<d->printers.size())) {
1904-
1905- auto printer = d->printers[index.row()];
1906+ if ((0<=index.row()) && (index.row()<m_printers.size())) {
1907+
1908+ auto printer = m_printers[index.row()];
1909
1910 switch (role) {
1911 case ColorModelRole: {
1912@@ -341,10 +331,10 @@
1913 return result;
1914 }
1915
1916-QSharedPointer<Printer> PrinterModel::getPrinterFromName(const QString &name)
1917+Printer* PrinterModel::getPrinterFromName(const QString &name)
1918 {
1919 Q_UNUSED(name);
1920- return QSharedPointer<Printer>(nullptr);
1921+ return Q_NULLPTR;
1922 }
1923
1924 PrinterFilter::PrinterFilter(QObject *parent) : QSortFilterProxyModel(parent)
1925
1926=== modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.h'
1927--- plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-19 21:02:07 +0000
1928+++ plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-23 14:09:24 +0000
1929@@ -29,15 +29,14 @@
1930 #include <QTimer>
1931 #include <QVariant>
1932
1933-class PrinterModelPrivate;
1934 class PRINTERS_DECL_EXPORT PrinterModel : public QAbstractListModel
1935 {
1936 Q_OBJECT
1937- Q_DECLARE_PRIVATE(PrinterModel)
1938 Q_PROPERTY(int count READ count NOTIFY countChanged)
1939 public:
1940- explicit PrinterModel(int timerMsec=5000, QObject *parent = 0);
1941- explicit PrinterModel(PrinterInfo *info, CupsFacade *cups, int timerMsec=5000, QObject *parent = 0);
1942+ explicit PrinterModel(const int updateIntervalMSecs=5000, QObject *parent = Q_NULLPTR);
1943+ explicit PrinterModel(PrinterBackend *backend, const int updateIntervalMSecs=5000,
1944+ QObject *parent = Q_NULLPTR);
1945 ~PrinterModel();
1946
1947 enum Roles
1948@@ -75,15 +74,19 @@
1949
1950 int count() const;
1951
1952- QSharedPointer<Printer> getPrinterFromName(const QString &name);
1953+ Printer* getPrinterFromName(const QString &name);
1954
1955 Q_INVOKABLE QVariantMap get(const int row) const;
1956 private:
1957- QScopedPointer<PrinterModelPrivate> const d_ptr;
1958 QTimer m_update_timer;
1959+ PrinterBackend *m_backend;
1960+
1961+ /* FIXME: there's currently no need to share the Printer obj with QML, so
1962+ this should be normal pointers that are deletedLater. */
1963+ QList<Printer*> m_printers;
1964
1965 private Q_SLOTS:
1966- void startUpdateTimer(int msecs);
1967+ void startUpdateTimer(const int &msecs);
1968 void update();
1969
1970 Q_SIGNALS:
1971
1972=== removed file 'plugins/Ubuntu/Settings/Printers/models/printermodel_p.h'
1973--- plugins/Ubuntu/Settings/Printers/models/printermodel_p.h 2017-01-18 16:18:40 +0000
1974+++ plugins/Ubuntu/Settings/Printers/models/printermodel_p.h 1970-01-01 00:00:00 +0000
1975@@ -1,35 +0,0 @@
1976-/*
1977- * Copyright (C) 2017 Canonical, Ltd.
1978- *
1979- * This program is free software; you can redistribute it and/or modify
1980- * it under the terms of the GNU Lesser General Public License as published by
1981- * the Free Software Foundation; version 3.
1982- *
1983- * This program is distributed in the hope that it will be useful,
1984- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1985- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1986- * GNU Lesser General Public License for more details.
1987- *
1988- * You should have received a copy of the GNU Lesser General Public License
1989- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1990- */
1991-
1992-#ifndef USC_PRINTERS_PRINTERMODELPRIVATE_H
1993-#define USC_PRINTERS_PRINTERMODELPRIVATE_H
1994-
1995-struct PrinterModelPrivate
1996-{
1997- Q_DISABLE_COPY(PrinterModelPrivate)
1998- Q_DECLARE_PUBLIC(PrinterModel)
1999- explicit PrinterModelPrivate(PrinterModel *q);
2000- explicit PrinterModelPrivate(PrinterModel *q, PrinterInfo *info, CupsFacade *cups);
2001- CupsFacade *cups;
2002- PrinterModel *q_ptr;
2003- PrinterInfo *info;
2004-
2005- /* FIXME: there's currently no need to share the Printer obj with QML, so
2006- this should be normal pointers that are deletedLater. */
2007- QList<QSharedPointer<Printer>> printers;
2008-};
2009-
2010-#endif // USC_PRINTERS_PRINTERMODELPRIVATE_H
2011
2012=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.cpp'
2013--- plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-20 12:08:00 +0000
2014+++ plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-23 14:09:24 +0000
2015@@ -17,83 +17,43 @@
2016 #include "utils.h"
2017
2018 #include "printer.h"
2019-#include "printer_p.h"
2020
2021 #include <QDebug>
2022
2023 Printer::Printer(QObject *parent)
2024 : QObject(parent)
2025- , d_ptr(new PrinterPrivate(this))
2026 {
2027+ // TODO: remove this constructor.
2028 }
2029
2030-Printer::Printer(PrinterInfo *info, CupsFacade *cups, QObject *parent)
2031+Printer::Printer(PrinterBackend *backend, QObject *parent)
2032 : QObject(parent)
2033- , d_ptr(new PrinterPrivate(this, info, cups))
2034+ , m_backend(backend)
2035 {
2036+ loadColorModel();
2037+ loadPrintQualities();
2038 }
2039
2040 Printer::~Printer()
2041 {
2042-
2043-}
2044-
2045-PrinterPrivate::PrinterPrivate(Printer *q)
2046-{
2047- loadColorModel();
2048- loadPrintQualities();
2049-}
2050-
2051-PrinterPrivate::PrinterPrivate(Printer *q, PrinterInfo *info, CupsFacade *cups)
2052-{
2053- this->info = info;
2054- this->cups = cups;
2055-
2056- loadColorModel();
2057- loadPrintQualities();
2058-}
2059-
2060-PrinterPrivate::~PrinterPrivate()
2061-{
2062- delete this->info;
2063-}
2064-
2065-void PrinterPrivate::loadColorModel()
2066-{
2067- if (!this->info->isPdf()) {
2068- QStringList opts({"DefaultColorModel"});
2069- auto name = this->info->printerName();
2070- auto vals = this->cups->printerGetOptions(name, opts);
2071- m_defaultColorModel = vals["DefaultColorModel"].value<ColorModel>();
2072-
2073- m_supportedColorModels = this->cups->printerGetSupportedColorModels(name);
2074-
2075- if (m_supportedColorModels.size() == 0) {
2076- m_supportedColorModels.append(m_defaultColorModel);
2077- }
2078- } else {
2079- ColorModel rgb;
2080- rgb.colorType = PrinterEnum::ColorModelType::ColorType;
2081- rgb.name = "RGB";
2082- rgb.text = "Color";
2083-
2084- m_defaultColorModel = rgb;
2085- m_supportedColorModels = QList<ColorModel>{rgb};
2086- }
2087-}
2088-
2089-void PrinterPrivate::loadPrintQualities()
2090-{
2091- if (!this->info->isPdf()) {
2092- QString name = this->info->printerName();
2093- m_defaultPrintQuality = this->cups->printerGetOption(
2094- name, "DefaultPrintQuality").value<PrintQuality>();
2095- m_supportedPrintQualities = this->cups->printerGetSupportedQualities(name);
2096- } else {
2097- PrintQuality quality;
2098- m_defaultPrintQuality = quality;
2099- m_supportedPrintQualities = QList<PrintQuality>({quality});
2100- }
2101+ m_backend->deleteLater();
2102+}
2103+
2104+void Printer::loadColorModel()
2105+{
2106+ m_supportedColorModels = m_backend->printerGetSupportedColorModels(name());
2107+ m_defaultColorModel = m_backend->printerGetDefaultColorModel(name());
2108+
2109+ if (m_supportedColorModels.size() == 0) {
2110+ m_supportedColorModels.append(m_defaultColorModel);
2111+ }
2112+}
2113+
2114+void Printer::loadPrintQualities()
2115+{
2116+ m_supportedPrintQualities = m_backend->printerGetSupportedQualities(name());
2117+ m_defaultPrintQuality = m_backend->printerGetDefaultQuality(name());
2118+
2119 if (m_supportedPrintQualities.size() == 0) {
2120 m_supportedPrintQualities.append(m_defaultPrintQuality);
2121 }
2122@@ -101,37 +61,31 @@
2123
2124 ColorModel Printer::defaultColorModel() const
2125 {
2126- Q_D(const Printer);
2127- return d->m_defaultColorModel;
2128+ return m_defaultColorModel;
2129 }
2130
2131 QList<ColorModel> Printer::supportedColorModels() const
2132 {
2133- Q_D(const Printer);
2134- return d->m_supportedColorModels;
2135+ return m_supportedColorModels;
2136 }
2137
2138 PrintQuality Printer::defaultPrintQuality() const
2139 {
2140- Q_D(const Printer);
2141- return d->m_defaultPrintQuality;
2142+ return m_defaultPrintQuality;
2143 }
2144
2145 QList<PrintQuality> Printer::supportedPrintQualities() const
2146 {
2147- Q_D(const Printer);
2148- return d->m_supportedPrintQualities;
2149+ return m_supportedPrintQualities;
2150 }
2151
2152 QList<PrinterEnum::DuplexMode> Printer::supportedDuplexModes() const
2153 {
2154- Q_D(const Printer);
2155- return d->info->supportedDuplexModes();
2156+ return m_backend->supportedDuplexModes();
2157 }
2158
2159 QStringList Printer::supportedDuplexStrings() const
2160 {
2161- Q_D(const Printer);
2162 QStringList list;
2163 Q_FOREACH(const PrinterEnum::DuplexMode &mode, supportedDuplexModes()) {
2164 list << Utils::duplexModeToUIString(mode);
2165@@ -141,8 +95,7 @@
2166
2167 PrinterEnum::DuplexMode Printer::defaultDuplexMode() const
2168 {
2169- Q_D(const Printer);
2170- return d->info->defaultDuplexMode();
2171+ return m_backend->defaultDuplexMode();
2172 }
2173
2174 PrinterJob *Printer::job()
2175@@ -152,36 +105,30 @@
2176
2177 int Printer::printFile(const QString &filepath, const PrinterJob *options)
2178 {
2179- Q_D(const Printer);
2180-
2181- auto dest = d->cups->makeDest(this->name(), options); // options could be QMap<QString, QString> ?
2182+ auto dest = m_backend->makeDest(name(), options); // options could be QMap<QString, QString> ?
2183
2184 qDebug() << "Going to print:" << filepath << options->title();
2185- return d->cups->printFileToDest(filepath, options->title(), dest);
2186+ return m_backend->printFileToDest(filepath, options->title(), dest);
2187 }
2188
2189 QString Printer::name() const
2190 {
2191- Q_D(const Printer);
2192- return d->info->printerName();
2193+ return m_backend->printerName();
2194 }
2195
2196 QString Printer::description() const
2197 {
2198- Q_D(const Printer);
2199- return d->info->description();
2200+ return m_backend->description();
2201 }
2202
2203 QPageSize Printer::defaultPageSize() const
2204 {
2205- Q_D(const Printer);
2206- return d->info->defaultPageSize();
2207+ return m_backend->defaultPageSize();
2208 }
2209
2210 QList<QPageSize> Printer::supportedPageSizes() const
2211 {
2212- Q_D(const Printer);
2213- return d->info->supportedPageSizes();
2214+ return m_backend->supportedPageSizes();
2215 }
2216
2217 PrinterEnum::AccessControl Printer::accessControl() const
2218@@ -216,20 +163,16 @@
2219
2220 bool Printer::isDefault()
2221 {
2222- Q_D(Printer);
2223- return name() == d->info->defaultPrinterName();
2224+ return name() == m_backend->defaultPrinterName();
2225 }
2226
2227 bool Printer::isPdf()
2228 {
2229- Q_D(Printer);
2230- return d->info->isPdf();
2231+ return m_backend->backendType() == PrinterBackend::BackendType::PdfType;
2232 }
2233
2234 void Printer::setDefaultColorModel(const ColorModel &colorModel)
2235 {
2236- Q_D(Printer);
2237-
2238 if (defaultColorModel() == colorModel) {
2239 return;
2240 }
2241@@ -240,10 +183,10 @@
2242 }
2243
2244 QStringList vals({colorModel.name});
2245- QString reply = d->cups->printerAddOption(name(), "ColorModel", vals);
2246+ QString reply = m_backend->printerAddOption(name(), "ColorModel", vals);
2247 Q_UNUSED(reply);
2248
2249- d->loadColorModel();
2250+ loadColorModel();
2251 Q_EMIT defaultColorModelChanged();
2252 }
2253
2254@@ -254,30 +197,27 @@
2255
2256 void Printer::setDescription(const QString &description)
2257 {
2258- Q_D(const Printer);
2259- QString answer = d->cups->printerSetInfo(d->info->printerName(), description);
2260+ QString answer = m_backend->printerSetInfo(name(), description);
2261
2262- d->info->refresh();
2263+ m_backend->refresh();
2264 Q_EMIT descriptionChanged();
2265 }
2266
2267 void Printer::setDefaultDuplexMode(const PrinterEnum::DuplexMode &duplexMode)
2268 {
2269- Q_D(Printer);
2270-
2271 if (defaultDuplexMode() == duplexMode) {
2272 return;
2273 }
2274
2275- if (!d->info->supportedDuplexModes().contains(duplexMode)) {
2276+ if (!m_backend->supportedDuplexModes().contains(duplexMode)) {
2277 qWarning() << Q_FUNC_INFO << "duplex mode not supported";
2278 return;
2279 }
2280
2281 QStringList vals({Utils::duplexModeToPpdChoice(duplexMode)});
2282- QString reply = d->cups->printerAddOption(name(), "Duplex", vals);
2283+ QString reply = m_backend->printerAddOption(name(), "Duplex", vals);
2284
2285- d->info->refresh();
2286+ m_backend->refresh();
2287 Q_EMIT defaultDuplexModeChanged();
2288 }
2289
2290@@ -298,8 +238,6 @@
2291
2292 void Printer::setDefaultPrintQuality(const PrintQuality &quality)
2293 {
2294- Q_D(Printer);
2295-
2296 if (defaultPrintQuality() == quality) {
2297 return;
2298 }
2299@@ -310,19 +248,17 @@
2300 }
2301
2302 QStringList vals({quality.name});
2303- QString reply = d->cups->printerAddOption(name(), quality.originalOption, vals);
2304- d->loadPrintQualities();
2305+ QString reply = m_backend->printerAddOption(name(), quality.originalOption, vals);
2306+ loadPrintQualities();
2307 }
2308
2309 void Printer::setDefaultPageSize(const QPageSize &pageSize)
2310 {
2311- Q_D(Printer);
2312-
2313 if (defaultPageSize() == pageSize) {
2314 return;
2315 }
2316
2317- if (!d->info->supportedPageSizes().contains(pageSize)) {
2318+ if (!m_backend->supportedPageSizes().contains(pageSize)) {
2319 qWarning() << Q_FUNC_INFO << "pagesize not supported.";
2320 return;
2321 }
2322@@ -333,9 +269,9 @@
2323 }
2324
2325 QStringList vals({pageSize.key()});
2326- QString reply = d->cups->printerAddOption(name(), "PageSize", vals);
2327+ QString reply = m_backend->printerAddOption(name(), "PageSize", vals);
2328
2329- d->info->refresh();
2330+ m_backend->refresh();
2331 Q_EMIT defaultPageSizeChanged();
2332 }
2333
2334
2335=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.h'
2336--- plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-19 21:02:07 +0000
2337+++ plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-23 14:09:24 +0000
2338@@ -19,9 +19,8 @@
2339
2340 #include "printers_global.h"
2341
2342-#include "cups/cupsfacade.h"
2343+#include "backend/backend.h"
2344 #include "enums.h"
2345-#include "printer/printerinfo.h"
2346 #include "printer/printerjob.h"
2347 #include "structs.h"
2348
2349@@ -32,32 +31,14 @@
2350 #include <QString>
2351 #include <QStringList>
2352
2353-class CupsFacade;
2354+class PrinterBackend;
2355 class PrinterJob;
2356-
2357-class PrinterPrivate;
2358 class PRINTERS_DECL_EXPORT Printer : public QObject
2359 {
2360 Q_OBJECT
2361- Q_DECLARE_PRIVATE(Printer)
2362- Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
2363- Q_PROPERTY(ColorModel defaultColorModel READ defaultColorModel WRITE setDefaultColorModel NOTIFY defaultColorModelChanged)
2364- Q_PROPERTY(QStringList supportedDuplexStrings READ supportedDuplexStrings CONSTANT)
2365- Q_PROPERTY(PrinterEnum::DuplexMode defaultDuplexMode READ defaultDuplexMode WRITE setDefaultDuplexMode NOTIFY defaultDuplexModeChanged)
2366- Q_PROPERTY(QString name READ name NOTIFY nameChanged)
2367- Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
2368- Q_PROPERTY(QPageSize defaultPageSize READ defaultPageSize WRITE setDefaultPageSize NOTIFY defaultPageSizeChanged)
2369- Q_PROPERTY(QList<QPageSize> supportedPageSizes READ supportedPageSizes CONSTANT)
2370- Q_PROPERTY(PrinterEnum::AccessControl accessControl READ accessControl WRITE setAccessControl NOTIFY accessControlChanged)
2371- Q_PROPERTY(PrinterEnum::ErrorPolicy errorPolicy READ errorPolicy WRITE setErrorPolicy NOTIFY errorPolicyChanged)
2372- Q_PROPERTY(QStringList users READ users NOTIFY usersChanged)
2373- Q_PROPERTY(PrinterEnum::State state READ state NOTIFY stateChanged)
2374- Q_PROPERTY(QString lastStateMessage READ lastStateMessage NOTIFY lastStateMessageChanged)
2375-
2376- QScopedPointer<PrinterPrivate> const d_ptr;
2377 public:
2378 explicit Printer(QObject *parent = nullptr);
2379- explicit Printer(PrinterInfo *info, CupsFacade *cups, QObject *parent = nullptr);
2380+ explicit Printer(PrinterBackend *backend, QObject *parent = nullptr);
2381 ~Printer();
2382
2383 bool enabled() const;
2384@@ -124,6 +105,16 @@
2385
2386 // Signals that some printer setting was changed.
2387 void printerChanged();
2388+
2389+private:
2390+ void loadColorModel();
2391+ void loadPrintQualities();
2392+
2393+ PrinterBackend *m_backend;
2394+ ColorModel m_defaultColorModel;
2395+ QList<ColorModel> m_supportedColorModels;
2396+ PrintQuality m_defaultPrintQuality;
2397+ QList<PrintQuality> m_supportedPrintQualities;
2398 };
2399
2400 // FIXME: not necessary outside tests
2401
2402=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printer_p.h'
2403--- plugins/Ubuntu/Settings/Printers/printer/printer_p.h 2017-01-19 21:00:28 +0000
2404+++ plugins/Ubuntu/Settings/Printers/printer/printer_p.h 1970-01-01 00:00:00 +0000
2405@@ -1,41 +0,0 @@
2406-/*
2407- * Copyright (C) 2017 Canonical, Ltd.
2408- *
2409- * This program is free software; you can redistribute it and/or modify
2410- * it under the terms of the GNU Lesser General Public License as published by
2411- * the Free Software Foundation; version 3.
2412- *
2413- * This program is distributed in the hope that it will be useful,
2414- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2415- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2416- * GNU Lesser General Public License for more details.
2417- *
2418- * You should have received a copy of the GNU Lesser General Public License
2419- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2420- */
2421-
2422-#ifndef USC_PRINTERS_PRINTERPRIVATE_H
2423-#define USC_PRINTERS_PRINTERPRIVATE_H
2424-
2425-struct PrinterPrivate
2426-{
2427- Q_DISABLE_COPY(PrinterPrivate)
2428- Q_DECLARE_PUBLIC(Printer)
2429- explicit PrinterPrivate(Printer *q);
2430- explicit PrinterPrivate(Printer *q, PrinterInfo *info, CupsFacade *cups);
2431- ~PrinterPrivate();
2432- void loadColorModel();
2433- void loadPrintQualities();
2434-
2435- CupsFacade *cups;
2436- Printer *q_ptr;
2437- PrinterInfo *info;
2438-
2439- ColorModel m_defaultColorModel;
2440- QList<ColorModel> m_supportedColorModels;
2441-
2442- PrintQuality m_defaultPrintQuality;
2443- QList<PrintQuality> m_supportedPrintQualities;
2444-};
2445-
2446-#endif // USC_PRINTERS_PRINTERPRIVATE_H
2447
2448=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo.h'
2449--- plugins/Ubuntu/Settings/Printers/printer/printerinfo.h 2017-01-19 17:59:17 +0000
2450+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo.h 1970-01-01 00:00:00 +0000
2451@@ -1,67 +0,0 @@
2452-/*
2453- * Copyright (C) 2017 Canonical, Ltd.
2454- *
2455- * This program is free software; you can redistribute it and/or modify
2456- * it under the terms of the GNU Lesser General Public License as published by
2457- * the Free Software Foundation; version 3.
2458- *
2459- * This program is distributed in the hope that it will be useful,
2460- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2461- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2462- * GNU Lesser General Public License for more details.
2463- *
2464- * You should have received a copy of the GNU Lesser General Public License
2465- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2466- */
2467-
2468-#ifndef USC_PRINTERS_PRINTERINFO_H
2469-#define USC_PRINTERS_PRINTERINFO_H
2470-
2471-#include "enums.h"
2472-
2473-#include <QPageSize>
2474-#include <QList>
2475-#include <QString>
2476-#include <QStringList>
2477-
2478-class PrinterInfo
2479-{
2480-public:
2481- explicit PrinterInfo(const QString &name = QString::null)
2482- : m_printerName(name) {};
2483- virtual ~PrinterInfo() {};
2484-
2485- virtual bool holdsDefinition() const = 0;
2486-
2487- virtual QString printerName() const = 0;
2488- virtual QString description() const = 0;
2489- virtual QString location() const = 0;
2490- virtual QString makeAndModel() const = 0;
2491-
2492- virtual PrinterEnum::State state() const = 0;
2493- virtual QList<QPageSize> supportedPageSizes() const = 0;
2494- virtual QPageSize defaultPageSize() const = 0;
2495- virtual bool supportsCustomPageSizes() const = 0;
2496-
2497- virtual QPageSize minimumPhysicalPageSize() const = 0;
2498- virtual QPageSize maximumPhysicalPageSize() const = 0;
2499- virtual QList<int> supportedResolutions() const = 0;
2500- virtual PrinterEnum::DuplexMode defaultDuplexMode() const = 0;
2501- virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const = 0;
2502-
2503- virtual QList<PrinterInfo*> availablePrinters() = 0;
2504- virtual QStringList availablePrinterNames() = 0;
2505- virtual PrinterInfo* printerInfo(const QString &printerName) = 0;
2506- virtual QString defaultPrinterName() = 0;
2507-
2508- virtual bool isPdf() const = 0;
2509-
2510- virtual void refresh() = 0;
2511-protected:
2512- const QString m_printerName;
2513-
2514-};
2515-
2516-Q_DECLARE_TYPEINFO(PrinterInfo, Q_MOVABLE_TYPE);
2517-
2518-#endif // USC_PRINTERS_PRINTERINFO_H
2519
2520=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp'
2521--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp 2017-01-19 17:59:17 +0000
2522+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.cpp 1970-01-01 00:00:00 +0000
2523@@ -1,39 +0,0 @@
2524-/*
2525- * Copyright (C) 2017 Canonical, Ltd.
2526- *
2527- * This program is free software; you can redistribute it and/or modify
2528- * it under the terms of the GNU Lesser General Public License as published by
2529- * the Free Software Foundation; version 3.
2530- *
2531- * This program is distributed in the hope that it will be useful,
2532- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2533- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2534- * GNU Lesser General Public License for more details.
2535- *
2536- * You should have received a copy of the GNU Lesser General Public License
2537- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2538- */
2539-
2540-#include "printer/printerinfo_allimpl.h"
2541-
2542-#include "printer/printerinfo_impl.h"
2543-#include "printer/printerinfo_pdfimpl.h"
2544-
2545-PrinterInfoAllImpl::PrinterInfoAllImpl(const QString &name) : PrinterInfo(name)
2546-{
2547- m_pdf_printers = new PrinterInfoPdfImpl();
2548- m_qt_printers = new PrinterInfoImpl();
2549-}
2550-
2551-PrinterInfoAllImpl::~PrinterInfoAllImpl()
2552-{
2553-
2554-}
2555-
2556-QList<PrinterInfo*> PrinterInfoAllImpl::availablePrinters()
2557-{
2558- QList<PrinterInfo*> list;
2559- list += m_pdf_printers->availablePrinters();
2560- list += m_qt_printers->availablePrinters();
2561- return list;
2562-}
2563
2564=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h'
2565--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h 2017-01-19 17:59:17 +0000
2566+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_allimpl.h 1970-01-01 00:00:00 +0000
2567@@ -1,58 +0,0 @@
2568-/*
2569- * Copyright (C) 2017 Canonical, Ltd.
2570- *
2571- * This program is free software; you can redistribute it and/or modify
2572- * it under the terms of the GNU Lesser General Public License as published by
2573- * the Free Software Foundation; version 3.
2574- *
2575- * This program is distributed in the hope that it will be useful,
2576- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2577- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2578- * GNU Lesser General Public License for more details.
2579- *
2580- * You should have received a copy of the GNU Lesser General Public License
2581- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2582- */
2583-
2584-#ifndef USC_PRINTERS_PRINTERINFO_ALLIMPL_H
2585-#define USC_PRINTERS_PRINTERINFO_ALLIMPL_H
2586-
2587-#include "printer/printerinfo.h"
2588-
2589-class PrinterInfoAllImpl : public PrinterInfo
2590-{
2591-public:
2592- explicit PrinterInfoAllImpl(const QString &name = QString::null);
2593- virtual ~PrinterInfoAllImpl() override;
2594-
2595- virtual bool holdsDefinition() const override {}
2596-
2597- virtual QString printerName() const override {}
2598- virtual QString description() const override {}
2599- virtual QString location() const override {}
2600- virtual QString makeAndModel() const override {}
2601-
2602- virtual PrinterEnum::State state() const override {}
2603- virtual QList<QPageSize> supportedPageSizes() const override {}
2604- virtual QPageSize defaultPageSize() const override {}
2605- virtual bool supportsCustomPageSizes() const override {}
2606-
2607- virtual QPageSize minimumPhysicalPageSize() const override {}
2608- virtual QPageSize maximumPhysicalPageSize() const override {}
2609- virtual QList<int> supportedResolutions() const override {}
2610- virtual PrinterEnum::DuplexMode defaultDuplexMode() const override {}
2611- virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override {}
2612- virtual QList<PrinterInfo*> availablePrinters() override;
2613- virtual QStringList availablePrinterNames() override {}
2614- virtual PrinterInfo* printerInfo(const QString &printerName) override {}
2615- virtual QString defaultPrinterName() override {}
2616-
2617- virtual bool isPdf() const override {}
2618-
2619- virtual void refresh() override {}
2620-private:
2621- PrinterInfo *m_pdf_printers;
2622- PrinterInfo *m_qt_printers;
2623-};
2624-
2625-#endif // USC_PRINTERS_PRINTERINFO_ALLIMPL_H
2626
2627=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp'
2628--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp 2017-01-19 17:59:17 +0000
2629+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.cpp 1970-01-01 00:00:00 +0000
2630@@ -1,152 +0,0 @@
2631-/*
2632- * Copyright (C) 2017 Canonical, Ltd.
2633- *
2634- * This program is free software; you can redistribute it and/or modify
2635- * it under the terms of the GNU Lesser General Public License as published by
2636- * the Free Software Foundation; version 3.
2637- *
2638- * This program is distributed in the hope that it will be useful,
2639- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2640- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2641- * GNU Lesser General Public License for more details.
2642- *
2643- * You should have received a copy of the GNU Lesser General Public License
2644- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2645- */
2646-
2647-#include "utils.h"
2648-
2649-#include "printer/printerinfo_impl.h"
2650-
2651-#include <QDebug>
2652-#include <QPrinter>
2653-
2654-PrinterInfoImpl::PrinterInfoImpl(const QString &name) : PrinterInfo(name)
2655-{
2656- refresh();
2657-}
2658-
2659-PrinterInfoImpl::PrinterInfoImpl(QPrinterInfo info)
2660- : PrinterInfo(info.isNull() ? QString::null : info.printerName())
2661- , m_info(info)
2662-{
2663-}
2664-
2665-PrinterInfoImpl::~PrinterInfoImpl()
2666-{
2667-
2668-}
2669-
2670-bool PrinterInfoImpl::holdsDefinition() const
2671-{
2672- return !m_info.isNull();
2673-}
2674-
2675-QString PrinterInfoImpl::printerName() const
2676-{
2677- return m_info.printerName();
2678-}
2679-
2680-QString PrinterInfoImpl::description() const
2681-{
2682- return m_info.description();
2683-}
2684-
2685-QString PrinterInfoImpl::location() const
2686-{
2687-
2688-}
2689-
2690-QString PrinterInfoImpl::makeAndModel() const
2691-{
2692-
2693-}
2694-
2695-PrinterEnum::State PrinterInfoImpl::state() const
2696-{
2697-
2698-}
2699-
2700-QList<QPageSize> PrinterInfoImpl::supportedPageSizes() const
2701-{
2702- return m_info.supportedPageSizes();
2703-}
2704-
2705-QPageSize PrinterInfoImpl::defaultPageSize() const
2706-{
2707- return m_info.defaultPageSize();
2708-}
2709-
2710-bool PrinterInfoImpl::supportsCustomPageSizes() const
2711-{
2712-
2713-}
2714-
2715-QPageSize PrinterInfoImpl::minimumPhysicalPageSize() const
2716-{
2717-
2718-}
2719-
2720-QPageSize PrinterInfoImpl::maximumPhysicalPageSize() const
2721-{
2722-
2723-}
2724-
2725-QList<int> PrinterInfoImpl::supportedResolutions() const
2726-{
2727-
2728-}
2729-
2730-PrinterEnum::DuplexMode PrinterInfoImpl::defaultDuplexMode() const
2731-{
2732- return Utils::qDuplexModeToDuplexMode(m_info.defaultDuplexMode());
2733-}
2734-
2735-QList<PrinterEnum::DuplexMode> PrinterInfoImpl::supportedDuplexModes() const
2736-{
2737- QList<PrinterEnum::DuplexMode> list;
2738- Q_FOREACH(const QPrinter::DuplexMode mode, m_info.supportedDuplexModes()) {
2739- if (mode != QPrinter::DuplexAuto) {
2740- list.append(Utils::qDuplexModeToDuplexMode(mode));
2741- }
2742- }
2743- return list;
2744-}
2745-
2746-QList<PrinterInfo*> PrinterInfoImpl::availablePrinters()
2747-{
2748- QList<PrinterInfo*> list;
2749- Q_FOREACH(QPrinterInfo info, QPrinterInfo::availablePrinters()) {
2750- list.append(new PrinterInfoImpl(info));
2751- }
2752- return list;
2753-}
2754-
2755-QStringList PrinterInfoImpl::availablePrinterNames()
2756-{
2757-
2758-}
2759-
2760-PrinterInfo* PrinterInfoImpl::printerInfo(const QString &printerName)
2761-{
2762-
2763-}
2764-
2765-QString PrinterInfoImpl::defaultPrinterName()
2766-{
2767- return QPrinterInfo::defaultPrinterName();
2768-}
2769-
2770-bool PrinterInfoImpl::isPdf() const
2771-{
2772- return false;
2773-}
2774-
2775-void PrinterInfoImpl::refresh()
2776-{
2777- if (m_printerName.isEmpty()) {
2778- m_info = QPrinterInfo();
2779- } else {
2780- m_info = QPrinterInfo::printerInfo(m_printerName);
2781- }
2782-}
2783
2784=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h'
2785--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h 2017-01-19 17:59:17 +0000
2786+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_impl.h 1970-01-01 00:00:00 +0000
2787@@ -1,62 +0,0 @@
2788-/*
2789- * Copyright (C) 2017 Canonical, Ltd.
2790- *
2791- * This program is free software; you can redistribute it and/or modify
2792- * it under the terms of the GNU Lesser General Public License as published by
2793- * the Free Software Foundation; version 3.
2794- *
2795- * This program is distributed in the hope that it will be useful,
2796- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2797- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2798- * GNU Lesser General Public License for more details.
2799- *
2800- * You should have received a copy of the GNU Lesser General Public License
2801- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2802- */
2803-
2804-#ifndef USC_PRINTERS_PRINTERINFO_IMPL_H
2805-#define USC_PRINTERS_PRINTERINFO_IMPL_H
2806-
2807-#include "cups/cupsfacade.h"
2808-#include "printer/printerinfo.h"
2809-
2810-#include <QPrinterInfo>
2811-
2812-class PrinterInfoImpl : public PrinterInfo
2813-{
2814-public:
2815- explicit PrinterInfoImpl(const QString &name = QString::null);
2816- explicit PrinterInfoImpl(QPrinterInfo info);
2817- virtual ~PrinterInfoImpl() override;
2818-
2819- virtual bool holdsDefinition() const override;
2820-
2821- virtual QString printerName() const override;
2822- virtual QString description() const override;
2823- virtual QString location() const override;
2824- virtual QString makeAndModel() const override;
2825-
2826- virtual PrinterEnum::State state() const override;
2827- virtual QList<QPageSize> supportedPageSizes() const override;
2828- virtual QPageSize defaultPageSize() const override;
2829- virtual bool supportsCustomPageSizes() const override;
2830-
2831- virtual QPageSize minimumPhysicalPageSize() const override;
2832- virtual QPageSize maximumPhysicalPageSize() const override;
2833- virtual QList<int> supportedResolutions() const override;
2834- virtual PrinterEnum::DuplexMode defaultDuplexMode() const override;
2835- virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override;
2836- virtual QList<PrinterInfo*> availablePrinters() override;
2837- virtual QStringList availablePrinterNames() override;
2838- virtual PrinterInfo* printerInfo(const QString &printerName) override;
2839- virtual QString defaultPrinterName() override;
2840-
2841- virtual bool isPdf() const override;
2842-
2843- virtual void refresh() override;
2844-
2845-private:
2846- QPrinterInfo m_info;
2847-};
2848-
2849-#endif // USC_PRINTERS_PRINTERINFO_IMPL_H
2850
2851=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp'
2852--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp 2017-01-19 17:59:17 +0000
2853+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.cpp 1970-01-01 00:00:00 +0000
2854@@ -1,91 +0,0 @@
2855-/*
2856- * Copyright (C) 2017 Canonical, Ltd.
2857- *
2858- * This program is free software; you can redistribute it and/or modify
2859- * it under the terms of the GNU Lesser General Public License as published by
2860- * the Free Software Foundation; version 3.
2861- *
2862- * This program is distributed in the hope that it will be useful,
2863- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2864- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2865- * GNU Lesser General Public License for more details.
2866- *
2867- * You should have received a copy of the GNU Lesser General Public License
2868- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2869- */
2870-
2871-#include "printer/printerinfo_pdfimpl.h"
2872-
2873-#include <QPageSize>
2874-
2875-PrinterInfoPdfImpl::PrinterInfoPdfImpl(const QString &name) : PrinterInfo(name)
2876-{
2877-
2878-}
2879-
2880-PrinterInfoPdfImpl::~PrinterInfoPdfImpl()
2881-{
2882-
2883-}
2884-
2885-QList<PrinterInfo*> PrinterInfoPdfImpl::availablePrinters()
2886-{
2887- QList<PrinterInfo*> list;
2888- list.append(new PrinterInfoPdfImpl("Create PDF"));
2889- return list;
2890-}
2891-
2892-PrinterEnum::DuplexMode PrinterInfoPdfImpl::defaultDuplexMode() const
2893-{
2894- return PrinterEnum::DuplexMode::DuplexNone;
2895-}
2896-
2897-QPageSize PrinterInfoPdfImpl::defaultPageSize() const
2898-{
2899- return QPageSize(QPageSize::A4);
2900-}
2901-
2902-QString PrinterInfoPdfImpl::defaultPrinterName()
2903-{
2904- return "";
2905-}
2906-
2907-QString PrinterInfoPdfImpl::description() const
2908-{
2909- return QStringLiteral("");
2910-}
2911-
2912-bool PrinterInfoPdfImpl::holdsDefinition() const
2913-{
2914- return true;
2915-}
2916-
2917-bool PrinterInfoPdfImpl::isPdf() const
2918-{
2919- return true;
2920-}
2921-
2922-QString PrinterInfoPdfImpl::location() const
2923-{
2924- return QStringLiteral("");
2925-}
2926-
2927-QString PrinterInfoPdfImpl::makeAndModel() const
2928-{
2929- return QStringLiteral("");
2930-}
2931-
2932-QString PrinterInfoPdfImpl::printerName() const
2933-{
2934- return m_printerName;
2935-}
2936-
2937-QList<PrinterEnum::DuplexMode> PrinterInfoPdfImpl::supportedDuplexModes() const
2938-{
2939- return QList<PrinterEnum::DuplexMode>{PrinterEnum::DuplexMode::DuplexNone};
2940-}
2941-
2942-QList<QPageSize> PrinterInfoPdfImpl::supportedPageSizes() const
2943-{
2944- return QList<QPageSize>{QPageSize(QPageSize::A4)};
2945-}
2946
2947=== removed file 'plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h'
2948--- plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h 2017-01-19 17:59:17 +0000
2949+++ plugins/Ubuntu/Settings/Printers/printer/printerinfo_pdfimpl.h 1970-01-01 00:00:00 +0000
2950@@ -1,55 +0,0 @@
2951-/*
2952- * Copyright (C) 2017 Canonical, Ltd.
2953- *
2954- * This program is free software; you can redistribute it and/or modify
2955- * it under the terms of the GNU Lesser General Public License as published by
2956- * the Free Software Foundation; version 3.
2957- *
2958- * This program is distributed in the hope that it will be useful,
2959- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2960- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2961- * GNU Lesser General Public License for more details.
2962- *
2963- * You should have received a copy of the GNU Lesser General Public License
2964- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2965- */
2966-
2967-#ifndef USC_PRINTERS_PRINTERINFO_PDFIMPL_H
2968-#define USC_PRINTERS_PRINTERINFO_PDFIMPL_H
2969-
2970-#include "printer/printerinfo.h"
2971-
2972-class PrinterInfoPdfImpl : public PrinterInfo
2973-{
2974-public:
2975- explicit PrinterInfoPdfImpl(const QString &name = QString::null);
2976- virtual ~PrinterInfoPdfImpl() override;
2977-
2978- virtual bool holdsDefinition() const override;
2979-
2980- virtual QString printerName() const override;
2981- virtual QString description() const override;
2982- virtual QString location() const override;
2983- virtual QString makeAndModel() const override;
2984-
2985- virtual PrinterEnum::State state() const override {}
2986- virtual QList<QPageSize> supportedPageSizes() const override;
2987- virtual QPageSize defaultPageSize() const override;
2988- virtual bool supportsCustomPageSizes() const override {}
2989-
2990- virtual QPageSize minimumPhysicalPageSize() const override {}
2991- virtual QPageSize maximumPhysicalPageSize() const override {}
2992- virtual QList<int> supportedResolutions() const override {}
2993- virtual PrinterEnum::DuplexMode defaultDuplexMode() const override;
2994- virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override;
2995- virtual QList<PrinterInfo*> availablePrinters() override;
2996- virtual QStringList availablePrinterNames() override {}
2997- virtual PrinterInfo* printerInfo(const QString &printerName) override {}
2998- virtual QString defaultPrinterName() override;
2999-
3000- virtual bool isPdf() const override;
3001-
3002- virtual void refresh() override {}
3003-};
3004-
3005-#endif // USC_PRINTERS_PRINTERINFO_PDFIMPL_H
3006
3007=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp'
3008--- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-19 21:18:36 +0000
3009+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-23 14:09:24 +0000
3010@@ -16,46 +16,39 @@
3011
3012 #include <QtCore/QDebug>
3013
3014-#include "cups/cupsfacade_impl.h"
3015+#include "backend/backend_cups.h"
3016 #include "models/printermodel.h"
3017 #include "printer/printerjob.h"
3018-#include "printer/printerinfo_allimpl.h"
3019
3020 PrinterJob::PrinterJob(QObject *parent)
3021+ : PrinterJob(Q_NULLPTR, parent)
3022+{
3023+}
3024+
3025+PrinterJob::PrinterJob(Printer *printer, QObject *parent)
3026+ : PrinterJob(printer, new PrinterCupsBackend, parent)
3027+{
3028+}
3029+
3030+PrinterJob::PrinterJob(Printer *printer, PrinterBackend *backend,
3031+ QObject *parent)
3032 : QObject(parent)
3033 , m_color_model(0)
3034 , m_copies(1)
3035- , m_cups(new CupsFacadeImpl())
3036+ , m_backend(backend)
3037 , m_duplex_mode(0)
3038- , m_printer(Q_NULLPTR)
3039+ , m_printer(printer)
3040 , m_printer_name(QStringLiteral(""))
3041 , m_print_range(QStringLiteral(""))
3042 , m_print_range_mode(PrinterEnum::PrintRange::AllPages)
3043 , m_quality(0)
3044- // TODO: Do we need a separate Job state?
3045- // NotStarted, InQueue, Processing, Complete, Error ?
3046- , m_state(PrinterEnum::State::IdleState)
3047- , m_title(QStringLiteral(""))
3048-{
3049-
3050-}
3051-
3052-PrinterJob::PrinterJob(Printer *printer, QObject *parent)
3053- : QObject(parent)
3054- , m_copies(1)
3055- , m_cups(new CupsFacadeImpl())
3056- , m_printer(printer)
3057- , m_printer_name(QStringLiteral(""))
3058- , m_print_range(QStringLiteral(""))
3059- , m_print_range_mode(PrinterEnum::PrintRange::AllPages)
3060- // TODO: Do we need a separate Job state?
3061- // NotStarted, InQueue, Processing, Complete, Error ?
3062 , m_state(PrinterEnum::State::IdleState)
3063 , m_title(QStringLiteral(""))
3064 {
3065 loadDefaults();
3066 }
3067
3068+
3069 PrinterJob::~PrinterJob()
3070 {
3071
3072@@ -88,11 +81,11 @@
3073
3074 ColorModel PrinterJob::getColorModel() const
3075 {
3076- ColorModel ret;
3077 if (m_printer && colorModel() > -1 && colorModel() < m_printer->supportedColorModels().count()) {
3078- ret = m_printer->supportedColorModels().at(colorModel());
3079+ return m_printer->supportedColorModels().at(colorModel());
3080+ } else {
3081+ return ColorModel();
3082 }
3083- return ret;
3084 }
3085
3086 PrintQuality PrinterJob::getPrintQuality() const
3087@@ -230,25 +223,19 @@
3088
3089 void PrinterJob::setPrinterName(const QString &printerName)
3090 {
3091+ // Please note the return inside the foreach.
3092 if (m_printer_name != printerName) {
3093- PrinterInfo *printers = new PrinterInfoAllImpl();
3094- PrinterInfo *info = Q_NULLPTR;
3095-
3096- Q_FOREACH(PrinterInfo *printer, printers->availablePrinters()) {
3097- if (printer->printerName() == printerName) {
3098- info = printer;
3099+ Q_FOREACH(Printer *printer, m_backend->availablePrinters()) {
3100+ if (printer->name() == printerName) {
3101+ m_printer_name = printerName;
3102+ m_printer = printer;
3103+ loadDefaults();
3104+ Q_EMIT printerNameChanged();
3105+ return;
3106 }
3107 }
3108
3109- if (info && info->holdsDefinition()) {
3110- m_printer_name = printerName;
3111- m_printer = new Printer(info, m_cups);
3112- loadDefaults();
3113-
3114- Q_EMIT printerNameChanged();
3115- } else {
3116- qWarning() << "Unknown printer:" << printerName;
3117- }
3118+ qWarning() << "Unknown printer:" << printerName;
3119 }
3120 }
3121
3122
3123=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.h'
3124--- plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-19 21:18:36 +0000
3125+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-23 14:09:24 +0000
3126@@ -22,13 +22,13 @@
3127 #include "enums.h"
3128 #include "structs.h"
3129
3130-#include "cups/cupsfacade.h"
3131+#include "backend/backend.h"
3132 #include "printer/printer.h"
3133
3134 #include <QtCore/QObject>
3135
3136-class CupsFacade;
3137 class Printer;
3138+class PrinterBackend;
3139
3140 class PRINTERS_DECL_EXPORT PrinterJob : public QObject
3141 {
3142@@ -49,6 +49,8 @@
3143 public:
3144 explicit PrinterJob(QObject *parent=Q_NULLPTR);
3145 explicit PrinterJob(Printer *printer, QObject *parent=Q_NULLPTR);
3146+ explicit PrinterJob(Printer *printer, PrinterBackend *backend,
3147+ QObject *parent=Q_NULLPTR);
3148 ~PrinterJob();
3149
3150 int colorModel() const;
3151@@ -98,7 +100,7 @@
3152 private:
3153 int m_color_model;
3154 int m_copies;
3155- CupsFacade *m_cups;
3156+ PrinterBackend *m_backend; // TODO: Maybe use the printer's backend?
3157 int m_duplex_mode;
3158 bool m_landscape;
3159 Printer *m_printer;
3160
3161=== modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.cpp'
3162--- plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-01-19 20:05:56 +0000
3163+++ plugins/Ubuntu/Settings/Printers/printers/printers.cpp 2017-01-23 14:09:24 +0000
3164@@ -14,72 +14,49 @@
3165 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3166 */
3167
3168-#include "cups/cupsfacade_impl.h"
3169-#include "printer/printerinfo_allimpl.h"
3170+#include "backend/backend_cups.h"
3171 #include "printers/printers.h"
3172-#include "printers/printers_p.h"
3173
3174 #include <QQmlEngine>
3175
3176 Printers::Printers(int printerUpdateIntervalMSecs, QObject *parent)
3177- : QObject(parent)
3178- , d_ptr(new PrintersPrivate(this, printerUpdateIntervalMSecs))
3179+ : Printers(new PrinterCupsBackend, printerUpdateIntervalMSecs, parent)
3180 {
3181 }
3182
3183-Printers::Printers(PrinterInfo *info, CupsFacade *cups,
3184- int printerUpdateIntervalMSecs, QObject *parent)
3185+Printers::Printers(PrinterBackend *backend, int printerUpdateIntervalMSecs,
3186+ QObject *parent)
3187 : QObject(parent)
3188- , d_ptr(new PrintersPrivate(this, info, cups, printerUpdateIntervalMSecs))
3189+ , m_backend(backend)
3190+ , m_model(backend, printerUpdateIntervalMSecs)
3191 {
3192+ m_allPrinters.setSourceModel(&m_model);
3193+ m_allPrinters.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
3194+ m_allPrinters.filterOnPdf(false);
3195+ m_allPrinters.sort(0, Qt::DescendingOrder);
3196+
3197+ m_allPrintersWithPdf.setSourceModel(&m_model);
3198+ m_allPrintersWithPdf.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
3199+ m_allPrintersWithPdf.sort(0, Qt::DescendingOrder);
3200+
3201+ // Let Qt be in charge of RAII.
3202+ m_backend->setParent(this);
3203 }
3204
3205 Printers::~Printers()
3206 {
3207 }
3208
3209-PrintersPrivate::PrintersPrivate(Printers *q, int printerUpdateIntervalMSecs)
3210- : PrintersPrivate(q, new PrinterInfoAllImpl, new CupsFacadeImpl,
3211- printerUpdateIntervalMSecs)
3212-{
3213-}
3214-
3215-PrintersPrivate::PrintersPrivate(Printers *q, PrinterInfo *info,
3216- CupsFacade *cups,
3217- int printerUpdateIntervalMSecs)
3218- : model(info, cups, printerUpdateIntervalMSecs)
3219-{
3220- this->info = info;
3221- this->cups = cups;
3222-
3223- allPrinters.setSourceModel(&model);
3224- allPrinters.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
3225- allPrinters.filterOnPdf(false);
3226- allPrinters.sort(0, Qt::DescendingOrder);
3227-
3228- allPrintersWithPdf.setSourceModel(&model);
3229- allPrintersWithPdf.setSortRole(PrinterModel::Roles::DefaultPrinterRole);
3230- allPrintersWithPdf.sort(0, Qt::DescendingOrder);
3231-}
3232-
3233-PrintersPrivate::~PrintersPrivate()
3234-{
3235- delete cups;
3236- delete info;
3237-}
3238-
3239 QAbstractItemModel* Printers::allPrinters()
3240 {
3241- Q_D(Printers);
3242- auto ret = &d->allPrinters;
3243+ auto ret = &m_allPrinters;
3244 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
3245 return ret;
3246 }
3247
3248 QAbstractItemModel* Printers::allPrintersWithPdf()
3249 {
3250- Q_D(Printers);
3251- auto ret = &d->allPrintersWithPdf;
3252+ auto ret = &m_allPrintersWithPdf;
3253 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
3254 return ret;
3255 }
3256
3257=== modified file 'plugins/Ubuntu/Settings/Printers/printers/printers.h'
3258--- plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-01-19 17:59:17 +0000
3259+++ plugins/Ubuntu/Settings/Printers/printers/printers.h 2017-01-23 14:09:24 +0000
3260@@ -22,7 +22,6 @@
3261 #include "cups/cupsfacade.h"
3262 #include "models/printermodel.h"
3263 #include "printer/printer.h"
3264-#include "printer/printerinfo.h"
3265
3266 #include <QAbstractItemModel>
3267 #include <QObject>
3268@@ -31,24 +30,20 @@
3269 #include <QString>
3270 #include <QUrl>
3271
3272-class PrintersPrivate;
3273 class PRINTERS_DECL_EXPORT Printers : public QObject
3274 {
3275 Q_OBJECT
3276- Q_DECLARE_PRIVATE(Printers)
3277 Q_PROPERTY(QAbstractItemModel* allPrinters READ allPrinters CONSTANT)
3278 Q_PROPERTY(QAbstractItemModel* allPrintersWithPdf READ allPrintersWithPdf CONSTANT)
3279 Q_PROPERTY(QAbstractItemModel* recentPrinters READ recentPrinters CONSTANT)
3280 Q_PROPERTY(QAbstractItemModel* printJobs READ printJobs CONSTANT)
3281 Q_PROPERTY(QString defaultPrinterName READ defaultPrinterName WRITE setDefaultPrinterName NOTIFY defaultPrinterNameChanged)
3282
3283- QScopedPointer<PrintersPrivate> const d_ptr;
3284-
3285 public:
3286 explicit Printers(int printerUpdateIntervalMSecs = 5000, QObject *parent = nullptr);
3287
3288- // Printers takes ownership of info and cups objects.
3289- explicit Printers(PrinterInfo *info, CupsFacade *cups,
3290+ // Note: Printers takes ownership of backend.
3291+ explicit Printers(PrinterBackend *backend,
3292 int printerUpdateIntervalMSecs = 5000,
3293 QObject *parent = nullptr);
3294 ~Printers();
3295@@ -80,6 +75,13 @@
3296
3297 Q_SIGNALS:
3298 void defaultPrinterNameChanged();
3299+
3300+private:
3301+ PrinterBackend *m_backend;
3302+ PrinterModel m_model;
3303+ PrinterFilter m_allPrinters;
3304+ PrinterFilter m_allPrintersWithPdf;
3305+ PrinterFilter m_recentPrinters;
3306 };
3307
3308 #endif // USC_PRINTERS_H
3309
3310=== removed file 'plugins/Ubuntu/Settings/Printers/printers/printers_p.h'
3311--- plugins/Ubuntu/Settings/Printers/printers/printers_p.h 2017-01-19 17:59:17 +0000
3312+++ plugins/Ubuntu/Settings/Printers/printers/printers_p.h 1970-01-01 00:00:00 +0000
3313@@ -1,39 +0,0 @@
3314-/*
3315- * Copyright (C) 2017 Canonical, Ltd.
3316- *
3317- * This program is free software; you can redistribute it and/or modify
3318- * it under the terms of the GNU Lesser General Public License as published by
3319- * the Free Software Foundation; version 3.
3320- *
3321- * This program is distributed in the hope that it will be useful,
3322- * but WITHOUT ANY WARRANTY; without even the implied warranty of
3323- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3324- * GNU Lesser General Public License for more details.
3325- *
3326- * You should have received a copy of the GNU Lesser General Public License
3327- * along with this program. If not, see <http://www.gnu.org/licenses/>.
3328- */
3329-
3330-#ifndef USC_PRINTERS_PRIVATE_H
3331-#define USC_PRINTERS_PRIVATE_H
3332-
3333-#include "models/printermodel.h"
3334-
3335-struct PrintersPrivate
3336-{
3337- Q_DISABLE_COPY(PrintersPrivate)
3338- Q_DECLARE_PUBLIC(Printers)
3339- explicit PrintersPrivate(Printers *q, int printerUpdateIntervalMSecs);
3340- explicit PrintersPrivate(Printers *q, PrinterInfo *info, CupsFacade *cups,
3341- int printerUpdateIntervalMSecs);
3342- ~PrintersPrivate();
3343- CupsFacade *cups;
3344- Printers *q_ptr;
3345- PrinterInfo *info;
3346- PrinterModel model;
3347- PrinterFilter allPrinters;
3348- PrinterFilter allPrintersWithPdf;
3349- PrinterFilter recentPrinters;
3350-};
3351-
3352-#endif // USC_PRINTERS_PRIVATE_H
3353
3354=== modified file 'tests/unittests/Printers/CMakeLists.txt'
3355--- tests/unittests/Printers/CMakeLists.txt 2017-01-19 11:16:13 +0000
3356+++ tests/unittests/Printers/CMakeLists.txt 2017-01-23 14:09:24 +0000
3357@@ -6,8 +6,7 @@
3358 find_package(Qt5Test REQUIRED)
3359
3360 set(MOCK_SOURCES
3361- mockcupsfacade.h
3362- mockprinterinfo.h
3363+ mockbackend.h
3364 )
3365
3366 add_executable(testPrintersPrinter tst_printer.cpp ${MOCK_SOURCES})
3367
3368=== added file 'tests/unittests/Printers/mockbackend.h'
3369--- tests/unittests/Printers/mockbackend.h 1970-01-01 00:00:00 +0000
3370+++ tests/unittests/Printers/mockbackend.h 2017-01-23 14:09:24 +0000
3371@@ -0,0 +1,375 @@
3372+/*
3373+ * Copyright (C) 2017 Canonical, Ltd.
3374+ *
3375+ * This program is free software; you can redistribute it and/or modify
3376+ * it under the terms of the GNU Lesser General Public License as published by
3377+ * the Free Software Foundation; version 3.
3378+ *
3379+ * This program is distributed in the hope that it will be useful,
3380+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3381+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3382+ * GNU Lesser General Public License for more details.
3383+ *
3384+ * You should have received a copy of the GNU Lesser General Public License
3385+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3386+ */
3387+
3388+#ifndef USC_PRINTERS_MOCK_BACKEND_H
3389+#define USC_PRINTERS_MOCK_BACKEND_H
3390+
3391+#include "backend/backend.h"
3392+
3393+class MockPrinterBackend : public PrinterBackend
3394+{
3395+ Q_OBJECT
3396+public:
3397+ explicit MockPrinterBackend(QObject *parent = Q_NULLPTR) : PrinterBackend(parent) {};
3398+ explicit MockPrinterBackend(const QString &printerName,
3399+ QObject *parent = Q_NULLPTR)
3400+ : PrinterBackend(printerName, parent) {};
3401+ virtual ~MockPrinterBackend() {};
3402+
3403+ virtual bool holdsDefinition() const override
3404+ {
3405+
3406+ }
3407+
3408+ virtual QString printerAdd(const QString &name,
3409+ const QUrl &uri,
3410+ const QUrl &ppdFile,
3411+ const QString &info,
3412+ const QString &location) override
3413+ {
3414+ Q_UNUSED(name);
3415+ Q_UNUSED(uri);
3416+ Q_UNUSED(ppdFile);
3417+ Q_UNUSED(info);
3418+ Q_UNUSED(location);
3419+ return returnValue;
3420+ }
3421+
3422+ virtual QString printerAddWithPpd(const QString &name,
3423+ const QUrl &uri,
3424+ const QString &ppdFileName,
3425+ const QString &info,
3426+ const QString &location) override
3427+ {
3428+ Q_UNUSED(name);
3429+ Q_UNUSED(uri);
3430+ Q_UNUSED(ppdFileName);
3431+ Q_UNUSED(info);
3432+ Q_UNUSED(location);
3433+ return returnValue;
3434+ }
3435+
3436+ virtual QString printerDelete(const QString &name) override
3437+ {
3438+ Q_UNUSED(name);
3439+ return returnValue;
3440+ }
3441+
3442+ virtual QString printerSetEnabled(const QString &name,
3443+ const bool enabled) override
3444+ {
3445+ enableds.insert(name, enabled);
3446+ return returnValue;
3447+ }
3448+
3449+ virtual QString printerSetAcceptJobs(
3450+ const QString &name,
3451+ const bool enabled,
3452+ const QString &reason = QString::null) override
3453+ {
3454+ Q_UNUSED(name);
3455+ return returnValue;
3456+ }
3457+
3458+ virtual QString printerSetInfo(const QString &name,
3459+ const QString &info) override
3460+ {
3461+ infos.insert(name, info);
3462+ return returnValue;
3463+ }
3464+
3465+ virtual QString printerSetLocation(const QString &name,
3466+ const QString &location) override
3467+ {
3468+ locations.insert(name, location);
3469+ return returnValue;
3470+ }
3471+
3472+ virtual QString printerSetShared(const QString &name,
3473+ const bool shared) override
3474+ {
3475+ shareds.insert(name, shared);
3476+ return returnValue;
3477+ }
3478+
3479+ virtual QString printerSetJobSheets(const QString &name,
3480+ const QString &start,
3481+ const QString &end) override
3482+ {
3483+ Q_UNUSED(name);
3484+ Q_UNUSED(start);
3485+ Q_UNUSED(end);
3486+ return returnValue;
3487+ }
3488+
3489+ virtual QString printerSetErrorPolicy(const QString &name,
3490+ const PrinterEnum::ErrorPolicy &policy) override
3491+ {
3492+ errorPolicies.insert(name, policy);
3493+ return returnValue;
3494+ }
3495+
3496+
3497+ virtual QString printerSetOpPolicy(const QString &name,
3498+ const PrinterEnum::OperationPolicy &policy) override
3499+ {
3500+ operationPolicies.insert(name, policy);
3501+ return returnValue;
3502+ }
3503+
3504+ virtual QString printerSetUsersAllowed(const QString &name,
3505+ const QStringList &users) override
3506+ {
3507+ printerOptions[name].insert("users-allowed", QVariant::fromValue(users));
3508+ return returnValue;
3509+ }
3510+
3511+ virtual QString printerSetUsersDenied(const QString &name,
3512+ const QStringList &users) override
3513+ {
3514+ printerOptions[name].insert("users-denied", QVariant::fromValue(users));
3515+ return returnValue;
3516+ }
3517+
3518+ virtual QString printerAddOptionDefault(const QString &name,
3519+ const QString &option,
3520+ const QStringList &values) override
3521+ {
3522+ Q_UNUSED(name);
3523+ Q_UNUSED(option);
3524+ Q_UNUSED(values);
3525+ return returnValue;
3526+ }
3527+
3528+ virtual QString printerDeleteOptionDefault(const QString &name,
3529+ const QString &value) override
3530+ {
3531+ Q_UNUSED(name);
3532+ Q_UNUSED(value);
3533+ return returnValue;
3534+ }
3535+
3536+ virtual QString printerAddOption(const QString &name,
3537+ const QString &option,
3538+ const QStringList &values) override
3539+ {
3540+ printerOptions[name].insert(option, values);
3541+ return returnValue;
3542+ }
3543+
3544+
3545+ // TODO: const for both these getters (if possible)!
3546+ virtual QVariant printerGetOption(const QString &name,
3547+ const QString &option) const override
3548+ {
3549+ // FIXME: if we're to return a variant, check that it can be converted
3550+ return printerOptions[name].value(option);
3551+ }
3552+
3553+ virtual QMap<QString, QVariant> printerGetOptions(
3554+ const QString &name, const QStringList &options
3555+ ) override
3556+ {
3557+ QMap<QString, QVariant> opts;
3558+ Q_FOREACH(const QString &option, options) {
3559+ opts[option] = printerGetOption(name, option);
3560+ }
3561+ return opts;
3562+ }
3563+
3564+ // FIXME: maybe have a PrinterDest iface that has a CupsDest impl?
3565+ virtual cups_dest_t* makeDest(const QString &name,
3566+ const PrinterJob *options) override
3567+ {
3568+
3569+ }
3570+
3571+
3572+ virtual QList<ColorModel> printerGetSupportedColorModels(
3573+ const QString &name) const override
3574+ {
3575+ return printerOptions[name].value("ColorModels").value<QList<ColorModel>>();
3576+ }
3577+
3578+ virtual QList<PrintQuality> printerGetSupportedQualities(
3579+ const QString &name) const override
3580+ {
3581+ return printerOptions[name].value("PrintQualities").value<QList<PrintQuality>>();
3582+ }
3583+
3584+ virtual int printFileToDest(const QString &filepath,
3585+ const QString &title,
3586+ const cups_dest_t *dest) override
3587+ {
3588+
3589+ }
3590+
3591+
3592+ virtual QString printerName() const override
3593+ {
3594+ return m_printerName;
3595+ }
3596+
3597+ virtual QString description() const override
3598+ {
3599+ return m_description;
3600+ }
3601+
3602+ virtual QString location() const override
3603+ {
3604+ return m_location;
3605+ }
3606+
3607+ virtual QString makeAndModel() const override
3608+ {
3609+ return m_makeAndModel;
3610+ }
3611+
3612+ virtual PrinterEnum::State state() const override
3613+ {
3614+ return m_state;
3615+ }
3616+
3617+ virtual QList<QPageSize> supportedPageSizes() const override
3618+ {
3619+ return m_supportedPageSizes;
3620+ }
3621+
3622+ virtual QPageSize defaultPageSize() const override
3623+ {
3624+ return m_defaultPageSize;
3625+ }
3626+
3627+ virtual bool supportsCustomPageSizes() const override
3628+ {
3629+
3630+ }
3631+
3632+
3633+ virtual QPageSize minimumPhysicalPageSize() const override
3634+ {
3635+
3636+ }
3637+
3638+ virtual QPageSize maximumPhysicalPageSize() const override
3639+ {
3640+
3641+ }
3642+
3643+ virtual QList<int> supportedResolutions() const override
3644+ {
3645+
3646+ }
3647+
3648+ virtual PrinterEnum::DuplexMode defaultDuplexMode() const override
3649+ {
3650+ return m_defaultDuplexMode;
3651+ }
3652+
3653+ virtual QList<PrinterEnum::DuplexMode> supportedDuplexModes() const override
3654+ {
3655+ return m_supportedDuplexModes;
3656+ }
3657+
3658+ virtual QList<Printer*> availablePrinters() override
3659+ {
3660+ return m_availablePrinters;
3661+ }
3662+
3663+ virtual QStringList availablePrinterNames() override
3664+ {
3665+ return m_availablePrinterNames;
3666+ }
3667+
3668+ virtual Printer* getPrinter(const QString &printerName) override
3669+ {
3670+ Q_FOREACH(Printer* p, m_availablePrinters) {
3671+ if (p->name() == printerName) {
3672+ return p;
3673+ }
3674+ }
3675+ return Q_NULLPTR;
3676+ }
3677+
3678+ virtual QString defaultPrinterName() override
3679+ {
3680+ return m_defaultPrinterName;
3681+ }
3682+
3683+ virtual BackendType backendType() const override
3684+ {
3685+ return m_backendType;
3686+ }
3687+
3688+
3689+ void mockPrinterAdded(const QString &name)
3690+ {
3691+ Q_EMIT printerAdded(name);
3692+ }
3693+
3694+ void mockPrinterModified(const QString &name, const bool ppdChanged)
3695+ {
3696+ Q_EMIT printerModified(name, ppdChanged);
3697+ }
3698+
3699+ void mockPrinterDeleted(const QString &name)
3700+ {
3701+ Q_EMIT printerDeleted(name);
3702+ }
3703+
3704+ void mockPrinterStateChanged(const QString &name)
3705+ {
3706+ Q_EMIT printerStateChanged(name);
3707+ }
3708+
3709+public Q_SLOT:
3710+ virtual void refresh() override
3711+ {
3712+
3713+ }
3714+
3715+ QString returnValue = QString::null;
3716+
3717+ // Map from printer to key/val.
3718+ QMap<QString, QMap<QString, QVariant>> printerOptions;
3719+
3720+ QMap<QString, bool> enableds;
3721+ QMap<QString, bool> shareds;
3722+ QMap<QString, QString> infos;
3723+ QMap<QString, QString> locations;
3724+ QMap<QString, PrinterEnum::ErrorPolicy> errorPolicies;
3725+ QMap<QString, PrinterEnum::OperationPolicy> operationPolicies;
3726+
3727+ QString m_description = QString::null;
3728+ QString m_location = QString::null;
3729+ QString m_makeAndModel = QString::null;
3730+ QString m_defaultPrinterName = QString::null;
3731+
3732+ PrinterEnum::State m_state = PrinterEnum::State::IdleState;
3733+
3734+ QPageSize m_defaultPageSize;
3735+ QList<QPageSize> m_supportedPageSizes;
3736+
3737+ QList<PrinterEnum::DuplexMode> m_supportedDuplexModes;
3738+ PrinterEnum::DuplexMode m_defaultDuplexMode;
3739+
3740+ QStringList m_availablePrinterNames;
3741+ QList<Printer*> m_availablePrinters;
3742+ PrinterBackend::BackendType m_backendType;
3743+
3744+};
3745+
3746+#endif // USC_PRINTERS_MOCK_BACKEND_H
3747
3748=== modified file 'tests/unittests/Printers/tst_printer.cpp'
3749--- tests/unittests/Printers/tst_printer.cpp 2017-01-19 21:12:23 +0000
3750+++ tests/unittests/Printers/tst_printer.cpp 2017-01-23 14:09:24 +0000
3751@@ -16,10 +16,10 @@
3752
3753 #include "utils.h"
3754
3755-#include "mockcupsfacade.h"
3756-#include "mockprinterinfo.h"
3757+#include "mockbackend.h"
3758
3759-#include "cups/cupsfacade.h"
3760+#include "backend/backend.h"
3761+#include "backend/backend_pdf.h"
3762 #include "printer/printer.h"
3763
3764 #include <QDebug>
3765@@ -35,31 +35,30 @@
3766 private Q_SLOTS:
3767 void init()
3768 {
3769- m_mockcups = new MockCupsFacade;
3770- m_mockinfo = new MockPrinterInfo(m_printerName);
3771- m_instance = new Printer(m_mockinfo, m_mockcups);
3772+ m_backend = new MockPrinterBackend(m_printerName);
3773+ m_instance = new Printer(m_backend);
3774 }
3775 void cleanup()
3776 {
3777 QSignalSpy destroyedSpy(m_instance, SIGNAL(destroyed(QObject*)));
3778 m_instance->deleteLater();
3779 QTRY_COMPARE(destroyedSpy.count(), 1);
3780- delete m_mockcups;
3781+ delete m_backend;
3782 }
3783 void testName()
3784 {
3785- QCOMPARE(m_mockinfo->printerName(), m_instance->name());
3786+ QCOMPARE(m_backend->printerName(), m_instance->name());
3787 }
3788 void testDescription()
3789 {
3790- ((MockPrinterInfo*) m_mockinfo)->m_description = "some description";
3791- QCOMPARE(m_mockinfo->description(), m_instance->description());
3792+ getBackend()->m_description = "some description";
3793+ QCOMPARE(m_backend->description(), m_instance->description());
3794 }
3795 void testSetDescription()
3796 {
3797 QString desc("another description");
3798 m_instance->setDescription(desc);
3799- QCOMPARE(((MockCupsFacade*) m_mockcups)->infos.value(m_printerName), desc);
3800+ QCOMPARE(getBackend()->infos.value(m_printerName), desc);
3801 }
3802 void testSupportedDuplexModes_data()
3803 {
3804@@ -80,48 +79,36 @@
3805 {
3806 QFETCH(QList<PrinterEnum::DuplexMode>, modes);
3807 QFETCH(QStringList, strings);
3808- ((MockPrinterInfo*) m_mockinfo)->m_supportedDuplexModes = modes;
3809+ getBackend()->m_supportedDuplexModes = modes;
3810 QCOMPARE(m_instance->supportedDuplexModes(), modes);
3811 QCOMPARE(m_instance->supportedDuplexStrings(), strings);
3812 }
3813 void testDefaultDuplexMode()
3814 {
3815- ((MockPrinterInfo*) m_mockinfo)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexLongSide;
3816+ getBackend()->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexLongSide;
3817 QCOMPARE(m_instance->defaultDuplexMode(), PrinterEnum::DuplexMode::DuplexLongSide);
3818- ((MockPrinterInfo*) m_mockinfo)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
3819+ getBackend()->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
3820 QCOMPARE(m_instance->defaultDuplexMode(), PrinterEnum::DuplexMode::DuplexNone);
3821- ((MockPrinterInfo*) m_mockinfo)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexShortSide;
3822+ getBackend()->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexShortSide;
3823 QCOMPARE(m_instance->defaultDuplexMode(), PrinterEnum::DuplexMode::DuplexShortSide);
3824 }
3825 void testSetDefaultDuplexMode()
3826 {
3827- ((MockPrinterInfo*) m_mockinfo)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
3828+ getBackend()->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
3829
3830 // Add support
3831 QList<PrinterEnum::DuplexMode> modes({PrinterEnum::DuplexMode::DuplexNone, PrinterEnum::DuplexMode::DuplexLongSide});
3832- ((MockPrinterInfo*) m_mockinfo)->m_supportedDuplexModes = modes;
3833+ getBackend()->m_supportedDuplexModes = modes;
3834
3835 m_instance->setDefaultDuplexMode(PrinterEnum::DuplexMode::DuplexLongSide);
3836
3837- QVariant duplexVar = ((MockCupsFacade*) m_mockcups)->printerOptions[m_printerName].value("Duplex");
3838+ QVariant duplexVar = getBackend()->printerOptions[m_printerName].value("Duplex");
3839 QStringList duplexVals = duplexVar.toStringList();
3840 QCOMPARE(
3841 duplexVals.at(0),
3842 (QString) Utils::duplexModeToPpdChoice(PrinterEnum::DuplexMode::DuplexLongSide)
3843 );
3844 }
3845- void testDefaultPageSize()
3846- {
3847- auto targetSize = QPageSize(QPageSize::A4);
3848- ((MockPrinterInfo*) m_mockinfo)->m_defaultPageSize = targetSize;
3849- QCOMPARE(m_instance->defaultPageSize(), targetSize);
3850- }
3851- void testSupportedPageSizes_data()
3852- {
3853- auto supported = QList<QPageSize>({QPageSize(QPageSize::A4), QPageSize(QPageSize::Letter)});
3854- ((MockPrinterInfo*) m_mockinfo)->m_supportedPageSizes = supported;
3855- QCOMPARE(m_instance->supportedPageSizes(), supported);
3856- }
3857 void testSetDefaultPageSize_data()
3858 {
3859 QTest::addColumn<QList<QPageSize>>("sizes");
3860@@ -144,17 +131,29 @@
3861 QTest::newRow("supported, but non-ppd size") << sizes << custom << false << "";
3862 }
3863 }
3864+ void testDefaultPageSize()
3865+ {
3866+ auto targetSize = QPageSize(QPageSize::A4);
3867+ getBackend()->m_defaultPageSize = targetSize;
3868+ QCOMPARE(m_instance->defaultPageSize(), targetSize);
3869+ }
3870+ void testSupportedPageSizes_data()
3871+ {
3872+ auto supported = QList<QPageSize>({QPageSize(QPageSize::A4), QPageSize(QPageSize::Letter)});
3873+ getBackend()->m_supportedPageSizes = supported;
3874+ QCOMPARE(m_instance->supportedPageSizes(), supported);
3875+ }
3876 void testSetDefaultPageSize()
3877 {
3878 QFETCH(QList<QPageSize>, sizes);
3879 QFETCH(QPageSize, size);
3880 QFETCH(bool, expectCupsCommunication);
3881 QFETCH(QString, expectedValue);
3882- ((MockPrinterInfo*) m_mockinfo)->m_supportedPageSizes = sizes;
3883+ getBackend()->m_supportedPageSizes = sizes;
3884
3885 m_instance->setDefaultPageSize(size);
3886
3887- QVariant pageSizeVar = ((MockCupsFacade*) m_mockcups)->printerOptions[m_printerName].value("PageSize");
3888+ QVariant pageSizeVar = getBackend()->printerOptions[m_printerName].value("PageSize");
3889 QStringList pageSizeVals = pageSizeVar.toStringList();
3890
3891 if (expectCupsCommunication) {
3892@@ -175,11 +174,10 @@
3893 b.text = "RBG";
3894 QList<ColorModel> models({a, b});
3895
3896- PrinterInfo *info = new MockPrinterInfo(m_printerName);
3897- CupsFacade *cups = new MockCupsFacade;
3898- ((MockCupsFacade*) cups)->printerOptions[m_printerName].insert(
3899+ PrinterBackend *backend = new MockPrinterBackend(m_printerName);
3900+ ((MockPrinterBackend*) backend)->printerOptions[m_printerName].insert(
3901 "ColorModels", QVariant::fromValue(models));
3902- Printer p(info, cups);
3903+ Printer p(backend);
3904 QCOMPARE(p.supportedColorModels(), models);
3905 }
3906 void testDefaultPrintQuality()
3907@@ -196,11 +194,10 @@
3908 b.name = "Worse";
3909 QList<PrintQuality> qualities({a, b});
3910
3911- PrinterInfo *info = new MockPrinterInfo(m_printerName);
3912- CupsFacade *cups = new MockCupsFacade;
3913- ((MockCupsFacade*) cups)->printerOptions[m_printerName].insert(
3914+ PrinterBackend *backend = new MockPrinterBackend(m_printerName);
3915+ ((MockPrinterBackend*) backend)->printerOptions[m_printerName].insert(
3916 "PrintQualities", QVariant::fromValue(qualities));
3917- Printer p(info, cups);
3918+ Printer p(backend);
3919 QCOMPARE(p.supportedPrintQualities(), qualities);
3920 }
3921 void testIsDefault_data()
3922@@ -212,14 +209,26 @@
3923 void testIsDefault()
3924 {
3925 QFETCH(bool, isDefault);
3926- ((MockPrinterInfo*) m_mockinfo)->m_defaultPrinterName = isDefault ? m_printerName : "some-other";
3927+ getBackend()->m_defaultPrinterName = isDefault ? m_printerName : "some-other";
3928 QCOMPARE(m_instance->isDefault(), isDefault);
3929 }
3930+ void testPdfPrinter()
3931+ {
3932+ PrinterBackend *backend = new PrinterPdfBackend(m_printerName);
3933+ Printer p(backend);
3934+ QCOMPARE(p.defaultColorModel().name, QString("RGB"));
3935+ QCOMPARE(p.defaultPageSize(), QPageSize(QPageSize::A4));
3936+ QCOMPARE(p.defaultDuplexMode(), PrinterEnum::DuplexMode::DuplexNone);
3937+ QCOMPARE(p.isPdf(), true);
3938+
3939+ }
3940 private:
3941 QString m_printerName = "my-printer";
3942- CupsFacade *m_mockcups = nullptr;
3943+ PrinterBackend *m_backend = nullptr;
3944 Printer *m_instance = nullptr;
3945- PrinterInfo *m_mockinfo = nullptr;
3946+ MockPrinterBackend* getBackend() {
3947+ return (MockPrinterBackend*) m_backend;
3948+ }
3949 };
3950
3951 QTEST_GUILESS_MAIN(TestPrinter)
3952
3953=== modified file 'tests/unittests/Printers/tst_printerfilter.cpp'
3954--- tests/unittests/Printers/tst_printerfilter.cpp 2017-01-19 11:16:13 +0000
3955+++ tests/unittests/Printers/tst_printerfilter.cpp 2017-01-23 14:09:24 +0000
3956@@ -14,8 +14,7 @@
3957 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3958 */
3959
3960-#include "mockcupsfacade.h"
3961-#include "mockprinterinfo.h"
3962+#include "mockbackend.h"
3963
3964 #include "models/printermodel.h"
3965
3966@@ -24,8 +23,7 @@
3967 #include <QScopedPointer>
3968 #include <QTest>
3969
3970-Q_DECLARE_METATYPE(CupsFacade*)
3971-Q_DECLARE_METATYPE(PrinterInfo*)
3972+Q_DECLARE_METATYPE(PrinterBackend*)
3973 Q_DECLARE_METATYPE(PrinterJob*)
3974
3975 class TestPrinterFilter : public QObject
3976@@ -34,9 +32,8 @@
3977 private Q_SLOTS:
3978 void testEmptyCount()
3979 {
3980- QScopedPointer<CupsFacade> cups(new MockCupsFacade);
3981- QScopedPointer<PrinterInfo> info(new MockPrinterInfo);
3982- PrinterModel model(info.data(), cups.data(), 100);
3983+ QScopedPointer<PrinterBackend> backend(new MockPrinterBackend);
3984+ PrinterModel model(backend.data(), 100);
3985
3986 PrinterFilter filter;
3987 filter.setSourceModel(&model);
3988@@ -44,14 +41,15 @@
3989 }
3990 void testNonEmptyCount()
3991 {
3992- QScopedPointer<CupsFacade> cups(new MockCupsFacade);
3993- QScopedPointer<PrinterInfo> info(new MockPrinterInfo);
3994- PrinterModel model(info.data(), cups.data(), 100);
3995-
3996- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
3997- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
3998-
3999- ((MockPrinterInfo*) info.data())->m_availablePrinters << printerA << printerB;
4000+ QScopedPointer<PrinterBackend> backend(new MockPrinterBackend);
4001+ PrinterModel model(backend.data(), 100);
4002+
4003+ PrinterBackend* printerABackend = new MockPrinterBackend("a-printer");
4004+ PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer");
4005+ Printer printerA(printerABackend);
4006+ Printer printerB(printerBBackend);
4007+
4008+ ((MockPrinterBackend*) backend.data())->m_availablePrinters << &printerA << &printerB;
4009
4010 PrinterFilter filter;
4011 filter.setSourceModel(&model);
4012@@ -60,14 +58,15 @@
4013 }
4014 void testCountChanged()
4015 {
4016- QScopedPointer<CupsFacade> cups(new MockCupsFacade);
4017- QScopedPointer<PrinterInfo> info(new MockPrinterInfo);
4018- PrinterModel model(info.data(), cups.data(), 100);
4019-
4020- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4021- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
4022-
4023- ((MockPrinterInfo*) info.data())->m_availablePrinters << printerA << printerB;
4024+ QScopedPointer<PrinterBackend> backend(new MockPrinterBackend);
4025+ PrinterModel model(backend.data(), 100);
4026+
4027+ PrinterBackend* printerABackend = new MockPrinterBackend("a-printer");
4028+ PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer");
4029+ Printer printerA(printerABackend);
4030+ Printer printerB(printerBBackend);
4031+
4032+ ((MockPrinterBackend*) backend.data())->m_availablePrinters << &printerA << &printerB;
4033
4034 PrinterFilter filter;
4035 filter.setSourceModel(&model);
4036
4037=== modified file 'tests/unittests/Printers/tst_printerjob.cpp'
4038--- tests/unittests/Printers/tst_printerjob.cpp 2017-01-18 14:35:30 +0000
4039+++ tests/unittests/Printers/tst_printerjob.cpp 2017-01-23 14:09:24 +0000
4040@@ -16,10 +16,9 @@
4041
4042 #include "utils.h"
4043
4044-#include "mockcupsfacade.h"
4045-#include "mockprinterinfo.h"
4046+#include "mockbackend.h"
4047
4048-#include "cups/cupsfacade.h"
4049+#include "backend/backend.h"
4050 #include "printer/printer.h"
4051 #include "printer/printerjob.h"
4052
4053@@ -36,10 +35,9 @@
4054 private Q_SLOTS:
4055 void init()
4056 {
4057- m_mock_cups = new MockCupsFacade;
4058- m_mock_info = new MockPrinterInfo(m_printer_name);
4059- m_mock_printer = new Printer(m_mock_info, m_mock_cups);
4060- m_instance = new PrinterJob(m_mock_printer);
4061+ m_backend = new MockPrinterBackend(m_printer_name);
4062+ m_mock_printer = new Printer(m_backend);
4063+ m_instance = new PrinterJob(m_mock_printer, m_backend);
4064 }
4065 void cleanup()
4066 {
4067@@ -51,7 +49,7 @@
4068 m_mock_printer->deleteLater();
4069 QTRY_COMPARE(destroyedSpy.count(), 1);
4070
4071- delete m_mock_cups;
4072+ delete m_backend;
4073 }
4074 void refreshInstance()
4075 {
4076@@ -59,7 +57,7 @@
4077 m_instance->deleteLater();
4078 QTRY_COMPARE(destroyedSpy.count(), 1);
4079
4080- m_instance = new PrinterJob(m_mock_printer);
4081+ m_instance = new PrinterJob(m_mock_printer, m_backend);
4082 }
4083
4084 void testCancel()
4085@@ -109,9 +107,9 @@
4086 PrinterEnum::DuplexMode::DuplexLongSide,
4087 PrinterEnum::DuplexMode::DuplexShortSide
4088 };
4089- ((MockPrinterInfo *) m_mock_info)->m_supportedDuplexModes = modes;
4090+ ((MockPrinterBackend *) m_backend)->m_supportedDuplexModes = modes;
4091
4092- ((MockPrinterInfo *) m_mock_info)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
4093+ ((MockPrinterBackend *) m_backend)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
4094 refreshInstance();
4095 QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexNone));
4096 QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexNone);
4097@@ -120,7 +118,7 @@
4098 QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexLongSide));
4099 QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexLongSide);
4100
4101- ((MockPrinterInfo *) m_mock_info)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexShortSide;
4102+ ((MockPrinterBackend *) m_backend)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexShortSide;
4103 refreshInstance();
4104 QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexShortSide));
4105 QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexShortSide);
4106@@ -160,8 +158,7 @@
4107 }
4108 private:
4109 PrinterJob *m_instance = nullptr;
4110- CupsFacade *m_mock_cups = nullptr;
4111- PrinterInfo *m_mock_info = nullptr;
4112+ PrinterBackend *m_backend = nullptr;
4113 Printer *m_mock_printer = nullptr;
4114 QString m_printer_name = "my-printer";
4115 };
4116
4117=== modified file 'tests/unittests/Printers/tst_printermodel.cpp'
4118--- tests/unittests/Printers/tst_printermodel.cpp 2017-01-19 11:42:11 +0000
4119+++ tests/unittests/Printers/tst_printermodel.cpp 2017-01-23 14:09:24 +0000
4120@@ -14,10 +14,9 @@
4121 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4122 */
4123
4124-#include "mockcupsfacade.h"
4125-#include "mockprinterinfo.h"
4126+#include "mockbackend.h"
4127
4128-#include "cups/cupsfacade.h"
4129+#include "backend/backend.h"
4130 #include "models/printermodel.h"
4131 #include "printer/printer.h"
4132 #include "printer/printerjob.h"
4133@@ -27,8 +26,7 @@
4134 #include <QSignalSpy>
4135 #include <QTest>
4136
4137-Q_DECLARE_METATYPE(CupsFacade*)
4138-Q_DECLARE_METATYPE(PrinterInfo*)
4139+Q_DECLARE_METATYPE(PrinterBackend*)
4140 Q_DECLARE_METATYPE(PrinterJob*)
4141
4142 class TestPrinterModel : public QObject
4143@@ -37,49 +35,42 @@
4144 private Q_SLOTS:
4145 void init()
4146 {
4147- m_mock_cups = new MockCupsFacade;
4148- m_mock_info = new MockPrinterInfo;
4149- m_model = new PrinterModel(m_mock_info, m_mock_cups, 100);
4150+ m_backend = new MockPrinterBackend;
4151+ m_model = new PrinterModel(m_backend, 100);
4152 }
4153 void cleanup()
4154 {
4155 QSignalSpy destroyedSpy(m_model, SIGNAL(destroyed(QObject*)));
4156 m_model->deleteLater();
4157 QTRY_COMPARE(destroyedSpy.count(), 1);
4158-
4159- delete m_mock_info;
4160- delete m_mock_cups;
4161+ delete m_backend;
4162 }
4163 void testInstantiation_data()
4164 {
4165- QTest::addColumn<CupsFacade*>("cups");
4166- QTest::addColumn<PrinterInfo*>("info");
4167+ QTest::addColumn<PrinterBackend*>("backend");
4168 QTest::addColumn<int>("targetCount");
4169
4170 {
4171- CupsFacade* cups = new MockCupsFacade;
4172- PrinterInfo* info = new MockPrinterInfo;
4173- QTest::newRow("no printers") << cups << info << 0;
4174+ PrinterBackend* backend = new MockPrinterBackend;
4175+ QTest::newRow("no printers") << backend << 0;
4176 }
4177 {
4178- CupsFacade* cups = new MockCupsFacade;
4179- PrinterInfo* info = new MockPrinterInfo;
4180-
4181- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4182- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
4183-
4184- ((MockPrinterInfo*) info)->m_availablePrinters << printerA;
4185-
4186- QTest::newRow("some printers") << cups << info << 1;
4187+ PrinterBackend* backend = new MockPrinterBackend;
4188+
4189+ PrinterBackend *printerABackend = new MockPrinterBackend("a-printer");
4190+ Printer* printerA = new Printer(printerABackend);
4191+
4192+ ((MockPrinterBackend*) backend)->m_availablePrinters << printerA;
4193+
4194+ QTest::newRow("some printers") << backend << 1;
4195 }
4196 }
4197 void testInstantiation()
4198 {
4199- QFETCH(CupsFacade*, cups);
4200- QFETCH(PrinterInfo*, info);
4201+ QFETCH(PrinterBackend*, backend);
4202 QFETCH(int, targetCount);
4203
4204- PrinterModel model(info, cups);
4205+ PrinterModel model(backend);
4206 QCOMPARE(model.count(), targetCount);
4207 }
4208 void testUpdateInsert()
4209@@ -87,8 +78,9 @@
4210 QSignalSpy countSpy(m_model, SIGNAL(countChanged()));
4211 QSignalSpy insertSpy(m_model, SIGNAL(rowsInserted(const QModelIndex&, int, int)));
4212
4213- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4214- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters << printerA;
4215+ PrinterBackend* printerABackend = new MockPrinterBackend("a-printer");
4216+ Printer* printerA = new Printer(printerABackend);
4217+ ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA;
4218
4219 QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 1, 500);
4220 QCOMPARE(countSpy.count(), 1);
4221@@ -102,16 +94,18 @@
4222 void testUpdateMove()
4223 {
4224 // Setup two printers
4225- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4226- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
4227- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters << printerA << printerB;
4228+ PrinterBackend* printerABackend = new MockPrinterBackend("a-printer");
4229+ Printer* printerA = new Printer(printerABackend);
4230+ PrinterBackend* printerBBackend = new MockPrinterBackend("b-printer");
4231+ Printer* printerB = new Printer(printerBBackend);
4232+ ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB;
4233
4234 QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 2, 500);
4235
4236 // Setup spy and move a printer
4237 int from = 1;
4238 int to = 0;
4239- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters.move(from, to);
4240+ ((MockPrinterBackend*) m_backend)->m_availablePrinters.move(from, to);
4241
4242 // Check signals were fired
4243 QSignalSpy moveSpy(m_model, SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
4244@@ -127,16 +121,18 @@
4245 void testUpdateRemove()
4246 {
4247 // Setup two printers
4248- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4249- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
4250- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters << printerA << printerB;
4251+ PrinterBackend *printerABackend = new MockPrinterBackend("a-printer");
4252+ Printer* printerA = new Printer(printerABackend);
4253+ PrinterBackend *printerBBackend = new MockPrinterBackend("b-printer");
4254+ Printer* printerB = new Printer(printerBBackend);
4255+ ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB;
4256
4257 QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 2, 500);
4258
4259 // Setup spy and remove a printer
4260 QSignalSpy countSpy(m_model, SIGNAL(countChanged()));
4261 QSignalSpy removeSpy(m_model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
4262- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters.removeLast();
4263+ ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeLast();
4264
4265 QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 1, 500);
4266 QCOMPARE(countSpy.count(), 1);
4267@@ -150,19 +146,23 @@
4268 void testUpdateRemoveMulti()
4269 {
4270 // Setup four printers
4271- PrinterInfo* printerA = new MockPrinterInfo("a-printer");
4272- PrinterInfo* printerB = new MockPrinterInfo("b-printer");
4273- PrinterInfo* printerC = new MockPrinterInfo("c-printer");
4274- PrinterInfo* printerD = new MockPrinterInfo("d-printer");
4275- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters << printerA << printerB << printerC << printerD;
4276+ MockPrinterBackend *printerABackend = new MockPrinterBackend("a-printer");
4277+ Printer* printerA = new Printer(printerABackend);
4278+ MockPrinterBackend *printerBBackend = new MockPrinterBackend("b-printer");
4279+ Printer* printerB = new Printer(printerBBackend);
4280+ MockPrinterBackend *printerCBackend = new MockPrinterBackend("c-printer");
4281+ Printer* printerC = new Printer(printerCBackend);
4282+ MockPrinterBackend *printerDBackend = new MockPrinterBackend("d-printer");
4283+ Printer* printerD = new Printer(printerDBackend);
4284+ ((MockPrinterBackend*) m_backend)->m_availablePrinters << printerA << printerB << printerC << printerD;
4285
4286 QTRY_COMPARE_WITH_TIMEOUT(m_model->count(), 4, 500);
4287
4288 // Setup spy and remove middle two printers
4289 QSignalSpy countSpy(m_model, SIGNAL(countChanged()));
4290 QSignalSpy removeSpy(m_model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
4291- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters.removeAt(2);
4292- ((MockPrinterInfo*) m_mock_info)->m_availablePrinters.removeAt(1);
4293+ ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeAt(2);
4294+ ((MockPrinterBackend*) m_backend)->m_availablePrinters.removeAt(1);
4295
4296 // Wait until one count signal has been fired
4297 // (to ensure this is only one iteration of update)
4298@@ -181,8 +181,7 @@
4299 QCOMPARE(args.at(2).toInt(), 1);
4300 }
4301 private:
4302- CupsFacade *m_mock_cups;
4303- PrinterInfo *m_mock_info;
4304+ PrinterBackend *m_backend;
4305 PrinterModel *m_model;
4306 };
4307
4308
4309=== modified file 'tests/unittests/Printers/tst_printers.cpp'
4310--- tests/unittests/Printers/tst_printers.cpp 2017-01-18 16:32:23 +0000
4311+++ tests/unittests/Printers/tst_printers.cpp 2017-01-23 14:09:24 +0000
4312@@ -14,10 +14,9 @@
4313 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4314 */
4315
4316-#include "mockcupsfacade.h"
4317-#include "mockprinterinfo.h"
4318+#include "mockbackend.h"
4319
4320-#include "cups/cupsfacade.h"
4321+#include "backend/backend.h"
4322 #include "printers/printers.h"
4323
4324 #include <QDebug>
4325@@ -25,9 +24,8 @@
4326 #include <QSignalSpy>
4327 #include <QTest>
4328
4329-Q_DECLARE_METATYPE(CupsFacade*)
4330-Q_DECLARE_METATYPE(PrinterInfo*)
4331-Q_DECLARE_METATYPE(QList<PrinterInfo*>)
4332+Q_DECLARE_METATYPE(PrinterBackend*)
4333+Q_DECLARE_METATYPE(QList<Printer*>)
4334
4335 class TestPrinters : public QObject
4336 {
4337@@ -35,33 +33,31 @@
4338 private Q_SLOTS:
4339 void testInstantiation_data()
4340 {
4341- QTest::addColumn<CupsFacade*>("cups");
4342- QTest::addColumn<PrinterInfo*>("info");
4343+ QTest::addColumn<PrinterBackend*>("backend");
4344
4345 {
4346- CupsFacade* cups = new MockCupsFacade;
4347- PrinterInfo* info = new MockPrinterInfo;
4348- QTest::newRow("no printers") << cups << info;
4349+ PrinterBackend* backend = new MockPrinterBackend;
4350+ QTest::newRow("no printers") << backend;
4351 }
4352 }
4353 void testInstantiation()
4354 {
4355- QFETCH(CupsFacade*, cups);
4356- QFETCH(PrinterInfo*, info);
4357-
4358- Printers printers(info, cups);
4359+ QFETCH(PrinterBackend*, backend);
4360+ Printers printers(backend);
4361 }
4362 void testAllPrintersFilter_data()
4363 {
4364- QTest::addColumn<QList<PrinterInfo*>>("in");
4365- QTest::addColumn<QList<PrinterInfo*>>("out");
4366+ QTest::addColumn<QList<Printer*>>("in");
4367+ QTest::addColumn<QList<Printer*>>("out");
4368
4369 {
4370- auto in = QList<PrinterInfo*>();
4371- auto out = QList<PrinterInfo*>();
4372+ auto in = QList<Printer*>();
4373+ auto out = QList<Printer*>();
4374
4375- auto a = new MockPrinterInfo("printer-a");
4376- auto b = new MockPrinterInfo("printer-b");
4377+ auto aBackend = new MockPrinterBackend("printer-a");
4378+ auto a = new Printer(aBackend);
4379+ auto bBackend = new MockPrinterBackend("printer-b");
4380+ auto b = new Printer(bBackend);
4381
4382 in << a << b;
4383 out << a << b;
4384@@ -69,12 +65,14 @@
4385 QTest::newRow("no defaults") << in << out;
4386 }
4387 {
4388- auto in = QList<PrinterInfo*>();
4389- auto out = QList<PrinterInfo*>();
4390+ auto in = QList<Printer*>();
4391+ auto out = QList<Printer*>();
4392
4393- auto a = new MockPrinterInfo("printer-a");
4394- auto b = new MockPrinterInfo("printer-b");
4395- b->m_defaultPrinterName = "printer-b";
4396+ auto aBackend = new MockPrinterBackend("printer-a");
4397+ auto a = new Printer(aBackend);
4398+ auto bBackend = new MockPrinterBackend("printer-b");
4399+ auto b = new Printer(bBackend);
4400+ bBackend->m_defaultPrinterName = "printer-b";
4401
4402 in << a << b;
4403 out << b << a;
4404@@ -84,22 +82,20 @@
4405 }
4406 void testAllPrintersFilter()
4407 {
4408- QFETCH(QList<PrinterInfo*>, in);
4409- QFETCH(QList<PrinterInfo*>, out);
4410-
4411- CupsFacade* cups = new MockCupsFacade;
4412- PrinterInfo* info = new MockPrinterInfo;
4413-
4414- ((MockPrinterInfo*) info)->m_availablePrinters = in;
4415-
4416- Printers printers(info, cups, 100);
4417+ QFETCH(QList<Printer*>, in);
4418+ QFETCH(QList<Printer*>, out);
4419+
4420+ PrinterBackend* backend = new MockPrinterBackend;
4421+ ((MockPrinterBackend*) backend)->m_availablePrinters = in;
4422+
4423+ Printers printers(backend, 100);
4424 auto all = printers.allPrinters();
4425
4426 QTRY_COMPARE_WITH_TIMEOUT(all->rowCount(), out.size(), 101);
4427 for (int i = 0; i < all->rowCount(); i++) {
4428 QCOMPARE(
4429 all->data(all->index(i, 0)).toString(),
4430- out.at(i)->printerName()
4431+ out.at(i)->name()
4432 );
4433 }
4434 }

Subscribers

People subscribed via source and target branches