summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2017-03-10 15:40:29 +0100
committerSimon Rettberg2017-03-10 15:40:29 +0100
commit10f53d98f5d3a5fa270e637959f96a1264084d57 (patch)
tree171d6fcd7690df8810ae81a0249e1be79612f143 /src
parent[printergui] Handle NULL ppd in handleTrustedPrint() (diff)
downloadprintergui-10f53d98f5d3a5fa270e637959f96a1264084d57.tar.gz
printergui-10f53d98f5d3a5fa270e637959f96a1264084d57.tar.xz
printergui-10f53d98f5d3a5fa270e637959f96a1264084d57.zip
[maingui] Cache parsed ppds, more error handling/debug output on error
Diffstat (limited to 'src')
-rw-r--r--src/maingui/printergui.cpp22
-rw-r--r--src/maingui/printergui.h3
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<QTreeWidgetItem*, ppd_file_t*>::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 <QTreeWidget>
#include <cups/cups.h>
#include <cups/ppd.h>
+#include <QMap>
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<QTreeWidgetItem*, ppd_file_t*> ppds;
};
#endif // MAINWINDOW_H