diff options
Diffstat (limited to 'src/maingui')
-rw-r--r-- | src/maingui/backdrop.cpp | 93 | ||||
-rw-r--r-- | src/maingui/backdrop.h | 13 | ||||
-rw-r--r-- | src/maingui/main.cpp | 1 | ||||
-rw-r--r-- | src/maingui/printergui.cpp | 5 | ||||
-rw-r--r-- | src/maingui/pwgui.cpp | 97 | ||||
-rw-r--r-- | src/maingui/pwgui.h | 40 | ||||
-rw-r--r-- | src/maingui/pwgui.ui | 135 |
7 files changed, 378 insertions, 6 deletions
diff --git a/src/maingui/backdrop.cpp b/src/maingui/backdrop.cpp index 4a907e8..db16b01 100644 --- a/src/maingui/backdrop.cpp +++ b/src/maingui/backdrop.cpp @@ -1,4 +1,6 @@ #include "backdrop.h" +#include "../util.h" +#include "pwgui.h" #include <QApplication> #include <QDesktopWidget> @@ -6,11 +8,18 @@ #include <QPaintEvent> #include <QPixmap> #include <QRgb> +#include <QLocalServer> +#include <QLocalSocket> +#include <sys/stat.h> + +static const QString strTest("test"); Backdrop::Backdrop() : QWidget(NULL), screenshot(NULL), - mainWindow(NULL) + mainWindow(NULL), + server(NULL), + pwgui(NULL) { QPixmap shot = QPixmap::grabWindow(QApplication::desktop()->winId()); if (!shot.isNull() && shot.height() > 0) { @@ -34,6 +43,75 @@ Backdrop::Backdrop() : screenshot = new QPixmap(shot); this->resize(screenshot->width(), screenshot->height()); this->setWindowFlags(Qt::Tool | Qt::CustomizeWindowHint | Qt::FramelessWindowHint); + + char sockPath[500]; + if (NULL != util_sockPath(-1, -1, sockPath, sizeof sockPath)) { + QString path = QString::fromUtf8(sockPath); + QFile::remove(path); + server = new QLocalServer(this); + if (server->listen(sockPath)) { + chmod(sockPath, 0600); + QObject::connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); + } + } + QObject::connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); +} + +QLocalSocket* Backdrop::getClient() +{ + QObject *sender = QObject::sender(); + if (sender == NULL || sender->property("test").toString() != strTest) + return NULL; + return (QLocalSocket*)sender; +} + +void Backdrop::newConnection() +{ + QLocalSocket *client; + while ((client = server->nextPendingConnection())) { + client->setProperty("test", strTest); + QObject::connect(client, SIGNAL(readyRead()), this, SLOT(incomingData())); + QObject::connect(client, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(closeConnection())); + QObject::connect(client, SIGNAL(disconnected()), this, SLOT(closeConnection())); + } +} + +void Backdrop::closeConnection() +{ + QLocalSocket *client = getClient(); + client->close(); + client->waitForDisconnected(50); + client->deleteLater(); +} + +void Backdrop::incomingData() +{ + QLocalSocket *client = getClient(); + char buffer[100]; + while (client->canReadLine()) { + if (client->readLine(buffer, sizeof buffer) > 0) { + if (strcmp(buffer, "open") == 0) { + if (pwgui == NULL) { + pwgui = new PwGui(this); + } + if (pwgui->isVisible()) { + client->write("busy\n"); + } else { + pwgui->exec(); + if (pwgui->isCancelled()) { + server->blockSignals(true); + client->write("cancel\n"); + client->waitForBytesWritten(1000); + client->close(); + client->waitForDisconnected(50); + QApplication::exit(0); + } + // Got some credentials, send to back end + client->write(pwgui->getUser().toUtf8() += '\0' += pwgui->getPassword() += '\0'); + } + } + } + } } Backdrop::~Backdrop() @@ -49,8 +127,19 @@ void Backdrop::paintEvent(QPaintEvent * event) void Backdrop::mouseReleaseEvent(QMouseEvent * event) { - if (mainWindow != NULL) { + if (pwgui != NULL && pwgui->isVisible()) { + pwgui->raise(); + pwgui->activateWindow(); + } else if (mainWindow != NULL && mainWindow->isVisible()) { mainWindow->raise(); mainWindow->activateWindow(); } } + +void Backdrop::aboutToQuit() +{ + if (server != NULL) { + QFile::remove(server->serverName()); + server->close(); + } +} diff --git a/src/maingui/backdrop.h b/src/maingui/backdrop.h index b798a89..7df6d40 100644 --- a/src/maingui/backdrop.h +++ b/src/maingui/backdrop.h @@ -4,6 +4,9 @@ #include <QWidget> class QPixmap; +class QLocalServer; +class QLocalSocket; +class PwGui; class Backdrop : public QWidget { @@ -12,6 +15,16 @@ class Backdrop : public QWidget private: const QPixmap * screenshot; QWidget * mainWindow; + QLocalServer * server; + PwGui * pwgui; + + QLocalSocket* getClient(); + +private slots: + void newConnection(); + void closeConnection(); + void incomingData(); + void aboutToQuit(); protected: virtual void paintEvent(QPaintEvent * event); diff --git a/src/maingui/main.cpp b/src/maingui/main.cpp index 25f81a0..be4099b 100644 --- a/src/maingui/main.cpp +++ b/src/maingui/main.cpp @@ -38,7 +38,6 @@ int main(int argc, char *argv[]) return a.exec(); } - static Backdrop* showGrayBackground() { Backdrop *bg = new Backdrop; diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp index 21e03f4..2506fd6 100644 --- a/src/maingui/printergui.cpp +++ b/src/maingui/printergui.cpp @@ -212,7 +212,7 @@ void PrinterGui::closeEvent(QCloseEvent * e) cupsCancelJob(ui->printerList->currentItem()->text(0).toUtf8().constData(), jobId); jobId = 0; } - QCoreApplication::instance()->exit(0); + QApplication::exit(0); } QDialog::closeEvent(e); } @@ -313,7 +313,6 @@ void PrinterGui::on_buttonPrint_clicked() ui->lineEditCopies->setEnabled(false); ui->printerList->setEnabled(false); } - } void PrinterGui::bgTimer_timeout() @@ -324,7 +323,7 @@ void PrinterGui::bgTimer_timeout() } if (++this->bgTimeout > 120) { // Job was sent, GUI is invisible, quit after a few seconds - QCoreApplication::instance()->exit(0); + QApplication::exit(0); } } diff --git a/src/maingui/pwgui.cpp b/src/maingui/pwgui.cpp new file mode 100644 index 0000000..635ca42 --- /dev/null +++ b/src/maingui/pwgui.cpp @@ -0,0 +1,97 @@ +#include "pwgui.h" +#include "ui_pwgui.h" +#include <QMessageBox> +#include <QTimer> +#include <QDialog> +#include <unistd.h> + +#define BUFLEN 400 + +// ____________________________________________________________________________ +PwGui::PwGui(QWidget *parent) : + QDialog(parent), + ui(new Ui::PwGui), + cancelled(true) +{ + // 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; +} + +const QString PwGui::getUser() const +{ + return ui->lineEditUser->text(); +} + +const QString PwGui::getPassword() const +{ + return ui->lineEditPass->text(); +} + +// ____________________________________________________________________________ +void PwGui::initializeUI(char *user) +{ + ui->setupUi(this); + this->setWindowModality(Qt::ApplicationModal); + // Put always on top + this->setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint); + + // 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); + + /* Main Window properties */ + + // 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 PwGui::on_accept() +{ + cancelled = false; + this->close(); +} + +// ____________________________________________________________________________ +void PwGui::on_reject() +{ + this->close(); +} + +void PwGui::keyPressEvent(QKeyEvent * e) +{ + if(e->key() != Qt::Key_Escape) { + QMainWindow::keyPressEvent(e); + return; + } + this->close(); +} + +void PwGui::hideEvent(QHideEvent * e) +{ + this->close(); +} + +int PwGui::exec() { + cancelled = true; + this->show(); + this->showNormal(); + this->raise(); + this->activateWindow(); + return QDialog::exec(); +} diff --git a/src/maingui/pwgui.h b/src/maingui/pwgui.h new file mode 100644 index 0000000..fa3f465 --- /dev/null +++ b/src/maingui/pwgui.h @@ -0,0 +1,40 @@ +#ifndef AUTHENTICATION_H +#define AUTHENTICATION_H + +#include <QDialog> +#include <QDebug> + +namespace Ui +{ +class PwGui; +} + +class QTimer; + +class PwGui : public QDialog +{ + Q_OBJECT + +public: + explicit PwGui(QWidget *parent = 0); + ~PwGui(); + const QString getUser() const; + const QString getPassword() const; + const bool isCancelled() const { return cancelled; }; + int exec(); + +protected: + void hideEvent(QHideEvent * e); + void keyPressEvent(QKeyEvent * e); + +private slots: + void on_accept(); + void on_reject(); + +private: + Ui::PwGui *ui; + void initializeUI(char *username); + bool cancelled; +}; + +#endif // AUTHENTICATION_H diff --git a/src/maingui/pwgui.ui b/src/maingui/pwgui.ui new file mode 100644 index 0000000..32678a8 --- /dev/null +++ b/src/maingui/pwgui.ui @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PwGui</class> + <widget class="QDialog" name="PwGui"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>310</width> + <height>160</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>Drucken - Authentifizierung</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Benutzername</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="lineEditUser"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Passwort</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="lineEditPass"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="labelStatus"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="frameShape"> + <enum>QFrame::Panel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="text"> + <string>Bitte Anmelden</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |