diff options
author | Albert Astals Cid <albert.astals.cid@kdab.com> | 2018-03-27 17:17:20 +0200 |
---|---|---|
committer | Albert Astals Cid <albert.astals.cid@kdab.com> | 2018-04-04 07:14:49 +0000 |
commit | 3ea2955a45fa3d0026248f9ff4fef0ace31cfb38 (patch) | |
tree | 7fab19fcaf59300ccea7e3bfdcb637f9ec0cba2d /src/plugins/printsupport/cups/qppdprintdevice.cpp | |
parent | 98f7eba6cffc7676b791ef1e58a837b38d99ffd3 (diff) |
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>
Diffstat (limited to 'src/plugins/printsupport/cups/qppdprintdevice.cpp')
-rw-r--r-- | src/plugins/printsupport/cups/qppdprintdevice.cpp | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/src/plugins/printsupport/cups/qppdprintdevice.cpp b/src/plugins/printsupport/cups/qppdprintdevice.cpp index 94d73288a4..21d11ca709 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.cpp +++ b/src/plugins/printsupport/cups/qppdprintdevice.cpp @@ -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); |