~ci-train-bot/ubuntu-ui-extras/ubuntu-ui-extras-ubuntu-zesty-2515

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/Extras/Printers/printers/printers.h

  • Committer: Andrew Hayzen
  • Date: 2017-02-21 10:46:29 UTC
  • Revision ID: ahayzen@gmail.com-20170221104629-pbm454x5k7rr4ot5
* Add printer-components from ubuntu-settings-components to ubuntu-ui-extras (original branch https://code.launchpad.net/~phablet-team/ubuntu-settings-components/printer-components)
* Add plugin module to Extras/Printers
* Add translation support for cpp/h
* Add tests for Printers
* Add debian depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2017 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
#ifndef USC_PRINTERS_H
 
18
#define USC_PRINTERS_H
 
19
 
 
20
#include "printers_global.h"
 
21
 
 
22
#include "models/drivermodel.h"
 
23
#include "models/printermodel.h"
 
24
#include "printer/printer.h"
 
25
 
 
26
#include <QAbstractItemModel>
 
27
#include <QObject>
 
28
#include <QScopedPointer>
 
29
#include <QSharedPointer>
 
30
#include <QString>
 
31
 
 
32
#define CUPSD_NOTIFIER_DBUS_PATH "/org/cups/cupsd/Notifier"
 
33
 
 
34
class PRINTERS_DECL_EXPORT Printers : public QObject
 
35
{
 
36
    Q_OBJECT
 
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)
 
45
 
 
46
public:
 
47
    explicit Printers(QObject *parent = Q_NULLPTR);
 
48
 
 
49
    // Note: Printers takes ownership of backend.
 
50
    explicit Printers(PrinterBackend *backend, QObject *parent = Q_NULLPTR);
 
51
    ~Printers();
 
52
 
 
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;
 
61
 
 
62
    void setDefaultPrinterName(const QString &name);
 
63
    void setDriverFilter(const QString &filter);
 
64
 
 
65
public Q_SLOTS:
 
66
    QSharedPointer<Printer> getPrinterByName(const QString &name);
 
67
    QSharedPointer<Printer> getJobOwner(const int &jobId);
 
68
 
 
69
    PrinterJob* createJob(const QString &printerName);
 
70
    void cancelJob(const QString &printerName, const int jobId);
 
71
 
 
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();
 
77
 
 
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);
 
85
 
 
86
    bool removePrinter(const QString &name);
 
87
 
 
88
private Q_SLOTS:
 
89
    void jobAdded(QSharedPointer<PrinterJob> job);
 
90
    void printerAdded(QSharedPointer<Printer> printer);
 
91
 
 
92
Q_SIGNALS:
 
93
    void defaultPrinterNameChanged();
 
94
    void driverFilterChanged();
 
95
 
 
96
private:
 
97
    PrinterBackend *m_backend;
 
98
    DriverModel m_drivers;
 
99
    PrinterModel m_model;
 
100
    JobModel m_jobs;
 
101
    PrinterFilter m_allPrinters;
 
102
    PrinterFilter m_allPrintersWithPdf;
 
103
    PrinterFilter m_recentPrinters;
 
104
    QString m_lastMessage;
 
105
};
 
106
 
 
107
#endif // USC_PRINTERS_H