Refresh CUPS printer list when QPrinterInfo.availablePrinters() is called.
Introduce freeCupsPrinters() thus fixing a bug in the old deallocation code which would first set m_cupsPrintersCount = 0 and then pass it to cupsFreeDests(). Task-number: QTBUG-33666 Change-Id: I94c51cb390761a669a9cbd589c1131cfb51354c3 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
e7cf7c1c65
commit
39eb7e0b89
@ -66,8 +66,7 @@ QCupsPrinterSupport::QCupsPrinterSupport() : QPlatformPrinterSupport(),
|
||||
|
||||
QCupsPrinterSupport::~QCupsPrinterSupport()
|
||||
{
|
||||
if (cupsFreeDests)
|
||||
cupsFreeDests(m_cupsPrintersCount, m_cupsPrinters);
|
||||
freeCupsPrinters();
|
||||
}
|
||||
|
||||
QPrintEngine *QCupsPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode printerMode)
|
||||
@ -98,14 +97,20 @@ void QCupsPrinterSupport::loadCups()
|
||||
cupsGetOption = (CupsGetOption) m_cups.resolve("cupsGetOption");
|
||||
}
|
||||
|
||||
void QCupsPrinterSupport::freeCupsPrinters()
|
||||
{
|
||||
if (cupsFreeDests && m_cupsPrintersCount) {
|
||||
cupsFreeDests(m_cupsPrintersCount, m_cupsPrinters);
|
||||
m_cupsPrintersCount = 0;
|
||||
m_cupsPrinters = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QCupsPrinterSupport::loadCupsPrinters()
|
||||
{
|
||||
m_cupsPrintersCount = 0;
|
||||
freeCupsPrinters();
|
||||
m_printers.clear();
|
||||
|
||||
if (cupsFreeDests)
|
||||
cupsFreeDests(m_cupsPrintersCount, m_cupsPrinters);
|
||||
|
||||
if (cupsGetDests)
|
||||
m_cupsPrintersCount = cupsGetDests(&m_cupsPrinters);
|
||||
|
||||
@ -122,6 +127,12 @@ void QCupsPrinterSupport::loadCupsPrinters()
|
||||
}
|
||||
}
|
||||
|
||||
QList<QPrinterInfo> QCupsPrinterSupport::availablePrinters()
|
||||
{
|
||||
loadCupsPrinters();
|
||||
return QPlatformPrinterSupport::availablePrinters();
|
||||
}
|
||||
|
||||
QString QCupsPrinterSupport::printerOption(const QPrinterInfo &printer, const QString &key) const
|
||||
{
|
||||
return cupsOption(printerIndex(printer), key);
|
||||
|
@ -68,12 +68,14 @@ public:
|
||||
virtual QPaintEngine *createPaintEngine(QPrintEngine *printEngine, QPrinter::PrinterMode);
|
||||
virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
|
||||
virtual QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &) const;
|
||||
virtual QList<QPrinterInfo> availablePrinters();
|
||||
virtual QString printerOption(const QPrinterInfo &printer, const QString &key) const;
|
||||
virtual PrinterOptions printerOptions(const QPrinterInfo &printer) const;
|
||||
|
||||
private:
|
||||
void loadCups();
|
||||
void loadCupsPrinters();
|
||||
void freeCupsPrinters();
|
||||
QString cupsOption(int i, const QString &key) const;
|
||||
|
||||
QLibrary m_cups;
|
||||
|
Loading…
Reference in New Issue
Block a user