summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2015-02-03 17:17:17 +0100
committerSimon Rettberg2015-02-03 17:17:17 +0100
commit5caf1c18bb4f686c140cb58bd1f7bf50fb783c43 (patch)
tree3c381ae1d51a7ff409880d704c5594344a840615 /src
parentBring windows to top more agressively (diff)
downloadprintergui-5caf1c18bb4f686c140cb58bd1f7bf50fb783c43.tar.gz
printergui-5caf1c18bb4f686c140cb58bd1f7bf50fb783c43.tar.xz
printergui-5caf1c18bb4f686c140cb58bd1f7bf50fb783c43.zip
Consistent code formatting
Diffstat (limited to 'src')
-rw-r--r--src/maingui/main.cpp29
-rw-r--r--src/maingui/printergui.cpp286
-rw-r--r--src/maingui/printergui.h31
-rw-r--r--src/pwgui/main.cpp174
-rw-r--r--src/pwgui/pwgui.cpp76
-rw-r--r--src/pwgui/pwgui.h19
6 files changed, 320 insertions, 295 deletions
diff --git a/src/maingui/main.cpp b/src/maingui/main.cpp
index f9b8bb2..53aa68f 100644
--- a/src/maingui/main.cpp
+++ b/src/maingui/main.cpp
@@ -6,20 +6,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
- int fh = open(argv[2], O_RDONLY);
- if (fh < 0) {
- fprintf(stderr, "ERROR: Could not open %s for reading..\n", argv[2]);
- return 2;
- }
- close(fh);
+ // Check if file exists
+ int fh = open(argv[2], O_RDONLY);
+ if (fh < 0) {
+ fprintf(stderr, "ERROR: Could not open %s for reading..\n", argv[2]);
+ return 2;
+ }
+ close(fh);
- QApplication a(argc, argv);
- PrinterGui w(argv);
- w.show();
- return a.exec();
+ QApplication a(argc, argv);
+ PrinterGui w(argv);
+ w.show();
+ return a.exec();
}
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()));
- }
+ }
}
diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h
index 7dcea7c..77d50b4 100644
--- a/src/maingui/printergui.h
+++ b/src/maingui/printergui.h
@@ -7,7 +7,8 @@
#include <QTreeWidget>
#include "cups/cups.h"
-namespace Ui {
+namespace Ui
+{
class PrinterGui;
}
@@ -15,30 +16,30 @@ class QTimer;
class PrinterGui : public QMainWindow
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PrinterGui(char *argv[], QWidget *parent = 0);
- ~PrinterGui();
+ explicit PrinterGui(char *argv[], QWidget *parent = 0);
+ ~PrinterGui();
private slots:
- void on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
- void on_buttonCancel_clicked();
- void on_buttonPrint_clicked();
+ void on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
+ void on_buttonCancel_clicked();
+ void on_buttonPrint_clicked();
// void on_bgTimer_timeout();
private:
- Ui::PrinterGui *ui;
- void initializeUI();
- cups_dest_t *dests;
- int num_dests;
- char * user;
- char * file;
+ Ui::PrinterGui *ui;
+ void initializeUI();
+ cups_dest_t *dests;
+ int num_dests;
+ char * user;
+ char * file;
// QTimer * bgTimer;
// int bgTimeout;
- QString _colorOptionName;
- QString _duplexOptionName;
+ QString _colorOptionName;
+ QString _duplexOptionName;
};
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index e673108..4dcfbfb 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -95,8 +95,9 @@ int main(int argc, char *argv[])
// Mimic cups behaviour wrt dropping privs (Only 0700 or 0500 == root)
helper_loadlpuser();
struct stat st;
- if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0)
+ if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0) {
helper_dropprivs();
+ }
WARNING("Over and out.\n");
execv(backend, argv);
exit(127);
@@ -118,7 +119,9 @@ int main(int argc, char *argv[])
int total = 0;
for (;;) {
bytes = read(STDIN_FILENO, buffer, BUFLEN);
- if (bytes == 0) break;
+ if (bytes == 0) {
+ break;
+ }
if (bytes < 0) {
helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht auf STDIN empfangen.");
ERROR("Could not read print job from STDIN. Over and out.\n");
@@ -152,7 +155,9 @@ int main(int argc, char *argv[])
// Try right away with what we got
spoolres = run_backend(backend, device, argv[1], argv[2], argv[3], argv[4], argv[5], tmpfile, NULL);
- if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) return helper_cupsError(spoolres); // Yay
+ if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) {
+ return helper_cupsError(spoolres); // Yay
+ }
// Seems we need the dialog
int status;
@@ -193,7 +198,9 @@ int main(int argc, char *argv[])
}
creds[bytes] = '\0';
int len = strlen(creds);
- if (len < bytes) pass = creds + len + 1;
+ if (len < bytes) {
+ pass = creds + len + 1;
+ }
// Run backend with pimped user/pass
status = run_backend(backend, device, argv[1], creds, argv[3], argv[4], argv[5], tmpfile, pass);
helper_cupsError(status);
@@ -214,16 +221,22 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
dup2(pipefd[1], 2); // send stderr to pipe
close(pipefd[1]); // no longer needed after dup
// Newer backend can read credentials from environment
- if (user != NULL) setenv("AUTH_USERNAME", user, 1);
- if (password != NULL) setenv("AUTH_PASSWORD", password, 1);
+ if (user != NULL) {
+ setenv("AUTH_USERNAME", user, 1);
+ }
+ if (password != NULL) {
+ setenv("AUTH_PASSWORD", password, 1);
+ }
// Compute proper string length
int len = strlen(uri) + 20 + strlen("?waitprinter=no&waitjob=no");
- if (user != NULL)
+ if (user != NULL) {
len += strlen(user) * 3;
+ }
- if(password != NULL)
+ if(password != NULL) {
len += strlen(password) * 3;
+ }
char *newstr = (char*)malloc(len);
@@ -237,30 +250,28 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
*ptr++ = '@';
ptr += sprintf(ptr, "%s", uri + 8); // TODO: If uri already contains credentials, skip over them (check if there's a @ before the first /, starting at index 8)
// Since we've already forked and execv anyways there's no need to clean up anything...
- }
- else
+ } else {
strcpy(newstr, uri);
+ }
uri = newstr;
// Append wait options
if (strncmp(uri, "ipp:", 4) == 0
- || strncmp(uri, "ipp14:", 6) == 0
- || strncmp(uri, "ipps:", 5) == 0
- || strncmp(uri, "http:", 5) == 0
- || strncmp(uri, "https:", 6) == 0)
- {
- if (strchr(uri, '?') != NULL)
- {
+ || strncmp(uri, "ipp14:", 6) == 0
+ || strncmp(uri, "ipps:", 5) == 0
+ || strncmp(uri, "http:", 5) == 0
+ || strncmp(uri, "https:", 6) == 0) {
+ if (strchr(uri, '?') != NULL) {
// Question mark has been found, parse the options for waitprinter and
// waitjob.
- if(strstr(uri, "waitprinter=") == NULL)
+ if(strstr(uri, "waitprinter=") == NULL) {
strcat(uri, "&waitprinter=no");
- if(strstr(uri, "waitjob=") == NULL)
+ }
+ if(strstr(uri, "waitjob=") == NULL) {
strcat(uri, "&waitjob=no");
- }
- else
- {
+ }
+ } else {
// No question mark found. Fine hence just add the options
strcat(uri, "?waitprinter=no&waitjob=no");
}
@@ -279,7 +290,9 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
args[7] = NULL;
// Priv dropping
struct stat st;
- if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0) helper_dropprivs();
+ if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0) {
+ helper_dropprivs();
+ }
// Exec
execv(backend, args);
exit(127);
@@ -329,7 +342,9 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
return CUPS_BACKEND_FAILED;
}
status = WEXITSTATUS(status);
- if (status != CUPS_BACKEND_OK) ERROR("Backend returned %d\n", status);
+ if (status != CUPS_BACKEND_OK) {
+ ERROR("Backend returned %d\n", status);
+ }
return status;
}
@@ -383,7 +398,9 @@ static bool helper_getpiduid(char *user, char *title)
while ((ret = read(fh, ptr, ENVLEN - (ptr - gui_env) - 2)) > 0) {
bytes += ret;
ptr += ret;
- if (bytes + 3 >= ENVLEN) break;
+ if (bytes + 3 >= ENVLEN) {
+ break;
+ }
}
close(fh);
if (bytes >= 0) {
@@ -398,7 +415,9 @@ static bool helper_getpiduid(char *user, char *title)
static bool helper_loadlpuser()
{
struct passwd *pw = getpwnam("lp");
- if (pw == NULL) return false;
+ if (pw == NULL) {
+ return false;
+ }
ruid = pw->pw_uid;
rgid = pw->pw_gid;
return true;
@@ -406,7 +425,9 @@ static bool helper_loadlpuser()
static void helper_dropprivs()
{
- if (ruid == 0) return;
+ if (ruid == 0) {
+ return;
+ }
initgroups(ruser, rgid);
setgid(rgid);
setuid(ruid);
@@ -451,8 +472,11 @@ static char *helper_urlencode(char *source, char *enc)
unsigned char *s = (unsigned char*)source;
for (; *s != '\0'; s++) {
- if (table[*s] != '\0') len = sprintf(enc, "%c", table[*s]);
- else len = sprintf(enc, "%%%02X", *s);
+ if (table[*s] != '\0') {
+ len = sprintf(enc, "%c", table[*s]);
+ } else {
+ len = sprintf(enc, "%%%02X", *s);
+ }
enc += len;
}
*enc = '\0';
@@ -468,52 +492,52 @@ static char *helper_urlencode(char *source, char *enc)
static int helper_cupsError(const int code)
{
switch (code) {
- case CUPS_BACKEND_OK:
- helper_messageBox("CUPS", "Der Druckauftrag wurde erfolgreich an den print server übermittelt", false);
- return CUPS_BACKEND_OK;
-
- case CUPS_BACKEND_FAILED:
- // The print file was not successfully transmitted to the device or remote server. The scheduler will respond to this by canceling the job, retrying the job, or stopping the queue depending on the state of the error-policy attribute.
- helper_messageBox("CUPS Fehler", "Fehler beim lokalen Verarbeiten des Druckauftrags");
- return CUPS_BACKEND_HOLD;
-
- case CUPS_BACKEND_AUTH_REQUIRED:
- // The print file was not successfully transmitted because valid authentication information is required. The scheduler will respond to this by holding the job and adding the "cups-held-for-authentication" keyword to the "job-reasons" attribute.
- helper_messageBox("CUPS Fehler", "Authentifizierung am Druckserver/Drucker fehlgeschlagen");
- break;
-
- case CUPS_BACKEND_HOLD:
- // The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by holding the job.
- helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (3)");
- break;
-
- case CUPS_BACKEND_STOP:
- // The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by stopping the queue.
- helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (4)");
- return CUPS_BACKEND_HOLD;
-
- case CUPS_BACKEND_CANCEL:
- // The print file was not successfully transmitted because one or more attributes are not supported or the job was canceled at the printer. The scheduler will respond to this by canceling the job.
- helper_messageBox("CUPS Fehler", "Fehler 5 beim lokalen Verarbeiten des Druckauftrags");
- return CUPS_BACKEND_HOLD;
-
- case CUPS_BACKEND_RETRY:
- // The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job at a future time - other jobs may print before this one.
- helper_messageBox("CUPS Fehler", "Fehler 6 beim lokalen Verarbeiten des Druckauftrags");
- return CUPS_BACKEND_HOLD;
-
- case CUPS_BACKEND_RETRY_CURRENT:
- // The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job immediately without allowing intervening jobs.
- helper_messageBox("CUPS Fehler", "Fehler 7 beim lokalen Verarbeiten des Druckauftrags");
- return CUPS_BACKEND_HOLD;
-
- case CUSTOM_CUPS_NO_SUCH_PRINTER:
- helper_messageBox("CUPS Fehler", "Die Druckerwarteschlange existiert nicht auf dem print server. Fehlerhafte lokale printers.conf?");
- return CUPS_BACKEND_CANCEL;
- default:
- ERROR("Unknown cupsError code %d\n", code);
- helper_messageBox("CUPS Fehler", "Unbekannter Fehler beim Drucken", true);
- break;
+ case CUPS_BACKEND_OK:
+ helper_messageBox("CUPS", "Der Druckauftrag wurde erfolgreich an den print server übermittelt", false);
+ return CUPS_BACKEND_OK;
+
+ case CUPS_BACKEND_FAILED:
+ // The print file was not successfully transmitted to the device or remote server. The scheduler will respond to this by canceling the job, retrying the job, or stopping the queue depending on the state of the error-policy attribute.
+ helper_messageBox("CUPS Fehler", "Fehler beim lokalen Verarbeiten des Druckauftrags");
+ return CUPS_BACKEND_HOLD;
+
+ case CUPS_BACKEND_AUTH_REQUIRED:
+ // The print file was not successfully transmitted because valid authentication information is required. The scheduler will respond to this by holding the job and adding the "cups-held-for-authentication" keyword to the "job-reasons" attribute.
+ helper_messageBox("CUPS Fehler", "Authentifizierung am Druckserver/Drucker fehlgeschlagen");
+ break;
+
+ case CUPS_BACKEND_HOLD:
+ // The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by holding the job.
+ helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (3)");
+ break;
+
+ case CUPS_BACKEND_STOP:
+ // The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by stopping the queue.
+ helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (4)");
+ return CUPS_BACKEND_HOLD;
+
+ case CUPS_BACKEND_CANCEL:
+ // The print file was not successfully transmitted because one or more attributes are not supported or the job was canceled at the printer. The scheduler will respond to this by canceling the job.
+ helper_messageBox("CUPS Fehler", "Fehler 5 beim lokalen Verarbeiten des Druckauftrags");
+ return CUPS_BACKEND_HOLD;
+
+ case CUPS_BACKEND_RETRY:
+ // The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job at a future time - other jobs may print before this one.
+ helper_messageBox("CUPS Fehler", "Fehler 6 beim lokalen Verarbeiten des Druckauftrags");
+ return CUPS_BACKEND_HOLD;
+
+ case CUPS_BACKEND_RETRY_CURRENT:
+ // The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job immediately without allowing intervening jobs.
+ helper_messageBox("CUPS Fehler", "Fehler 7 beim lokalen Verarbeiten des Druckauftrags");
+ return CUPS_BACKEND_HOLD;
+
+ case CUSTOM_CUPS_NO_SUCH_PRINTER:
+ helper_messageBox("CUPS Fehler", "Die Druckerwarteschlange existiert nicht auf dem print server. Fehlerhafte lokale printers.conf?");
+ return CUPS_BACKEND_CANCEL;
+ default:
+ ERROR("Unknown cupsError code %d\n", code);
+ helper_messageBox("CUPS Fehler", "Unbekannter Fehler beim Drucken", true);
+ break;
}
return code;
}
diff --git a/src/pwgui/pwgui.cpp b/src/pwgui/pwgui.cpp
index b9473aa..193341b 100644
--- a/src/pwgui/pwgui.cpp
+++ b/src/pwgui/pwgui.cpp
@@ -9,67 +9,69 @@
// ____________________________________________________________________________
PwGui::PwGui(int pfd, char *user, QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::PwGui),
- pipefd(pfd)
+ QMainWindow(parent),
+ ui(new Ui::PwGui),
+ pipefd(pfd)
{
- // Initialize UI
- initializeUI(user);
- connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(on_accept()));
- connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(on_reject()));
+ // Initialize UI
+ initializeUI(user);
+ connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(on_accept()));
+ connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(on_reject()));
}
// ____________________________________________________________________________
PwGui::~PwGui()
{
- delete ui;
+ delete ui;
}
// ____________________________________________________________________________
void PwGui::initializeUI(char *user)
{
- ui->setupUi(this);
+ ui->setupUi(this);
- // Prefill username
- if (user != NULL) {
- ui->lineEditUser->setText(QString::fromUtf8(user));
- }
+ // Prefill username
+ if (user != NULL) {
+ ui->lineEditUser->setText(QString::fromUtf8(user));
+ }
- // Protect password from being seen
- ui->lineEditPass->setEchoMode(QLineEdit::Password);
- ui->lineEditPass->setInputMethodHints(ui->lineEditPass->inputMethodHints() | Qt::ImhNoAutoUppercase);
+ // Protect password from being seen
+ ui->lineEditPass->setEchoMode(QLineEdit::Password);
+ ui->lineEditPass->setInputMethodHints(ui->lineEditPass->inputMethodHints() | Qt::ImhNoAutoUppercase);
- /* Main Window properties */
+ /* 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->show();
- this->showNormal();
- this->raise();
- this->activateWindow();
+ // 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->show();
+ this->showNormal();
+ this->raise();
+ this->activateWindow();
}
// ____________________________________________________________________________
void PwGui::on_accept()
{
- char buffer[BUFLEN + 1];
- int len = snprintf(buffer, BUFLEN, "%s%c%s%c", ui->lineEditUser->text().toUtf8().constData(), 0, ui->lineEditPass->text().toUtf8().constData(), 0);
- if (len > BUFLEN) len = BUFLEN;
- buffer[len] = '\0';
- ::write(pipefd, buffer, len);
- ::close(pipefd);
- // Quit with code 0
- QCoreApplication::instance()->exit(0);
+ char buffer[BUFLEN + 1];
+ int len = snprintf(buffer, BUFLEN, "%s%c%s%c", ui->lineEditUser->text().toUtf8().constData(), 0, ui->lineEditPass->text().toUtf8().constData(), 0);
+ if (len > BUFLEN) {
+ len = BUFLEN;
+ }
+ buffer[len] = '\0';
+ ::write(pipefd, buffer, len);
+ ::close(pipefd);
+ // Quit with code 0
+ QCoreApplication::instance()->exit(0);
}
// ____________________________________________________________________________
void PwGui::on_reject()
{
- // Quit with code 1
- QCoreApplication::instance()->exit(1);
+ // Quit with code 1
+ QCoreApplication::instance()->exit(1);
}
diff --git a/src/pwgui/pwgui.h b/src/pwgui/pwgui.h
index 07070b5..348c5a1 100644
--- a/src/pwgui/pwgui.h
+++ b/src/pwgui/pwgui.h
@@ -4,7 +4,8 @@
#include <QMainWindow>
#include <QDebug>
-namespace Ui {
+namespace Ui
+{
class PwGui;
}
@@ -12,20 +13,20 @@ class QTimer;
class PwGui : public QMainWindow
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit PwGui(int pfd, char *user, QWidget *parent = 0);
- ~PwGui();
+ explicit PwGui(int pfd, char *user, QWidget *parent = 0);
+ ~PwGui();
private slots:
- void on_accept();
- void on_reject();
+ void on_accept();
+ void on_reject();
private:
- Ui::PwGui *ui;
- void initializeUI(char *username);
- int pipefd;
+ Ui::PwGui *ui;
+ void initializeUI(char *username);
+ int pipefd;
};
#endif // AUTHENTICATION_H