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
#include "printerdriverloader.h"
19
PrinterDriverLoader::PrinterDriverLoader(
20
const QString &deviceId, const QString &language,
21
const QString &makeModel, const QString &product,
22
const QStringList &includeSchemes, const QStringList &excludeSchemes)
23
: m_deviceId(deviceId)
24
, m_language(language)
25
, m_makeModel(makeModel)
27
, m_includeSchemes(includeSchemes)
28
, m_excludeSchemes(excludeSchemes)
32
PrinterDriverLoader::~PrinterDriverLoader()
36
void PrinterDriverLoader::process()
40
ipp_t* response = client.createPrinterDriversRequest(
41
m_deviceId, m_language, m_makeModel, m_product, m_includeSchemes,
45
// Note: if the response somehow fails, we return.
46
if (!response || ippGetStatusCode(response) > IPP_OK_CONFLICT) {
47
QString err(cupsLastErrorString());
48
qWarning() << Q_FUNC_INFO << "Cups HTTP error:" << err;
58
ipp_attribute_t *attr;
59
QByteArray ppdDeviceId;
60
QByteArray ppdLanguage;
61
QByteArray ppdMakeModel;
64
// cups_option_t option;
65
QList<PrinterDriver> drivers;
67
for (attr = ippFirstAttribute(response); attr != NULL && m_running; attr = ippNextAttribute(response)) {
69
while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
70
attr = ippNextAttribute(response);
75
// Pull the needed attributes from this PPD...
81
while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) {
82
if (!strcmp(ippGetName(attr), "ppd-device-id") &&
83
ippGetValueTag(attr) == IPP_TAG_TEXT) {
84
ppdDeviceId = ippGetString(attr, 0, NULL);
85
} else if (!strcmp(ippGetName(attr), "ppd-natural-language") &&
86
ippGetValueTag(attr) == IPP_TAG_LANGUAGE) {
87
ppdLanguage = ippGetString(attr, 0, NULL);
89
} else if (!strcmp(ippGetName(attr), "ppd-make-and-model") &&
90
ippGetValueTag(attr) == IPP_TAG_TEXT) {
91
ppdMakeModel = ippGetString(attr, 0, NULL);
92
} else if (!strcmp(ippGetName(attr), "ppd-name") &&
93
ippGetValueTag(attr) == IPP_TAG_NAME) {
95
ppdName = ippGetString(attr, 0, NULL);
98
attr = ippNextAttribute(response);
101
// See if we have everything needed...
102
if (ppdLanguage.isEmpty() || ppdMakeModel.isEmpty() ||
112
m.deviceId = ppdDeviceId;
113
m.makeModel = ppdMakeModel;
114
m.language = ppdLanguage;
121
Q_EMIT loaded(drivers);
125
void PrinterDriverLoader::cancel()