From 7c5ae46b28ac8c70486553c58b82b492b7055580 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Tue, 6 Oct 2015 18:33:09 +0200
Subject: [printergui] Add paper size option
---
src/maingui/printergui.cpp | 45 ++++++++++++++++----
src/maingui/printergui.h | 5 ---
src/maingui/printergui.ui | 104 ++++++++++++++++++++++++++++-----------------
3 files changed, 101 insertions(+), 53 deletions(-)
diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp
index feddb52..8d2e81e 100644
--- a/src/maingui/printergui.cpp
+++ b/src/maingui/printergui.cpp
@@ -9,6 +9,7 @@
static QStringList knownColorOptions = QStringList() << "ColorModel" << "XRXColor";
static QStringList knownDuplexOptions = QStringList() << "Duplex";
+static QStringList knownPageSizeOptions = QStringList() << "PageSize";
// ____________________________________________________________________________
PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
@@ -111,7 +112,7 @@ void PrinterGui::initializeUI()
this->activateWindow();
}
-void PrinterGui::enableOptionSelection(ppd_file_t *ppd, QStringList &nameList, QComboBox *combo, QLabel *label)
+static void enableOptionSelection(ppd_file_t *ppd, QStringList &nameList, QComboBox *combo, QLabel *label)
{
// Check for each option if it matches an
QString matchedProperty;
@@ -123,13 +124,21 @@ void PrinterGui::enableOptionSelection(ppd_file_t *ppd, QStringList &nameList, Q
continue;
// Matches, update combo
matchedProperty = option;
+ combo->setUpdatesEnabled(false);
combo->clear();
for (int i = 0; i < o->num_choices; ++i) {
- combo->addItem(QString::fromUtf8(o->choices[i].text), QString::fromLatin1(o->choices[i].choice));
- if (strcmp(o->choices[i].choice, o->defchoice) == 0) {
+ if (o->choices[i].choice == NULL)
+ continue;
+ if (o->choices[i].text == NULL) {
+ combo->addItem(QString::fromUtf8(o->choices[i].choice), QString::fromLatin1(o->choices[i].choice));
+ } else {
+ combo->addItem(QString::fromUtf8(o->choices[i].text), QString::fromLatin1(o->choices[i].choice));
+ }
+ if (o->defchoice != NULL && strcmp(o->choices[i].choice, o->defchoice) == 0) {
combo->setCurrentIndex(i);
}
}
+ combo->setUpdatesEnabled(true);
combo->adjustSize();
break;
}
@@ -144,7 +153,7 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
{
ui->printerList->setFocus();
- cups_dest_t *dest =cupsGetNamedDest(CUPS_HTTP_DEFAULT, current->text(0).toUtf8().constData(), NULL);
+ cups_dest_t *dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, current->text(0).toUtf8().constData(), NULL);
/* * Check printer properties (auth, color, duplex, copies) * */
@@ -162,6 +171,7 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
//if (res & CUPS_PRINTER_COLOR) // No needed? Should just get disabled either way
enableOptionSelection(ppd, knownColorOptions, ui->comboBoxColor, ui->label_color);
enableOptionSelection(ppd, knownDuplexOptions, ui->comboBoxSides, ui->label_duplex);
+ enableOptionSelection(ppd, knownPageSizeOptions, ui->cboPaperSize, ui->lblPaperSize);
ppdClose(ppd);
} else {
qDebug() << "ppd is null"<< dest->name << cupsLastErrorString();
@@ -209,18 +219,28 @@ void PrinterGui::on_buttonPrint_clicked()
// Color
QString colorKey = ui->comboBoxColor->property("key").toString();
- if (!colorKey.isEmpty())
+ if (!colorKey.isEmpty()) {
dest->num_options = cupsAddOption(colorKey.toUtf8().constData(),
- ui->comboBoxColor->itemData(ui->comboBoxColor->currentIndex()).toString().toStdString().c_str(),
+ ui->comboBoxColor->itemData(ui->comboBoxColor->currentIndex()).toString().toUtf8().constData(),
dest->num_options,
&(dest->options));
+ }
// Duplex
QString duplexKey = ui->comboBoxSides->property("key").toString();
- if (!duplexKey.isEmpty())
+ if (!duplexKey.isEmpty()) {
dest->num_options = cupsAddOption(duplexKey.toUtf8().constData(),
- ui->comboBoxSides->itemData(ui->comboBoxSides->currentIndex()).toString().toStdString().c_str(),
+ ui->comboBoxSides->itemData(ui->comboBoxSides->currentIndex()).toString().toUtf8().constData(),
+ dest->num_options,
+ &(dest->options));
+ }
+ // Paper size
+ QString paperKey = ui->cboPaperSize->property("key").toString();
+ if (!paperKey.isEmpty()) {
+ dest->num_options = cupsAddOption(paperKey.toUtf8().constData(),
+ ui->cboPaperSize->itemData(ui->cboPaperSize->currentIndex()).toString().toUtf8().constData(),
dest->num_options,
&(dest->options));
+ }
// Kopien
if (ui->lineEditCopies->isEnabled()) {
dest->num_options = cupsAddOption("copies",
@@ -242,7 +262,14 @@ void PrinterGui::on_buttonPrint_clicked()
QMessageBox::critical(this, "CUPS Fehler", cupsLastErrorString());
} else {
this->bgTimeout = 0;
- this->hide();
+ statusBar()->showMessage("Druckauftrag wird verarbeitet...");
+ ui->buttonCancel->setEnabled(false);
+ ui->buttonPrint->setEnabled(false);
+ ui->cboPaperSize->setEnabled(false);
+ ui->comboBoxColor->setEnabled(false);
+ ui->comboBoxSides->setEnabled(false);
+ ui->lineEditCopies->setEnabled(false);
+ ui->printerList->setEnabled(false);
}
}
diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h
index 17fc8e6..cd71740 100644
--- a/src/maingui/printergui.h
+++ b/src/maingui/printergui.h
@@ -13,10 +13,6 @@ class PrinterGui;
}
class QTimer;
-class QLabel;
-class QComboBox;
-class QStringList;
-typedef struct ppd_file_s ppd_file_t;
class PrinterGui : public QMainWindow
{
@@ -35,7 +31,6 @@ private slots:
private:
Ui::PrinterGui *ui;
void initializeUI();
- void enableOptionSelection(ppd_file_t *ppd, QStringList &nameList, QComboBox *combo, QLabel *label);
cups_dest_t *dests;
int num_dests;
char * user;
diff --git a/src/maingui/printergui.ui b/src/maingui/printergui.ui
index dd13d0a..0b4849f 100644
--- a/src/maingui/printergui.ui
+++ b/src/maingui/printergui.ui
@@ -46,42 +46,6 @@
-
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
- false
-
-
- Abbrechen
-
-
-
- -
-
-
- false
-
-
-
- 0
- 0
-
-
-
- Drucken
-
-
-
-
-
-
-
@@ -121,7 +85,7 @@
- 00
+ 00;
1
@@ -165,7 +129,7 @@
-
- Farbe:
+ Farbe
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
@@ -175,13 +139,75 @@
-
- Duplex:
+ Duplex
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+ -
+
+
+ Papierformat
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ false
+
+
+ Abbrechen
+
+
+
+ -
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+ Drucken
+
+
+
+
+
--
cgit v1.2.3-55-g7522