~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/backend/backend_pdf.cpp

  • 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
#include "i18n.h"
 
18
#include "backend/backend_pdf.h"
 
19
 
 
20
PrinterPdfBackend::PrinterPdfBackend(const QString &printerName,
 
21
                                     QObject *parent)
 
22
    : PrinterBackend(printerName, parent)
 
23
{
 
24
    m_type = PrinterEnum::PrinterType::PdfType;
 
25
}
 
26
 
 
27
QVariant PrinterPdfBackend::printerGetOption(const QString &name,
 
28
                                             const QString &option) const
 
29
{
 
30
    auto res = printerGetOptions(name, QStringList({option}));
 
31
    return res[option];
 
32
}
 
33
 
 
34
QMap<QString, QVariant> PrinterPdfBackend::printerGetOptions(
 
35
    const QString &name, const QStringList &options) const
 
36
{
 
37
    Q_UNUSED(name);
 
38
 
 
39
    QMap<QString, QVariant> ret;
 
40
 
 
41
    ColorModel rgb;
 
42
    rgb.colorType = PrinterEnum::ColorModelType::ColorType;
 
43
    rgb.name = "RGB";
 
44
    rgb.text = __("Color");
 
45
 
 
46
    PrintQuality quality;
 
47
    quality.name = __("Normal");
 
48
 
 
49
    Q_FOREACH(const QString &option, options) {
 
50
        if (option == QLatin1String("DefaultColorModel")) {
 
51
            ret[option] = QVariant::fromValue(rgb);
 
52
        } else if (option == QLatin1String("DefaultPrintQuality")) {
 
53
            ret[option] = QVariant::fromValue(quality);
 
54
        } else if (option == QLatin1String("SupportedPrintQualities")) {
 
55
            auto qualities = QList<PrintQuality>({quality});
 
56
            ret[option] = QVariant::fromValue(qualities);
 
57
        } else if (option == QLatin1String("SupportedColorModels")) {
 
58
            auto models = QList<ColorModel>{rgb};
 
59
            ret[option] = QVariant::fromValue(models);
 
60
        } else if (option == QLatin1String("AcceptJobs")) {
 
61
            ret[option] = true;
 
62
        } else {
 
63
            throw std::invalid_argument("Invalid value for PDF printer: " + option.toStdString());
 
64
        }
 
65
    }
 
66
 
 
67
    return ret;
 
68
}
 
69
 
 
70
QString PrinterPdfBackend::printerName() const
 
71
{
 
72
    return m_printerName;
 
73
}
 
74
 
 
75
PrinterEnum::State PrinterPdfBackend::state() const
 
76
{
 
77
    return PrinterEnum::State::IdleState;
 
78
}
 
79
 
 
80
QList<QPageSize> PrinterPdfBackend::supportedPageSizes() const
 
81
{
 
82
    return QList<QPageSize>{QPageSize(QPageSize::A4)};
 
83
}
 
84
 
 
85
QPageSize PrinterPdfBackend::defaultPageSize() const
 
86
{
 
87
    return QPageSize(QPageSize::A4);
 
88
}
 
89
 
 
90
bool PrinterPdfBackend::supportsCustomPageSizes() const
 
91
{
 
92
    return false;
 
93
}
 
94
 
 
95
QPageSize PrinterPdfBackend::minimumPhysicalPageSize() const
 
96
{
 
97
    return QPageSize(QPageSize::A4);
 
98
}
 
99
 
 
100
QPageSize PrinterPdfBackend::maximumPhysicalPageSize() const
 
101
{
 
102
    return QPageSize(QPageSize::A4);
 
103
}
 
104
 
 
105
QList<int> PrinterPdfBackend::supportedResolutions() const
 
106
{
 
107
    return QList<int>{};
 
108
}
 
109
 
 
110
PrinterEnum::DuplexMode PrinterPdfBackend::defaultDuplexMode() const
 
111
{
 
112
    return PrinterEnum::DuplexMode::DuplexNone;
 
113
}
 
114
 
 
115
QList<PrinterEnum::DuplexMode> PrinterPdfBackend::supportedDuplexModes() const
 
116
{
 
117
    return QList<PrinterEnum::DuplexMode>{PrinterEnum::DuplexMode::DuplexNone};
 
118
}
 
119