summaryrefslogtreecommitdiffstats
path: root/src/maingui/printergui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/maingui/printergui.cpp')
-rw-r--r--src/maingui/printergui.cpp286
1 files changed, 141 insertions, 145 deletions
diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp
index 2724776..99980f2 100644
--- a/src/maingui/printergui.cpp
+++ b/src/maingui/printergui.cpp
@@ -8,32 +8,32 @@
// ____________________________________________________________________________
PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::PrinterGui)
- //bgTimeout(-1)
+ QMainWindow(parent),
+ ui(new Ui::PrinterGui)
+ //bgTimeout(-1)
{
- // When called it is guaranteed that argv has (at least) 3 elements
+ // When called it is guaranteed that argv has (at least) 3 elements
- // Set username
- // Do not use getlogin[_r] as it doesn't fucking work!
+ // Set username
+ // Do not use getlogin[_r] as it doesn't fucking work!
// struct passwd *pw = getpwuid(getuid());
// if (pw != NULL && pw->pw_name != NULL) {
// // Detect real name
// this->user = strdup(pw->pw_name);
// } else {
// // Fallback to what command line says
- this->user = strdup(argv[1]);
+ this->user = strdup(argv[1]);
// }
- // Filename
- this->file = new char[strlen(argv[2]) + 10]; // + 10 in case we rename (ghostscript)
- strcpy(this->file, argv[2]);
+ // Filename
+ this->file = new char[strlen(argv[2]) + 10]; // + 10 in case we rename (ghostscript)
+ strcpy(this->file, argv[2]);
- // Initialize cups
- num_dests = cupsGetDests(&dests);
+ // Initialize cups
+ num_dests = cupsGetDests(&dests);
- // Initialize UI
- initializeUI();
+ // Initialize UI
+ initializeUI();
// // Timer
// this->bgTimer = new QTimer(this);
@@ -45,65 +45,67 @@ PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
// ____________________________________________________________________________
PrinterGui::~PrinterGui()
{
- cupsFreeDests(num_dests, dests);
- free(this->user);
- delete[] this->file;
- delete this->ui;
+ cupsFreeDests(num_dests, dests);
+ free(this->user);
+ delete[] this->file;
+ delete this->ui;
}
// ____________________________________________________________________________
void PrinterGui::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::fromUtf8(dest->name));
- wi->setText(1, QString::fromUtf8(cupsGetOption("printer-info", dest->num_options, dest->options)));
- wi->setText(2, QString::fromUtf8(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((this->windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::WindowStaysOnTopHint);
- // 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);
- this->setWindowTitle(QString::fromUtf8("Drucken - %1").arg(this->user));
+ 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::fromUtf8(dest->name));
+ wi->setText(1, QString::fromUtf8(cupsGetOption("printer-info", dest->num_options, dest->options)));
+ wi->setText(2, QString::fromUtf8(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((this->windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::WindowStaysOnTopHint);
+ // 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);
+ this->setWindowTitle(QString::fromUtf8("Drucken - %1").arg(this->user));
ui->comboBoxColor->hide();
ui->comboBoxSides->hide();
ui->label_color->hide();
ui->label_duplex->hide();
- this->show();
- this->showNormal();
- this->raise();
- this->activateWindow();
+ this->show();
+ this->showNormal();
+ this->raise();
+ this->activateWindow();
}
@@ -111,19 +113,19 @@ void PrinterGui::initializeUI()
// ____________________________________________________________________________
void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
- ui->printerList->setFocus();
+ 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) * */
+ /* * Check printer properties (auth, color, duplex, copies) * */
- // get printer capabilities
- const char *type = cupsGetOption("printer-type", dest->num_options, dest->options);
- int res = 0;
- if (type != NULL) {
- res = ::atoi(type);
- }
+ // get printer capabilities
+ const char *type = cupsGetOption("printer-type", dest->num_options, dest->options);
+ int res = 0;
+ if (type != NULL) {
+ res = ::atoi(type);
+ }
// ui->comboBoxSides->hide();
// ui->comboBoxColor->hide();
@@ -131,31 +133,27 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
// ui->label_duplex->hide();
ppd_file_t *ppd = ppdOpenFile(cupsGetPPD2(CUPS_HTTP_DEFAULT, dest->name));
- if (ppd != NULL)
- {
+ if (ppd != NULL) {
// Check color capabilities
- if (res & CUPS_PRINTER_COLOR)
- {
+ if (res & CUPS_PRINTER_COLOR) {
// Check for each option if it matches an
_colorOptionName.clear();
QStringList knownColorOptions;
knownColorOptions << "ColorModel" << "XRXColor"; // TODO read from a file
- for (ppd_option_t *o = ppdFirstOption(ppd); o != NULL; o = ppdNextOption(ppd))
- {
+ for (ppd_option_t *o = ppdFirstOption(ppd); o != NULL; o = ppdNextOption(ppd)) {
QString option(o->keyword);
for (QStringList::iterator it = knownColorOptions.begin();
- it != knownColorOptions.end(); ++it)
- {
- if(option.contains(*it))
- {
+ it != knownColorOptions.end(); ++it) {
+ if(option.contains(*it)) {
_colorOptionName = option;
// Add the choices to the combobox
ui->comboBoxColor->clear();
for (int i = 0; i < o->num_choices; ++i) {
ui->comboBoxColor->addItem(o->choices[i].text, o->choices[i].choice);
- if (strcmp(o->choices[i].choice, o->defchoice) == 0)
+ if (strcmp(o->choices[i].choice, o->defchoice) == 0) {
ui->comboBoxColor->setCurrentIndex(i);
+ }
}
ui->comboBoxColor->show();
ui->label_color->show();
@@ -173,21 +171,19 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
QStringList knownDuplexOptions;
knownDuplexOptions << "Duplex"; // TODO read from a file
- for (ppd_option_t *o = ppdFirstOption(ppd); o != NULL; o = ppdNextOption(ppd))
- {
+ for (ppd_option_t *o = ppdFirstOption(ppd); o != NULL; o = ppdNextOption(ppd)) {
QString option(o->keyword);
for (QStringList::iterator it = knownDuplexOptions.begin();
- it != knownDuplexOptions.end(); ++it)
- {
- if (option == *it)
- {
+ it != knownDuplexOptions.end(); ++it) {
+ if (option == *it) {
_duplexOptionName = option;
// Add the choices to the combobox
ui->comboBoxSides->clear();
for (int i = 0; i < o->num_choices; ++i) {
ui->comboBoxSides->addItem(o->choices[i].text, o->choices[i].choice);
- if (strcmp(o->choices[i].choice, o->defchoice) == 0)
+ if (strcmp(o->choices[i].choice, o->defchoice) == 0) {
ui->comboBoxSides->setCurrentIndex(i);
+ }
}
ui->comboBoxSides->show();
ui->label_duplex->show();
@@ -197,86 +193,86 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
}
}
}
- }
- else
+ } else {
qDebug() << "ppd is null"<< dest->name << cupsLastErrorString();
+ }
+
+ // 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 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);
- }
+ // Check availability
+ if (res & CUPS_PRINTER_REJECTING) {
+ ui->buttonPrint->setEnabled(false);
+ } else {
+ ui->buttonPrint->setEnabled(true);
+ }
}
// ____________________________________________________________________________
void PrinterGui::on_buttonCancel_clicked()
{
- // Quit with code 1
- QCoreApplication::instance()->exit(1);
+ // Quit with code 1
+ QCoreApplication::instance()->exit(1);
}
// ____________________________________________________________________________
void PrinterGui::on_buttonPrint_clicked()
{
- QString cmd;
+ QString cmd;
- /* * Print via cups lib * */
+ /* * Print via cups lib * */
- // Destination / Queue
- cups_dest_t *dest = cupsGetDest(
- ui->printerList->currentItem()->text(0).toUtf8().constData(),
- NULL,
- num_dests,
- dests);
+ // Destination / Queue
+ cups_dest_t *dest = cupsGetDest(
+ ui->printerList->currentItem()->text(0).toUtf8().constData(),
+ NULL,
+ num_dests,
+ dests);
// Color
if (!_colorOptionName.isEmpty())
dest->num_options = cupsAddOption (_colorOptionName.toStdString().c_str(),
- ui->comboBoxColor->itemData(ui->comboBoxColor->currentIndex()).toString().toStdString().c_str(),
- dest->num_options,
- &(dest->options));
+ ui->comboBoxColor->itemData(ui->comboBoxColor->currentIndex()).toString().toStdString().c_str(),
+ dest->num_options,
+ &(dest->options));
// Duplex
if (!_duplexOptionName.isEmpty())
dest->num_options = cupsAddOption (_duplexOptionName.toStdString().c_str(),
- ui->comboBoxSides->itemData(ui->comboBoxSides->currentIndex()).toString().toStdString().c_str(),
- dest->num_options,
- &(dest->options));
- // Kopien
- if (ui->lineEditCopies->isEnabled()) {
- dest->num_options = cupsAddOption ("copies",
- ui->lineEditCopies->text().toUtf8().constData(),
- dest->num_options,
- &(dest->options));
- }
-
- cupsSetUser(this->user);
- char jobtitle[100];
- snprintf(jobtitle, 100, "gui-%d-%s", (int)getpid(), this->user);
-
- // Drucken
- if( 0 == cupsPrintFile(dest->name,
- file,
- jobtitle,
- dest->num_options,
- dest->options)) {
- QMessageBox::critical(this, "CUPS Fehler", cupsLastErrorString());
- } else {
+ ui->comboBoxSides->itemData(ui->comboBoxSides->currentIndex()).toString().toStdString().c_str(),
+ dest->num_options,
+ &(dest->options));
+ // Kopien
+ if (ui->lineEditCopies->isEnabled()) {
+ dest->num_options = cupsAddOption ("copies",
+ ui->lineEditCopies->text().toUtf8().constData(),
+ dest->num_options,
+ &(dest->options));
+ }
+
+ cupsSetUser(this->user);
+ char jobtitle[100];
+ snprintf(jobtitle, 100, "gui-%d-%s", (int)getpid(), this->user);
+
+ // Drucken
+ if( 0 == cupsPrintFile(dest->name,
+ file,
+ jobtitle,
+ dest->num_options,
+ dest->options)) {
+ QMessageBox::critical(this, "CUPS Fehler", cupsLastErrorString());
+ } else {
//this->bgTimeout = 0;
QCoreApplication::instance()->exit(0);
this->hide();
QTimer::singleShot(4000, QCoreApplication::instance(), SLOT(quit()));
- }
+ }
}