summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-02-07 14:47:54 +0100
committerSimon Rettberg2014-02-07 14:47:54 +0100
commit0d5f4f33c46fdfda1f8a08e41dbe63711b00dd50 (patch)
tree5b988b0205f28c4c985cc89bc82b6b4adfb9d84b
parentGetting there, slowly: (diff)
downloadprintergui-0d5f4f33c46fdfda1f8a08e41dbe63711b00dd50.tar.gz
printergui-0d5f4f33c46fdfda1f8a08e41dbe63711b00dd50.tar.xz
printergui-0d5f4f33c46fdfda1f8a08e41dbe63711b00dd50.zip
Implement writing filled out form back to pipe
-rw-r--r--src/pwgui/main.cpp6
-rw-r--r--src/pwgui/pwgui.cpp39
-rw-r--r--src/pwgui/pwgui.h9
3 files changed, 30 insertions, 24 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index c33b3f6..77ec7f0 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -126,6 +126,8 @@ int main(int argc, char *argv[])
// Seems we need the dialog
int status;
+ char creds[NAMELEN], *pass = NULL;
+ snprintf(creds, NAMELEN, "%s", argv[3]);
do {
int pfd[2];
if (pipe(pfd) != 0) {
@@ -139,7 +141,7 @@ int main(int argc, char *argv[])
helper_dropprivs();
helper_copyenv();
QApplication a(argc, argv);
- PwGui w(pfd[1]);
+ PwGui w(pfd[1], creds);
w.show();
exit(a.exec());
return CUPS_BACKEND_FAILED;
@@ -147,8 +149,8 @@ int main(int argc, char *argv[])
// Main (Parent)
close(pfd[1]);
// Read from pipe
- char creds[NAMELEN], *pass = NULL;
int bytes = read(pfd[0], creds, NAMELEN - 1);
+ close(pfd[0]);
// Wait for child to die
waitpid(pid, NULL, 0); // Don't check status, just look at pipe data
if (bytes <= 0) {
diff --git a/src/pwgui/pwgui.cpp b/src/pwgui/pwgui.cpp
index 448cee8..24c7b0c 100644
--- a/src/pwgui/pwgui.cpp
+++ b/src/pwgui/pwgui.cpp
@@ -4,14 +4,18 @@
#include <QTimer>
#include <QDesktopWidget>
+#define BUFLEN 400
+
// ____________________________________________________________________________
-PwGui::PwGui(int pfd, QWidget *parent) :
+PwGui::PwGui(int pfd, char *user, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::PwGui),
pipefd(pfd)
{
// Initialize UI
- initializeUI();
+ initializeUI(user);
+ connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(on_accept()));
+ connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(on_reject()));
}
// ____________________________________________________________________________
@@ -21,16 +25,14 @@ PwGui::~PwGui()
}
// ____________________________________________________________________________
-void PwGui::initializeUI()
+void PwGui::initializeUI(char *user)
{
ui->setupUi(this);
- /*
// Prefill username
- if (this->user != NULL) {
+ if (user != NULL) {
ui->lineEditUser->setText(QString::fromUtf8(user));
}
- */
// Protect password from being seen
ui->lineEditPass->setEchoMode(QLineEdit::Password);
@@ -43,23 +45,26 @@ void PwGui::initializeUI()
// 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);
+ desktopRect.height()/2-this->height()/2 );
}
-/*
-void PwGui::on_buttonCancel_clicked()
+// ____________________________________________________________________________
+void PwGui::on_accept()
{
- // Quit with code 1
- QCoreApplication::instance()->exit(1);
+ 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_checkStatusTimer()
+void PwGui::on_reject()
{
- static int retries = 0;
- if (++retries > 20) {
- QCoreApplication::instance()->quit();
- }
+ // Quit with code 1
+ QCoreApplication::instance()->exit(1);
}
diff --git a/src/pwgui/pwgui.h b/src/pwgui/pwgui.h
index 95a7a05..07070b5 100644
--- a/src/pwgui/pwgui.h
+++ b/src/pwgui/pwgui.h
@@ -3,7 +3,6 @@
#include <QMainWindow>
#include <QDebug>
-#include <QTimer>
namespace Ui {
class PwGui;
@@ -16,16 +15,16 @@ class PwGui : public QMainWindow
Q_OBJECT
public:
- explicit PwGui(int pfd, QWidget *parent = 0);
+ explicit PwGui(int pfd, char *user, QWidget *parent = 0);
~PwGui();
private slots:
- void on_checkStatusTimer();
+ void on_accept();
+ void on_reject();
private:
Ui::PwGui *ui;
- void initializeUI();
- QTimer* checkStatusTimer;
+ void initializeUI(char *username);
int pipefd;
};