2
* Copyright (C) 2017 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#ifndef USC_PRINTERS_H
18
#define USC_PRINTERS_H
20
#include "printers_global.h"
22
#include "models/drivermodel.h"
23
#include "models/printermodel.h"
24
#include "printer/printer.h"
26
#include <QAbstractItemModel>
28
#include <QScopedPointer>
29
#include <QSharedPointer>
32
#define CUPSD_NOTIFIER_DBUS_PATH "/org/cups/cupsd/Notifier"
34
class PRINTERS_DECL_EXPORT Printers : public QObject
37
Q_PROPERTY(QAbstractItemModel* allPrinters READ allPrinters CONSTANT)
38
Q_PROPERTY(QAbstractItemModel* allPrintersWithPdf READ allPrintersWithPdf CONSTANT)
39
Q_PROPERTY(QAbstractItemModel* recentPrinters READ recentPrinters CONSTANT)
40
Q_PROPERTY(QAbstractItemModel* printJobs READ printJobs CONSTANT)
41
Q_PROPERTY(QAbstractItemModel* drivers READ drivers CONSTANT)
42
Q_PROPERTY (QString driverFilter READ driverFilter WRITE setDriverFilter NOTIFY driverFilterChanged)
43
Q_PROPERTY(QString defaultPrinterName READ defaultPrinterName WRITE setDefaultPrinterName NOTIFY defaultPrinterNameChanged)
44
Q_PROPERTY(QString lastMessage READ lastMessage CONSTANT)
47
explicit Printers(QObject *parent = Q_NULLPTR);
49
// Note: Printers takes ownership of backend.
50
explicit Printers(PrinterBackend *backend, QObject *parent = Q_NULLPTR);
53
QAbstractItemModel* allPrinters();
54
QAbstractItemModel* allPrintersWithPdf();
55
QAbstractItemModel* recentPrinters();
56
QAbstractItemModel* printJobs();
57
QAbstractItemModel* drivers();
58
QString driverFilter() const;
59
QString defaultPrinterName() const;
60
QString lastMessage() const;
62
void setDefaultPrinterName(const QString &name);
63
void setDriverFilter(const QString &filter);
66
QSharedPointer<Printer> getPrinterByName(const QString &name);
67
QSharedPointer<Printer> getJobOwner(const int &jobId);
69
PrinterJob* createJob(const QString &printerName);
70
void cancelJob(const QString &printerName, const int jobId);
72
/* Instructs us to start loading drivers and what have you. In most cases,
73
the user is likely to merely configure existing printers/jobs. Loading
74
(at least) 12.000 drivers isn't relevant to those scenarios, so in order to
75
add printers, this method should be called first. */
76
void prepareToAddPrinter();
78
bool addPrinter(const QString &name, const QString &ppd,
79
const QString &device, const QString &description,
80
const QString &location);
81
bool addPrinterWithPpdFile(const QString &name, const QString &ppdFileName,
82
const QString &device,
83
const QString &description,
84
const QString &location);
86
bool removePrinter(const QString &name);
89
void jobAdded(QSharedPointer<PrinterJob> job);
90
void printerAdded(QSharedPointer<Printer> printer);
93
void defaultPrinterNameChanged();
94
void driverFilterChanged();
97
PrinterBackend *m_backend;
98
DriverModel m_drivers;
101
PrinterFilter m_allPrinters;
102
PrinterFilter m_allPrintersWithPdf;
103
PrinterFilter m_recentPrinters;
104
QString m_lastMessage;
107
#endif // USC_PRINTERS_H