QPpdPrintDevice: Move loadPrinter code to the constructor

It was only called from it and makes the code simpler by not having to have the code to free the ppd, etc

Change-Id: I4351f9906757b666255b7c31b4c1d8aecf6e873b
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
bb10
Albert Astals Cid 2018-03-27 17:17:20 +02:00
parent 98f7eba6cf
commit 3ea2955a45
2 changed files with 19 additions and 34 deletions

View File

@ -62,7 +62,25 @@ QPpdPrintDevice::QPpdPrintDevice(const QString &id)
m_cupsName = parts.at(0).toUtf8();
if (parts.size() > 1)
m_cupsInstance = parts.at(1).toUtf8();
loadPrinter();
// Get the print instance and PPD file
m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance.isNull() ? nullptr : m_cupsInstance.constData());
if (m_cupsDest) {
const char *ppdFile = cupsGetPPD(m_cupsName);
if (ppdFile) {
m_ppd = ppdOpenFile(ppdFile);
unlink(ppdFile);
}
if (m_ppd) {
ppdMarkDefaults(m_ppd);
cupsMarkOptions(m_ppd, m_cupsDest->num_options, m_cupsDest->options);
ppdLocalize(m_ppd);
} else {
cupsFreeDests(1, m_cupsDest);
m_cupsDest = nullptr;
m_ppd = nullptr;
}
}
if (m_cupsDest && m_ppd) {
m_name = printerOption("printer-info");
@ -478,38 +496,6 @@ void QPpdPrintDevice::loadMimeTypes() const
}
#endif
void QPpdPrintDevice::loadPrinter()
{
// Just to be safe, check if existing printer needs closing
if (m_ppd) {
ppdClose(m_ppd);
m_ppd = 0;
}
if (m_cupsDest) {
cupsFreeDests(1, m_cupsDest);
m_cupsDest = 0;
}
// Get the print instance and PPD file
m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance.isNull() ? nullptr : m_cupsInstance.constData());
if (m_cupsDest) {
const char *ppdFile = cupsGetPPD(m_cupsName);
if (ppdFile) {
m_ppd = ppdOpenFile(ppdFile);
unlink(ppdFile);
}
if (m_ppd) {
ppdMarkDefaults(m_ppd);
cupsMarkOptions(m_ppd, m_cupsDest->num_options, m_cupsDest->options);
ppdLocalize(m_ppd);
} else {
cupsFreeDests(1, m_cupsDest);
m_cupsDest = 0;
m_ppd = 0;
}
}
}
QString QPpdPrintDevice::printerOption(const QString &key) const
{
return cupsGetOption(key.toUtf8(), m_cupsDest->num_options, m_cupsDest->options);

View File

@ -104,7 +104,6 @@ protected:
#endif
private:
void loadPrinter();
QString printerOption(const QString &key) const;
cups_ptype_e printerTypeFlags() const;