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/vncthread.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/client/vnc/vncthread.cpp') 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 +#include "../../shared/util.h" +#include +#include #include /** @@ -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(rfbClientGetClientData(client, nullptr)); + auto* t = reinterpret_cast(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(rfbClientGetClientData(client, nullptr)); + auto *t = reinterpret_cast(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(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); } -- cgit v1.2.3-55-g7522