summaryrefslogtreecommitdiffstats
path: root/src/client/vnc/vncserver.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2022-10-30 20:34:23 +0100
committerSimon Rettberg2022-10-30 20:34:23 +0100
commit9f479b8f76238a03bce5d13aee14efd34e659c6e (patch)
treee320d32838202ac4604032da7a4bc3702cc304da /src/client/vnc/vncserver.cpp
parentUpdate translation files (diff)
downloadpvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.tar.gz
pvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.tar.xz
pvs2-9f479b8f76238a03bce5d13aee14efd34e659c6e.zip
Clean up and modernize code
- static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use <QtWidgets> and <QtCore>, but specific includes instead
Diffstat (limited to 'src/client/vnc/vncserver.cpp')
-rw-r--r--src/client/vnc/vncserver.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp
index d819668..4c2363e 100644
--- a/src/client/vnc/vncserver.cpp
+++ b/src/client/vnc/vncserver.cpp
@@ -6,11 +6,12 @@
*/
-#include <QApplication>
+#include <QGuiApplication>
#include <QProcess>
-#include <QDesktopWidget>
+#include <QScreen>
#include "vncserver.h"
#include "../util/util.h"
+#include "../../shared/util.h"
VncServer* VncServer::me = nullptr;
@@ -34,7 +35,7 @@ static QString makePassword(int len = 10)
{
QString ret(len, Qt::Uninitialized);
for (int i = 0; i < len; ++i)
- ret[i] = QChar(43 + qrand() % 80);
+ ret[i] = QChar(43 + slxrand() % 80);
return ret;
}
@@ -53,7 +54,7 @@ VncServer::VncServer() : _process(nullptr), _port(0), _timerId(0) {}
/**
* @brief VncServer::~VncServer
*/
-VncServer::~VncServer() {}
+VncServer::~VncServer() = default;
QSharedPointer<QFile> VncServer::createPwFile(const QDir& dir)
{
@@ -74,8 +75,8 @@ void VncServer::start()
{
// Keep things clean
if (_process != nullptr) {
- disconnect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
- disconnect(_process, SIGNAL(finished(int)), this, SLOT(onFinished(int)));
+ _process->blockSignals(true);
+ _process->kill();
}
this->stop();
// Generate passwords
@@ -99,22 +100,22 @@ void VncServer::start()
pwhandle->close();
// Create new process
_process = new QProcess(this);
- connect(_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStdOut()));
- connect(_process, SIGNAL(readyReadStandardError()), this, SLOT(onStdErr()));
- connect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
- connect(_process, SIGNAL(finished(int)), this, SLOT(onFinished(int)));
+ connect(_process, &QProcess::readyReadStandardOutput, this, &VncServer::onStdOut);
+ connect(_process, &QProcess::readyReadStandardError, this, &VncServer::onStdErr);
+ connect(_process, &QProcess::errorOccurred, this, &VncServer::onError);
+ connect(_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
+ this, &VncServer::onFinished);
_timerId = startTimer(4000);
QStringList args;
args << "-forever";
args << "-display" << ":0";
- args << "-passwdfile" << (QString("rm:" + pwhandle->fileName()));
+ args << "-passwdfile" << (QStringLiteral("rm:") + pwhandle->fileName());
args << "-shared";
args << "-repeat";
args << "-autoport" << QString::number(54112);
// Get rect of primary screen
- const QDesktopWidget desktop;
- const QRect primaryRect = desktop.screenGeometry();
+ const QRect primaryRect = QGuiApplication::primaryScreen()->geometry();
// Tell x11vnc to just use primary screen
args << "-clip";
@@ -141,8 +142,8 @@ void VncServer::stop()
if (_process == nullptr)
return;
qDebug("Stopping old VNC server.");
- disconnect(_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStdOut()));
- disconnect(_process, SIGNAL(readyReadStandardError()), this, SLOT(onStdErr()));
+ disconnect(_process, &QProcess::readyReadStandardOutput, this, &VncServer::onStdOut);
+ disconnect(_process, &QProcess::readyReadStandardError, this, &VncServer::onStdErr);
QProcess *process = _process;
_process = nullptr;
_port = 0;
@@ -215,7 +216,7 @@ void VncServer::onStdErr()
qDebug("VncServer::onStdErr() called in bad state.");
return;
}
- QByteArray data(_process->readAllStandardError());
+ _process->readAllStandardError(); // Throw away
}
/**
@@ -232,7 +233,7 @@ void VncServer::onError(QProcess::ProcessError /* error */ )
* @brief VncServer::onFinished
* @param exitCode
*/
-void VncServer::onFinished(int /* exitCode */ )
+void VncServer::onFinished(int /* exitCode */, QProcess::ExitStatus /* exitStatus */)
{
this->stop();
emit started(0, _ropass, _rwpass);