From 10f53d98f5d3a5fa270e637959f96a1264084d57 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 10 Mar 2017 15:40:29 +0100 Subject: [maingui] Cache parsed ppds, more error handling/debug output on error --- src/maingui/printergui.cpp | 22 +++++++++++++++++++--- src/maingui/printergui.h | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp index 4cd1192..e8947d5 100644 --- a/src/maingui/printergui.cpp +++ b/src/maingui/printergui.cpp @@ -77,6 +77,11 @@ PrinterGui::PrinterGui(char *argv[], QWidget *parent) : // ____________________________________________________________________________ PrinterGui::~PrinterGui() { + QMap::const_iterator i = ppds.constBegin(); + while (i != ppds.constEnd()) { + ppdClose(i.value()); + } + ppds.clear(); cupsFreeDests(num_dests, dests); free(this->user); delete[] this->file; @@ -274,7 +279,19 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr res = ::atoi(type); } - ppd_file_t *ppd = ppdOpenFile(cupsGetPPD2(CUPS_HTTP_DEFAULT, dest->name)); + ppd_file_t *ppd = NULL; + if (ppds.contains(current)) { + ppd = ppds[current]; + } else { + const char *ppdFile = cupsGetPPD2(CUPS_HTTP_DEFAULT, dest->name); + if (ppdFile == NULL) { + qDebug() << "cupsGetPPD2 for " << dest->name << " returned NULL: " << cupsLastErrorString(); + } else { + ppd = ppdOpenFile(ppdFile); + qDebug() << dest->name << " has ppd " << ppdFile; + } + ppds.insert(current, ppd); + } if (ppd != NULL) { // Check color capabilities //if (res & CUPS_PRINTER_COLOR) // No needed? Should just get disabled either way @@ -283,9 +300,8 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr // TODO: Make it so this selection overrides what the document specifies enableOptionSelection(ppd, knownPageSizeOptions, ui->cboPaperSize, ui->lblPaperSize, true); handleTrustedPrint(ppd); - ppdClose(ppd); } else { - qDebug() << "ppd is null"<< dest->name << cupsLastErrorString(); + qDebug() << "ppd is null for "<< dest->name << "; cups last error: " << cupsLastErrorString(); } // Check copy capabilities diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h index 55a4ddb..89e0559 100644 --- a/src/maingui/printergui.h +++ b/src/maingui/printergui.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace Ui { @@ -18,6 +19,7 @@ class QStatusBar; class QCloseEvent; class QHideEvent; class QKeyEvent; +class QTreeWidgetItem; class PrinterGui : public QDialog { @@ -51,6 +53,7 @@ private: QStatusBar *statusBar; int bgTimeout; int jobId; + QMap ppds; }; #endif // MAINWINDOW_H -- cgit v1.2.3-55-g7522