summaryrefslogtreecommitdiffstats
path: root/src/maingui/backdrop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/maingui/backdrop.cpp')
-rw-r--r--src/maingui/backdrop.cpp93
1 files changed, 91 insertions, 2 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();
+ }
+}