summaryrefslogtreecommitdiffstats
path: root/src/client/vnc/vncserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/vnc/vncserver.cpp')
-rw-r--r--src/client/vnc/vncserver.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp
index d819668..7db8423 100644
--- a/src/client/vnc/vncserver.cpp
+++ b/src/client/vnc/vncserver.cpp
@@ -6,11 +6,15 @@
*/
-#include <QApplication>
+#include <QGuiApplication>
#include <QProcess>
-#include <QDesktopWidget>
+#include <QScreen>
#include "vncserver.h"
#include "../util/util.h"
+#include "../../shared/util.h"
+
+// Remove in future - see util.h
+#undef errorOccurred
VncServer* VncServer::me = nullptr;
@@ -34,7 +38,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 +57,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 +78,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 +103,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 +145,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 +219,7 @@ void VncServer::onStdErr()
qDebug("VncServer::onStdErr() called in bad state.");
return;
}
- QByteArray data(_process->readAllStandardError());
+ _process->readAllStandardError(); // Throw away
}
/**
@@ -232,7 +236,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);