summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-10-06 18:33:09 +0200
committerSimon Rettberg2015-10-06 18:33:09 +0200
commit7c5ae46b28ac8c70486553c58b82b492b7055580 (patch)
tree897d5353cbb5f768f8a7e9d37a9a698dc51b8ede
parent[printergui] Refactor option parsing (diff)
downloadprintergui-7c5ae46b28ac8c70486553c58b82b492b7055580.tar.gz
printergui-7c5ae46b28ac8c70486553c58b82b492b7055580.tar.xz
printergui-7c5ae46b28ac8c70486553c58b82b492b7055580.zip
[printergui] Add paper size option
-rw-r--r--src/maingui/printergui.cpp45
-rw-r--r--src/maingui/printergui.h5
-rw-r--r--src/maingui/printergui.ui104
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 @@
<item row="3" column="1">
<widget class="QComboBox" name="comboBoxSides"/>
</item>
- <item row="3" column="3">
- <layout class="QHBoxLayout" name="horizontalLayoutButtons">
- <item>
- <widget class="QPushButton" name="buttonCancel">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="autoFillBackground">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Abbrechen</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="buttonPrint">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Drucken</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayoutCopies">
<item>
@@ -121,7 +85,7 @@
</size>
</property>
<property name="inputMask">
- <string>00</string>
+ <string>00; </string>
</property>
<property name="text">
<string>1</string>
@@ -165,7 +129,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_color">
<property name="text">
- <string>Farbe:</string>
+ <string>Farbe</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -175,13 +139,75 @@
<item row="3" column="0">
<widget class="QLabel" name="label_duplex">
<property name="text">
- <string>Duplex:</string>
+ <string>Duplex</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="lblPaperSize">
+ <property name="text">
+ <string>Papierformat</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QComboBox" name="cboPaperSize"/>
+ </item>
+ <item row="4" column="2">
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" column="3">
+ <layout class="QHBoxLayout" name="horizontalLayoutButtons">
+ <item>
+ <widget class="QPushButton" name="buttonCancel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Abbrechen</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonPrint">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Drucken</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</item>
</layout>