diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | src/main.cpp | 34 | ||||
-rw-r--r-- | src/mainwindow.cpp | 406 | ||||
-rw-r--r-- | src/mainwindow.ui | 2 |
4 files changed, 200 insertions, 243 deletions
@@ -1,4 +1,3 @@ - Do the authentication stuff -- Execute the printcommand directly from C/binary - Show a options command which offers all options and their choices diff --git a/src/main.cpp b/src/main.cpp index 4186bc5..a5582d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,25 +5,21 @@ int main(int argc, char *argv[]) { - // First check parameter count - if (argc != 3) - return 2; + // First check parameter count + if (argc != 3) + return 2; - // Check if file exists - std::fstream f; - try - { - f.open(argv[2], std::ios::in); - } - catch (std::fstream::failure e) - { - return 3; - } - f.close(); + // Check if file exists + std::fstream f; + try { + f.open(argv[2], std::ios::in); + } catch (std::fstream::failure e) { + return 3; + } + f.close(); - QApplication a(argc, argv); - MainWindow w(argv); - w.show(); - - return a.exec(); + QApplication a(argc, argv); + MainWindow w(argv); + w.show(); + return a.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2c56da2..903cd6b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,183 +2,212 @@ #include "ui_mainwindow.h" #include <QMessageBox> - +// ____________________________________________________________________________ MainWindow::MainWindow(char *argv[], QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), user(argv[1]), - file(argv[2]) -{ - // Initialize cups - num_dests = cupsGetDests(&dests); + file(argv[2]) { + // Initialize cups + num_dests = cupsGetDests(&dests); - // Initialize UI - initializeUI(); + // Initialize UI + initializeUI(); } - - -MainWindow::~MainWindow() -{ - cupsFreeDests(num_dests, dests); - delete ui; +// ____________________________________________________________________________ +MainWindow::~MainWindow() { + cupsFreeDests(num_dests, dests); + delete ui; } - - -void MainWindow::initializeUI() -{ - ui->setupUi(this); - ui->horizontalLayoutButtons->setAlignment(Qt::AlignRight); - - /* Initialize Treeview */ - - ui->printerList->setColumnCount(3); - ui->printerList->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); - - // Rename headers - QStringList h; - h.append("Drucker"); - h.append("Information"); - h.append("Standort"); - ui->printerList->setHeaderLabels(h); - - // Fill treewidget with data from cups dests; - cups_dest_t *dest = dests; - for (int i = num_dests; i>0; ++dest, --i ) - if (dest->instance == NULL) - { - QTreeWidgetItem *wi = new QTreeWidgetItem(); - wi->setText(0, QString(dest->name)); - wi->setText(1, QString(cupsGetOption("printer-info", dest->num_options, dest->options))); - wi->setText(2, QString(cupsGetOption("printer-location", dest->num_options, dest->options))); - ui->printerList->addTopLevelItem(wi); - if (dest->is_default) - ui->printerList->setCurrentItem(wi); - } - - // Resize columns to contents - for (int i = 0; i < 3; ++i) - ui->printerList->resizeColumnToContents(i); - - /* Main Window properties */ - - // Disable close button - this->setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint); - // center dialog on screen center - QRect desktopRect = QApplication::desktop()->screenGeometry(this); - this->move( desktopRect.width()/2-this->width()/2, - desktopRect.height()/2-this->height()/2); -} - - - - -void MainWindow::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) -{ - ui->printerList->setFocus(); - - cups_dest_t *dest =cupsGetNamedDest (CUPS_HTTP_DEFAULT, current->text(0).toAscii(), NULL); - - - /* * Check printer properties (auth, color, duplex, copies) * */ - // get printer capabilities - int res = ::atoi(cupsGetOption("printer-type", - dest->num_options, - dest->options)); - - // Check authentication - if (res & CUPS_PRINTER_AUTHENTICATED) - { - ui->labelUser->setEnabled(true); - ui->labelPass->setEnabled(true); - ui->lineEditUser->setEnabled(true); - ui->lineEditPass->setEnabled(true); - } - else - { - ui->labelUser->setEnabled(false); - ui->labelPass->setEnabled(false); - ui->lineEditUser->setEnabled(false); - ui->lineEditPass->setEnabled(false); +// ____________________________________________________________________________ +void MainWindow::initializeUI() { + ui->setupUi(this); + ui->horizontalLayoutButtons->setAlignment(Qt::AlignRight); + + /* Initialize Treeview */ + + ui->printerList->setColumnCount(3); + ui->printerList->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + + // Rename headers + QStringList h; + h.append("Drucker"); + h.append("Information"); + h.append("Standort"); + ui->printerList->setHeaderLabels(h); + + // Fill treewidget with data from cups dests; + cups_dest_t *dest = dests; + for (int i = num_dests; i>0; ++dest, --i ) + if (dest->instance == NULL) { + QTreeWidgetItem *wi = new QTreeWidgetItem(); + wi->setText(0, QString(dest->name)); + wi->setText(1, QString(cupsGetOption("printer-info", dest->num_options, dest->options))); + wi->setText(2, QString(cupsGetOption("printer-location", dest->num_options, dest->options))); + ui->printerList->addTopLevelItem(wi); + if (dest->is_default) + ui->printerList->setCurrentItem(wi); } - // Check color capabilities - if (res & CUPS_PRINTER_COLOR) - { - ui->comboBoxColor->setEnabled(true); - ui->comboBoxColor->setCurrentIndex(1); - } - else - { - ui->comboBoxColor->setEnabled(false); - ui->comboBoxColor->setCurrentIndex(0); - } + // Resize columns to contents + for (int i = 0; i < 3; ++i) + ui->printerList->resizeColumnToContents(i); - // Check duplex capabilities - if (res & CUPS_PRINTER_DUPLEX) - { - ui->comboBoxSides->setEnabled(true); - } - else - { - ui->comboBoxSides->setEnabled(false); - ui->comboBoxSides->setCurrentIndex(0); - } - - // Check copy capabilities - if (res & CUPS_PRINTER_COPIES) - { - ui->lineEditCopies->setEnabled(true); - ui->labelCopies->setEnabled(true); - } - else - { - ui->lineEditCopies->setEnabled(false); - ui->lineEditCopies->setText("1"); - ui->labelCopies->setEnabled(false); - } + /* Main Window properties */ - // Check availability - if (res & CUPS_PRINTER_REJECTING) - { - ui->buttonPrint->setEnabled(false); - } - else - { - ui->buttonPrint->setEnabled(true); - } + // Disable close button + this->setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint); + // center dialog on screen center + QRect desktopRect = QApplication::desktop()->screenGeometry(this); + this->move( desktopRect.width()/2-this->width()/2, + desktopRect.height()/2-this->height()/2); } - - -void MainWindow::on_buttonCancel_clicked() -{ - // Quit with code 1 - QCoreApplication::instance()->exit(1); +// ____________________________________________________________________________ +void MainWindow::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { + ui->printerList->setFocus(); + + cups_dest_t *dest =cupsGetNamedDest (CUPS_HTTP_DEFAULT, current->text(0).toAscii(), NULL); + + + /* * Check printer properties (auth, color, duplex, copies) * */ + // get printer capabilities + int res = ::atoi(cupsGetOption("printer-type", + dest->num_options, + dest->options)); + + // Check authentication + if (res & CUPS_PRINTER_AUTHENTICATED) { + ui->labelUser->setEnabled(true); + ui->labelPass->setEnabled(true); + ui->lineEditUser->setEnabled(true); + ui->lineEditPass->setEnabled(true); + } else { + ui->labelUser->setEnabled(false); + ui->labelPass->setEnabled(false); + ui->lineEditUser->setEnabled(false); + ui->lineEditPass->setEnabled(false); + } + + // Check color capabilities + if (res & CUPS_PRINTER_COLOR) { + ui->comboBoxColor->setEnabled(true); + ui->comboBoxColor->setCurrentIndex(1); + } else { + ui->comboBoxColor->setEnabled(false); + ui->comboBoxColor->setCurrentIndex(0); + } + + // Check duplex capabilities + if (res & CUPS_PRINTER_DUPLEX) { + ui->comboBoxSides->setEnabled(true); + } else { + ui->comboBoxSides->setEnabled(false); + ui->comboBoxSides->setCurrentIndex(0); + } + + // Check copy capabilities + if (res & CUPS_PRINTER_COPIES) { + ui->lineEditCopies->setEnabled(true); + ui->labelCopies->setEnabled(true); + } else { + ui->lineEditCopies->setEnabled(false); + ui->lineEditCopies->setText("1"); + ui->labelCopies->setEnabled(false); + } + + // Check availability + if (res & CUPS_PRINTER_REJECTING) { + ui->buttonPrint->setEnabled(false); + } else { + ui->buttonPrint->setEnabled(true); + } } +// ____________________________________________________________________________ +void MainWindow::on_buttonCancel_clicked() { + // Quit with code 1 + QCoreApplication::instance()->exit(1); +} - -void MainWindow::on_buttonPrint_clicked() -{ - QString cmd; - - // Wenn Farbe möglich ist. Aber trotzdem Graustufen gewählt - // Schieb file durch ghostscript - if (ui->comboBoxColor->isEnabled() && ui->comboBoxColor->currentIndex() == 0) - { - // Run ghostscript to make file grayscale - cmd = QString("gs -sDEVICE=psgray -dNOPAUSE -dBATCH -dQUIET -dSAFER -sOutputFile=\"%22\" \"%1\"").arg( - file, - file); - if (system(cmd.toAscii())) - return; // TODO WARN ABOUT MISSED GS JOB - +// ____________________________________________________________________________ +void MainWindow::on_buttonPrint_clicked() { + QString cmd; + + // Wenn Farbe möglich ist. Aber trotzdem Graustufen gewählt + // Schieb file durch ghostscript + if (ui->comboBoxColor->isEnabled() && ui->comboBoxColor->currentIndex() == 0) { + // Run ghostscript to make file grayscale + cmd = QString("gs -sDEVICE=psgray -dNOPAUSE -dBATCH -dQUIET -dSAFER -sOutputFile=\"%22\" \"%1\"").arg( + file, + file); + if (system(cmd.toAscii())) + return; // TODO WARN ABOUT MISSED GS JOB + + } + + /* * Print via cups lib * */ + + // Username + cupsSetUser(user); + + // Destination / Queue + cups_dest_t *dest = cupsGetDest( + ui->printerList->currentItem()->text(0).toAscii(), + NULL, + num_dests, + dests); + + // Duplex + if (ui->comboBoxSides->isEnabled()) { + switch (ui->comboBoxSides->currentIndex()) { + case 0: + dest->num_options = cupsAddOption ("Duplex", + "None", + dest->num_options, + &(dest->options)); + break; + case 1: + dest->num_options = cupsAddOption ("Duplex", + "DuplexNoTumble", + dest->num_options, + &(dest->options)); + break; + case 2: + dest->num_options = cupsAddOption ("Duplex", + "DuplexTumble", + dest->num_options, + &(dest->options)); + break; } + } + + // Kopien + if (ui->lineEditCopies->isEnabled()) { + dest->num_options = cupsAddOption ("copies", + ui->lineEditCopies->text().toAscii(), + dest->num_options, + &(dest->options)); + } + + // Drucken + if( 0 == cupsPrintFile(dest->name, + file, + NULL, + dest->num_options, + dest->options)) { + QMessageBox msgBox; + msgBox.setText(cupsLastErrorString()); + msgBox.exec(); + } else // Quit with code 0 + QCoreApplication::instance()->quit(); +} +/////////////////////////////// CODE PAPIERKORB ///////////////////////////// /* * Print via sysctem command * */ // // Username, part of whoami source @@ -211,70 +240,3 @@ void MainWindow::on_buttonPrint_clicked() // QTextStream (stdout, QIODevice::WriteOnly) << cmd; // // Execute the command // system(cmd.toAscii()); - - - - - /* * Print via cups lib * */ - - // Username - cupsSetUser(user); - - // Destination / Queue - cups_dest_t *dest = cupsGetDest( - ui->printerList->currentItem()->text(0).toAscii(), - NULL, - num_dests, - dests); - - // Duplex - if (ui->comboBoxSides->isEnabled()) - { - switch (ui->comboBoxSides->currentIndex()){ - case 0: - dest->num_options = cupsAddOption ("Duplex", - "None", - dest->num_options, - &(dest->options)); - break; - case 1: - dest->num_options = cupsAddOption ("Duplex", - "DuplexNoTumble", - dest->num_options, - &(dest->options)); - break; - case 2: - dest->num_options = cupsAddOption ("Duplex", - "DuplexTumble", - dest->num_options, - &(dest->options)); - break; - } - } - - // Kopien - if (ui->lineEditCopies->isEnabled()) - { - dest->num_options = cupsAddOption ("copies", - ui->lineEditCopies->text().toAscii(), - dest->num_options, - &(dest->options)); - } - - // Drucken - if( 0 == cupsPrintFile(dest->name, - file, - NULL, - dest->num_options, - dest->options)) - { - QMessageBox msgBox; - msgBox.setText(cupsLastErrorString()); - msgBox.exec(); - } - else // Quit with code 0 - QCoreApplication::instance()->quit(); - -} - - diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 022275e..9533e94 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -147,7 +147,7 @@ <bool>false</bool> </property> <property name="text"> - <string>Abrechen</string> + <string>Abbrechen</string> </property> </widget> </item> |