From 3ea2955a45fa3d0026248f9ff4fef0ace31cfb38 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 27 Mar 2018 17:17:20 +0200 Subject: 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 --- src/plugins/printsupport/cups/qppdprintdevice.cpp | 52 +++++++++-------------- src/plugins/printsupport/cups/qppdprintdevice.h | 1 - 2 files changed, 19 insertions(+), 34 deletions(-) (limited to 'src') 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); diff --git a/src/plugins/printsupport/cups/qppdprintdevice.h b/src/plugins/printsupport/cups/qppdprintdevice.h index 0ec62e3198..90f90d6788 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.h +++ b/src/plugins/printsupport/cups/qppdprintdevice.h @@ -104,7 +104,6 @@ protected: #endif private: - void loadPrinter(); QString printerOption(const QString &key) const; cups_ptype_e printerTypeFlags() const; -- cgit v1.2.3