summaryrefslogtreecommitdiffstats
path: root/src/client/vnc
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/vnc')
-rw-r--r--src/client/vnc/vncserver.cpp38
-rw-r--r--src/client/vnc/vncserver.h12
-rw-r--r--src/client/vnc/vncthread.cpp40
-rw-r--r--src/client/vnc/vncthread.h12
-rw-r--r--src/client/vnc/vncwindow.cpp45
-rw-r--r--src/client/vnc/vncwindow.h7
6 files changed, 77 insertions, 77 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);
diff --git a/src/client/vnc/vncserver.h b/src/client/vnc/vncserver.h
index 4974946..1e71e2e 100644
--- a/src/client/vnc/vncserver.h
+++ b/src/client/vnc/vncserver.h
@@ -25,29 +25,29 @@ private:
int _timerId;
VncServer();
- virtual ~VncServer();
- QSharedPointer<QFile> createPwFile(const QDir& dir);
+ ~VncServer() override;
+ static QSharedPointer<QFile> createPwFile(const QDir& dir);
static VncServer *me;
public:
static VncServer *instance();
- inline bool isVncServerRunning() { return _port > 0; }
+ inline bool isVncServerRunning() const { return _port > 0; }
void start();
void stop();
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) override;
signals:
// Emited when started succesfully, or if startup failed. port will be <= 0 if it failed.
- void started(int port, QString& ropass, QString& rwpass);
+ void started(int port, const QString& ropass, const QString& rwpass);
private slots:
void onStdOut();
void onStdErr();
- void onFinished(int exitCode);
+ void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
void onError(QProcess::ProcessError error);
};
diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp
index 1a903d5..0e98cfe 100644
--- a/src/client/vnc/vncthread.cpp
+++ b/src/client/vnc/vncthread.cpp
@@ -17,8 +17,10 @@
*/
#include "vncthread.h"
-#include <QPainter>
+#include "../../shared/util.h"
+#include <QPainter>
+#include <utility>
#include <netinet/tcp.h>
/**
@@ -29,15 +31,15 @@
* @param passwd The password of the VNC server
* @param quality The desired quality level for the VNC stream
*/
-VncThread::VncThread(QString host, int port, QString passwd, int quality) :
- QThread(), _run(true), _started(false)
+VncThread::VncThread(QString host, int port, QString passwd, int quality)
+ : QThread()
+ , _host(std::move(host))
+ , _port(port)
+ , _passwd(std::move(passwd))
+ , _quality(quality)
+ , _run(true)
+ , _started(false)
{
- _host = host;
- _port = port;
- _passwd = passwd;
- _quality = quality;
- _client = nullptr;
- _connected = false;
moveToThread(this);
}
@@ -74,7 +76,7 @@ void VncThread::run()
// setup network
for (int retry = 0; retry < 5 && _run; ++retry) {
- this->msleep(1 + qrand() % 60);
+ msleep(1 + slxrand() % 60);
if (!_run)
break;
_client = rfbGetClient(8, 3, 4);
@@ -100,7 +102,7 @@ void VncThread::run()
if (!_run)
break;
// error, let's try again
- this->msleep(10 + qrand() % 50);
+ msleep(10 + slxrand() % 50);
}
if (_client != nullptr) {
qDebug("[%s] Connection successful!", metaObject()->className());
@@ -125,7 +127,7 @@ void VncThread::run()
_connected = false;
emit projectionStopped();
while (_run)
- this->msleep(100);
+ msleep(100);
qDebug("[%s] VNC client stopped.", metaObject()->className());
}
@@ -134,10 +136,10 @@ void VncThread::run()
*
* @return Name of the remote desktop
*/
-const QString VncThread::getDesktopName() const
+QString VncThread::getDesktopName() const
{
if (_client == nullptr || _client->desktopName == nullptr)
- return QString();
+ return {};
return QString(_client->desktopName);
}
@@ -172,7 +174,7 @@ void VncThread::emitStarted()
*/
char* VncThread::passwdHandler(rfbClient *client)
{
- VncThread* t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr));
+ auto* t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr));
return strdup(t->_passwd.toUtf8());
}
@@ -185,7 +187,7 @@ char* VncThread::passwdHandler(rfbClient *client)
*/
rfbBool VncThread::frameBufferHandler(rfbClient *client)
{
- VncThread *t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr));
+ auto *t = reinterpret_cast<VncThread*>(rfbClientGetClientData(client, nullptr));
const int width = client->width, height = client->height, depth = 32;
const int size = width * height * (depth / 8);
qDebug("[%s] Remote desktop: %ix%ix%i", t->metaObject()->className(), width, height, depth);
@@ -196,8 +198,8 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client)
}
t->_img = QSharedPointer<QImage>(new QImage(width, height, QImage::Format_RGB32));
- if (size > t->_img->byteCount()) {
- qDebug() << "Fatal: Created image too small:" << t->_img->byteCount() << "<" << size;
+ if (size > t->_img->sizeInBytes()) {
+ qDebug() << "Fatal: Created image too small:" << t->_img->sizeInBytes() << "<" << size;
::exit(1);
}
client->frameBuffer = t->_img->bits();
@@ -260,6 +262,6 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client)
*/
void VncThread::updateImage(rfbClient* client, int x, int y, int w, int h)
{
- VncThread* t = (VncThread*)rfbClientGetClientData(client, 0);
+ auto* t = (VncThread*)rfbClientGetClientData(client, 0);
t->processImageUpdate(x, y, w, h);
}
diff --git a/src/client/vnc/vncthread.h b/src/client/vnc/vncthread.h
index 16491fe..f7a020b 100644
--- a/src/client/vnc/vncthread.h
+++ b/src/client/vnc/vncthread.h
@@ -38,7 +38,7 @@ class VncThread : public QThread
Q_OBJECT
private:
- rfbClient *_client;
+ rfbClient *_client{};
QString _host;
int _port;
@@ -47,7 +47,7 @@ private:
QSharedPointer<QImage> _img;
- volatile bool _connected;
+ volatile bool _connected{};
volatile bool _run;
bool _started;
@@ -63,13 +63,13 @@ private:
public:
VncThread(QString host, int port, QString passwd, int quality);
- ~VncThread();
+ ~VncThread() override;
- const QString getDesktopName() const;
- bool isConnected() { return _connected; }
+ QString getDesktopName() const;
+ bool isConnected() const { return _connected; }
void stop() { _run = false; }
const QSharedPointer<QImage>& getFrameBuffer() { return _img; }
- void run();
+ void run() override;
int const static HIGH = 0;
int const static MEDIUM = 1;
diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp
index f7b6a3e..0947112 100644
--- a/src/client/vnc/vncwindow.cpp
+++ b/src/client/vnc/vncwindow.cpp
@@ -19,7 +19,11 @@
#include "vncthread.h"
#include "../clientapp/clientapp.h"
+#include <QGuiApplication>
#include <QTimer>
+#include <QPainter>
+#include <QScreen>
+#include <QKeyEvent>
/**
* Calc greatest common divisor.
@@ -39,15 +43,12 @@ VncWindow::VncWindow(QWidget *parent) :
QWidget(parent), _srcStepX(1), _srcStepY(1), _dstStepX(1), _dstStepY(1),
_vncWorker(nullptr), _viewOnly(true), _multiScreen(false), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0)
{
- QTimer *upper = new QTimer(this);
- connect(upper, SIGNAL(timeout()), this, SLOT(timer_moveToTop()));
+ auto *upper = new QTimer(this);
+ connect(upper, &QTimer::timeout, this, &VncWindow::timer_moveToTop);
upper->start(1111);
}
-VncWindow::~VncWindow()
-{
- //
-}
+VncWindow::~VncWindow() = default;
////////////////////////////////////////////////////////////////////////////////
// Private
@@ -64,10 +65,9 @@ void VncWindow::terminateVncThread()
if (_vncWorker == nullptr)
return;
- disconnect(_vncWorker, SIGNAL(projectionStopped()), this, SLOT(onProjectionStopped()));
- disconnect(_vncWorker, SIGNAL(projectionStarted()), this, SLOT(onProjectionStarted()));
- disconnect(_vncWorker, SIGNAL(imageUpdated(const int, const int, const int, const int)), this,
- SLOT(onUpdateImage(const int, const int, const int, const int)));
+ disconnect(_vncWorker, &VncThread::projectionStopped, this, &VncWindow::onProjectionStopped);
+ disconnect(_vncWorker, &VncThread::projectionStarted, this, &VncWindow::onProjectionStarted);
+ disconnect(_vncWorker, &VncThread::imageUpdated, this, &VncWindow::onUpdateImage);
_vncWorker->stop();
_vncWorker = nullptr;
if (_redrawTimer != 0) {
@@ -188,12 +188,10 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool
this->terminateVncThread();
_clientId = clientId;
_vncWorker = new VncThread(host, port, passwd, 1);
- connect(_vncWorker, SIGNAL(projectionStopped()), this, SLOT(onProjectionStopped()), Qt::QueuedConnection);
- connect(_vncWorker, SIGNAL(projectionStarted()), this, SLOT(onProjectionStarted()), Qt::QueuedConnection);
- connect(_vncWorker, SIGNAL(imageUpdated(const int, const int, const int, const int)), this,
- SLOT(onUpdateImage(const int, const int, const int, const int)),
- Qt::QueuedConnection);
- connect(_vncWorker, SIGNAL(finished()), this, SLOT(deleteVncThread()), Qt::QueuedConnection);
+ connect(_vncWorker, &VncThread::projectionStopped, this, &VncWindow::onProjectionStopped, Qt::QueuedConnection);
+ connect(_vncWorker, &VncThread::projectionStarted, this, &VncWindow::onProjectionStarted, Qt::QueuedConnection);
+ connect(_vncWorker, &VncThread::imageUpdated, this, &VncWindow::onUpdateImage, Qt::QueuedConnection);
+ connect(_vncWorker, &VncThread::finished, this, &VncWindow::deleteVncThread, Qt::QueuedConnection);
setWindowTitle(caption);
@@ -201,22 +199,18 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool
_remoteThumb.loadFromData(rawThumb);
- QSize size;
if (fullscreen) {
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool); // | Qt::X11BypassWindowManagerHint); <- better, but window won't get any keyboard input
// Show projection on rightmost screen
- QDesktopWidget *desktop = QApplication::desktop();
- int ns = desktop->numScreens();
QRect best;
- for (int i = 0; i < ns; ++i) {
- QRect r = desktop->screenGeometry(i);
+ for (auto *screen : QGuiApplication::screens()) {
+ QRect r = screen->geometry();
if (best.isNull() || r.left() > best.left()) {
best = r;
}
}
- _multiScreen = ns > 1;
- qDebug() << "Spawning at" << best;
- size = best.size();
+ _multiScreen = QGuiApplication::screens().size() > 1;
+ qDebug() << "Spawning VNC viewer at" << best;
show();
setGeometry(best);
raise();
@@ -226,8 +220,7 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool
move(best.topLeft());
} else {
setWindowFlags(Qt::Tool | Qt::WindowMaximizeButtonHint);
- size = QSize(800, 600);
- resize(size);
+ resize(800, 600);
showNormal();
}
diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h
index 7124ddc..0e50ff9 100644
--- a/src/client/vnc/vncwindow.h
+++ b/src/client/vnc/vncwindow.h
@@ -14,12 +14,13 @@
#ifndef CLIENTVNCVIEWER_H_
#define CLIENTVNCVIEWER_H_
-#include <QtWidgets>
#include <QSharedPointer>
-#include <QImage>
+#include <QWidget>
+#include <QPixmap>
class VncThread;
class QPainter;
+class QImage;
class VncWindow : public QWidget
{
@@ -36,8 +37,8 @@ protected slots:
void timer_moveToTop();
void deleteVncThread();
+public slots:
void open(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId, const QByteArray& rawThumb);
-// bool close();
signals:
void running(const bool isRunning, const int clientId);