From 9f479b8f76238a03bce5d13aee14efd34e659c6e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 30 Oct 2022 20:34:23 +0100 Subject: 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 and , but specific includes instead --- src/client/vnc/vncserver.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/client/vnc/vncserver.cpp') 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 +#include #include -#include +#include #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 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::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); -- cgit v1.2.3-55-g7522