summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2016-12-21 16:05:37 +0100
committerSimon Rettberg2016-12-21 16:05:37 +0100
commit22478a51a4a897be6e67fe1f2a5165f3a27f4613 (patch)
treec87b4d5fd441a78a164cef3410006bdcc5d61bd8 /src
parent[pwgui] Steal env var for user prefix from printergui (diff)
downloadprintergui-22478a51a4a897be6e67fe1f2a5165f3a27f4613.tar.gz
printergui-22478a51a4a897be6e67fe1f2a5165f3a27f4613.tar.xz
printergui-22478a51a4a897be6e67fe1f2a5165f3a27f4613.zip
[maingui] Support SecuredPrint (Canon)
Diffstat (limited to 'src')
-rw-r--r--src/maingui/printergui.cpp93
-rw-r--r--src/maingui/printergui.h5
-rw-r--r--src/maingui/printergui.ui48
3 files changed, 133 insertions, 13 deletions
diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp
index a7f993b..8758a6b 100644
--- a/src/maingui/printergui.cpp
+++ b/src/maingui/printergui.cpp
@@ -5,8 +5,8 @@
#include <QTimer>
#include <QStatusBar>
#include <QCloseEvent>
+#include <QFileInfo>
#include <pwd.h>
-#include <cups/ppd.h>
static QStringList knownColorOptions = QStringList() << "ColorModel" << "XRXColor";
static QStringList knownDuplexOptions = QStringList() << "Duplex";
@@ -20,6 +20,7 @@ static char* cleanCupsString(const char* in);
PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
QDialog(parent),
ui(new Ui::PrinterGui),
+ user(NULL),
statusBar(NULL),
bgTimeout(-1),
jobId(0)
@@ -29,10 +30,29 @@ PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
// 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 && pw->pw_name[0] != '\0') {
+ if (pw != NULL && pw->pw_dir != NULL && pw->pw_dir[0] == '/') {
+ // Special case - .account file in user home, but only if it is owned by root
+ QFile file(QString(pw->pw_dir).append("/.account"));
+ if (file.exists()) {
+ QFileInfo fi(file);
+ // If owned by root, not writable by group or other, read user stored inside
+ if ((fi.permissions() & (QFile::WriteGroup | QFile::WriteOther)) == 0 && fi.owner() == "root" && file.open(QIODevice::ReadOnly)) {
+ char buffer[20];
+ qint64 ret = file.readLine(buffer, sizeof(buffer));
+ if (ret > 0) {
+ if (buffer[ret - 1] == '\n') {
+ buffer[ret - 1] = '\0';
+ }
+ this->user = strdup(buffer);
+ }
+ }
+ }
+ }
+ if (this->user == NULL && pw != NULL && pw->pw_name != NULL && pw->pw_name[0] != '\0') {
// Detect real name
this->user = strdup(pw->pw_name);
- } else {
+ }
+ if (this->user == NULL) {
// Fallback to what command line says
this->user = strdup(argv[1]);
}
@@ -51,6 +71,7 @@ PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
this->bgTimer = new QTimer(this);
connect(bgTimer, SIGNAL(timeout()), this, SLOT(bgTimer_timeout()));
this->bgTimer->start(1000);
+ ui->txtUserId->setText(this->user);
}
// ____________________________________________________________________________
@@ -82,7 +103,7 @@ void PrinterGui::initializeUI()
/* Initialize Treeview */
ui->printerList->setColumnCount(3);
- ui->printerList->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
+ //ui->printerList->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
// Rename headers
QStringList h;
@@ -132,6 +153,49 @@ void PrinterGui::initializeUI()
this->activateWindow();
}
+void PrinterGui::handleTrustedPrint(ppd_file_t *ppd)
+{
+ bool supported = false;
+ bool enabled = false;
+ QString pwProperty, pwMask;
+ static QRegExpValidator sevenNum(QRegExp("^[0-9]{1,7}$"));
+ QRegExpValidator *pwValidator = NULL;
+
+
+ for (ppd_option_t *o = ppdFirstOption(ppd); o != NULL; o = ppdNextOption(ppd)) {
+ if (strcmp(o->keyword, "UseSecure") == 0) {
+ supported = true;
+ enabled = (strcmp(o->defchoice, "On") == 0);
+ } else if (strcmp(o->keyword, "SecuredPassword") == 0) {
+ pwProperty = o->keyword;
+ pwValidator = &sevenNum;
+ } else if (strcmp(o->keyword, "UserPassword") == 0) {
+ if (pwProperty.isEmpty()) {
+ pwProperty = o->keyword;
+ pwValidator = &sevenNum;
+ }
+ }
+ }
+ ui->txtUserPin->setProperty("key", pwProperty);
+ ui->txtUserPin->setValidator(pwValidator);
+ ui->chkSecurePrint->setChecked(enabled);
+ for (int i = 0; i < ui->gridSecurePrint->count(); ++i) {
+ QWidget *child = ui->gridSecurePrint->itemAt(i)->widget();
+ if (child != NULL) {
+ child->setVisible(supported);
+ }
+ }
+}
+
+void PrinterGui::on_chkSecurePrint_stateChanged(int state)
+{
+ ui->txtUserId->setEnabled(state == Qt::Checked);
+ ui->txtUserPin->setEnabled(state == Qt::Checked);
+ if (state == Qt::Checked) {
+ ui->txtUserPin->setFocus();
+ }
+}
+
static void enableOptionSelection(ppd_file_t *ppd, QStringList &nameList, QComboBox *combo, QLabel *label, bool forceDisabled)
{
// Check for each option if it matches an
@@ -196,6 +260,7 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
enableOptionSelection(ppd, knownDuplexOptions, ui->comboBoxSides, ui->label_duplex, false);
// TODO: Make it so this selection overrides what the document specifies
enableOptionSelection(ppd, knownPageSizeOptions, ui->cboPaperSize, ui->lblPaperSize, true);
+ handleTrustedPrint(ppd);
ppdClose(ppd);
} else {
qDebug() << "ppd is null"<< dest->name << cupsLastErrorString();
@@ -267,6 +332,8 @@ void PrinterGui::on_buttonPrint_clicked()
num_dests,
dests);
+ // In dest we have the default options
+
// Color
QString colorKey = ui->comboBoxColor->property("key").toString();
if (!colorKey.isEmpty()) {
@@ -301,7 +368,21 @@ void PrinterGui::on_buttonPrint_clicked()
dest->num_options = cupsRemoveOption("InputSlot", dest->num_options, &(dest->options));
- cupsSetUser(this->user);
+ // If we use secured print, allow overriding username
+ if (ui->txtUserId->isHidden() || ui->txtUserId->text().isEmpty()) {
+ cupsSetUser(this->user);
+ } else {
+ cupsSetUser(ui->txtUserId->text().toUtf8().constData());
+ }
+ // Secured print -> set pin
+ if (!ui->txtUserPin->isHidden()) {
+ QString pinKey = ui->txtUserPin->property("key").toString();
+ dest->num_options = cupsAddOption(pinKey.toUtf8().constData(),
+ ui->txtUserPin->text().toUtf8().constData(),
+ dest->num_options,
+ &(dest->options));
+ }
+
char jobtitle[250];
const char *docName;
docName = getenv("J");
@@ -342,6 +423,8 @@ void PrinterGui::bgTimer_timeout()
{
if (this->bgTimeout == -1) {
// Could do something here every second....
+ this->raise();
+ this->activateWindow();
return;
}
if (++this->bgTimeout > 120) {
diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h
index 88ec685..55a4ddb 100644
--- a/src/maingui/printergui.h
+++ b/src/maingui/printergui.h
@@ -5,7 +5,8 @@
#include <QDebug>
#include <QDesktopWidget>
#include <QTreeWidget>
-#include "cups/cups.h"
+#include <cups/cups.h>
+#include <cups/ppd.h>
namespace Ui
{
@@ -35,11 +36,13 @@ private slots:
void on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_buttonCancel_clicked();
void on_buttonPrint_clicked();
+ void on_chkSecurePrint_stateChanged(int state);
void bgTimer_timeout();
private:
Ui::PrinterGui *ui;
void initializeUI();
+ void handleTrustedPrint(ppd_file_t *ppd);
cups_dest_t *dests;
int num_dests;
char * user;
diff --git a/src/maingui/printergui.ui b/src/maingui/printergui.ui
index 4666390..047c5ac 100644
--- a/src/maingui/printergui.ui
+++ b/src/maingui/printergui.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>629</width>
- <height>330</height>
+ <height>394</height>
</rect>
</property>
<property name="minimumSize">
@@ -19,14 +19,14 @@
<property name="windowTitle">
<string>Druckauftrag</string>
</property>
- <layout class="QGridLayout" name="gridLayout_3">
- <property name="margin">
- <number>0</number>
- </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>5</number>
</property>
- <item row="0" column="0">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>5</number>
@@ -47,6 +47,40 @@
</widget>
</item>
<item>
+ <layout class="QGridLayout" name="gridSecurePrint">
+ <item row="2" column="2">
+ <widget class="QLineEdit" name="txtUserPin"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>UserID</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLineEdit" name="txtUserId"/>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>PIN</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="chkSecurePrint">
+ <property name="text">
+ <string>Geschützter Druck</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxColor"/>
@@ -220,7 +254,7 @@
</item>
</layout>
</item>
- <item row="1" column="0">
+ <item>
<layout class="QVBoxLayout" name="statusBarLayout">
<property name="spacing">
<number>0</number>