summaryrefslogtreecommitdiffstats
path: root/src/client/vnc
diff options
context:
space:
mode:
authorChristian Klinger2016-09-29 15:40:18 +0200
committerChristian Klinger2016-09-29 15:40:18 +0200
commit3d82bfc698165bb20f3c38d42f2b77ab855c1edf (patch)
tree2c170bcdd5c89259bb0b530fa11fdfe701c99850 /src/client/vnc
parentadded an information dialog that displays ip and hostname. (diff)
downloadpvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.gz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.xz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.zip
astyle.
Diffstat (limited to 'src/client/vnc')
-rw-r--r--src/client/vnc/vncserver.cpp37
-rw-r--r--src/client/vnc/vncserver.h2
-rw-r--r--src/client/vnc/vncthread.cpp32
-rw-r--r--src/client/vnc/vncthread.h2
-rw-r--r--src/client/vnc/vncwindow.cpp49
-rw-r--r--src/client/vnc/vncwindow.h2
6 files changed, 44 insertions, 80 deletions
diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp
index aa7a89e..9d647f0 100644
--- a/src/client/vnc/vncserver.cpp
+++ b/src/client/vnc/vncserver.cpp
@@ -41,20 +41,19 @@ static QString makePassword(int len = 10)
/***************************************************************************//**
* @brief Ugly hack to get an el-cheapo platform independent sleep
*/
-struct Sleeper : public QThread
-{
+struct Sleeper : public QThread {
static void msleep(unsigned long msecs) { QThread::msleep(msecs); }
};
/***************************************************************************//**
* @brief VncServer::VncServer
*/
-VncServer::VncServer() : _process(NULL), _port(0), _timerId(0){}
+VncServer::VncServer() : _process(NULL), _port(0), _timerId(0) {}
/***************************************************************************//**
* @brief VncServer::~VncServer
*/
-VncServer::~VncServer(){}
+VncServer::~VncServer() {}
/***************************************************************************//**
* @brief VncServer::start
@@ -62,8 +61,7 @@ VncServer::~VncServer(){}
void VncServer::start()
{
// Keep things clean
- if (_process != NULL)
- {
+ if (_process != NULL) {
disconnect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
disconnect(_process, SIGNAL(finished(int)), this, SLOT(onFinished(int)));
}
@@ -77,8 +75,7 @@ void VncServer::start()
QFile pwhandle(pwfile);
if (pwhandle.exists())
pwhandle.remove();
- if (!pwhandle.open(QIODevice::WriteOnly))
- {
+ if (!pwhandle.open(QIODevice::WriteOnly)) {
qDebug() << "Could not open " << pwfile << " for writing";
emit started(0, _ropass, _rwpass);
return;
@@ -112,9 +109,9 @@ void VncServer::start()
args << "-clip";
QString rect;
rect = QString::number(primaryRect.width())
- + "x" + QString::number(primaryRect.height())
- + "+" + QString::number(primaryRect.x())
- + "+" + QString::number(primaryRect.y());
+ + "x" + QString::number(primaryRect.height())
+ + "+" + QString::number(primaryRect.x())
+ + "+" + QString::number(primaryRect.y());
args << rect;
qDebug() << "Arguments are: " << args;
@@ -126,8 +123,7 @@ void VncServer::start()
*/
void VncServer::stop()
{
- if (_timerId != 0)
- {
+ if (_timerId != 0) {
killTimer(_timerId);
_timerId = 0;
}
@@ -178,24 +174,20 @@ void VncServer::timerEvent(QTimerEvent *event)
*/
void VncServer::onStdOut()
{
- if (_process == NULL)
- {
+ if (_process == NULL) {
qDebug("VncServer::onStdOut() called in bad state.");
return;
}
QByteArray data(_process->readAllStandardOutput());
qDebug() << "x11vnc: " << data;
- if (_port <= 0)
- {
+ if (_port <= 0) {
const int pos = data.indexOf("PORT=", 0);
- if (pos != -1)
- {
+ if (pos != -1) {
_port = atoi(data.constData() + pos + 5);
qDebug() << "Got VNC port " << _port << ", ro " << _ropass << ", rw " << _rwpass;
emit started(_port, _ropass, _rwpass);
// Kill error timer, but only if port seemed valid
- if (_timerId != 0 && _port > 0)
- {
+ if (_timerId != 0 && _port > 0) {
killTimer(_timerId);
_timerId = 0;
}
@@ -208,8 +200,7 @@ void VncServer::onStdOut()
*/
void VncServer::onStdErr()
{
- if (_process == NULL)
- {
+ if (_process == NULL) {
qDebug("VncServer::onStdErr() called in bad state.");
return;
}
diff --git a/src/client/vnc/vncserver.h b/src/client/vnc/vncserver.h
index ac45822..61e6d21 100644
--- a/src/client/vnc/vncserver.h
+++ b/src/client/vnc/vncserver.h
@@ -31,7 +31,7 @@ private:
public:
static VncServer *instance();
- inline bool isVncServerRunning(){ return _port > 0; }
+ inline bool isVncServerRunning() { return _port > 0; }
void start();
void stop();
diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp
index dfa35af..b710a2c 100644
--- a/src/client/vnc/vncthread.cpp
+++ b/src/client/vnc/vncthread.cpp
@@ -62,8 +62,7 @@ VncThread::~VncThread()
Q_ASSERT(_run == false);
if (_frameBuffer)
delete[] _frameBuffer;
- if (_client != NULL)
- {
+ if (_client != NULL) {
if (_client->sock != -1)
::close(_client->sock);
_client->sock = -1;
@@ -134,7 +133,7 @@ void VncThread::run()
{
qDebug("[%s] VNC client started.", metaObject()->className());
qDebug("[%s] Host: '%s' Port: %i Passwd: '%s' Quality: %i", metaObject()->className(), qPrintable(_host), _port,
- qPrintable(_passwd), _quality);
+ qPrintable(_passwd), _quality);
// setup network
for (int retry = 0; retry < 5 && _run; ++retry) {
@@ -156,8 +155,7 @@ void VncThread::run()
rfbClientSetClientData(_client, 0, this);
// start client
- if (rfbInitClient(_client, NULL, NULL))
- {
+ if (rfbInitClient(_client, NULL, NULL)) {
break; // Success!
}
// Connection failed
@@ -167,8 +165,7 @@ void VncThread::run()
// error, let's try again
this->msleep(10 + qrand() % 50);
}
- if(_client != NULL)
- {
+ if (_client != NULL) {
qDebug("[%s] Connection successful!", metaObject()->className());
int one = 1;
setsockopt(_client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
@@ -180,16 +177,14 @@ void VncThread::run()
_connected = true;
emit projectionStarted();
}
- while (_run)
- {
+ while (_run) {
const int i = WaitForMessage(_client, 100 * 1000); // wait 100ms for message. returns -1 on error/disconnect, 0 if nothing happened, 1 if new data arrived
if (i < 0)
break;
if (i > 0 && !HandleRFBServerMessage(_client))
break;
- if (_hasNewLocalSize)
- {
+ if (_hasNewLocalSize) {
QMutexLocker lock(&_mutex);
_hasNewLocalSize = false;
_localSize = _newLocalSize;
@@ -235,8 +230,7 @@ const QString VncThread::getDesktopName() const
*/
void VncThread::processImageUpdate(const int x, const int y, const int w, const int h)
{
- if (_srcStepX > 1 || _srcStepY > 1)
- {
+ if (_srcStepX > 1 || _srcStepY > 1) {
// Scaling is required as vnc server and client are using different resolutions
// Calc section offsets first
const int startX = x / _srcStepX;
@@ -256,17 +250,14 @@ void VncThread::processImageUpdate(const int x, const int y, const int w, const
// Rescale
{
QMutexLocker lock(&_mutex);
- if (_painter != NULL)
- {
+ if (_painter != NULL) {
QImage scaled(
- _img.copy(srcX, srcY, srcW, srcH).scaled(dstW, dstH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ _img.copy(srcX, srcY, srcW, srcH).scaled(dstW, dstH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
_painter->drawImage(dstX, dstY, scaled, 0, 0, dstW, dstH);
}
}
emit imageUpdated(dstX, dstY, dstW, dstH);
- }
- else
- {
+ } else {
// Same resolution, nothing to do
emit imageUpdated(x, y, w, h);
}
@@ -318,8 +309,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client)
client->format.blueMax = 0xff;
const int quality = t->_quality;
- switch (quality)
- {
+ switch (quality) {
case VncThread::HIGH:
client->appData.useBGR233 = 0;
client->appData.encodingsString = "copyrect zlib hextile raw";
diff --git a/src/client/vnc/vncthread.h b/src/client/vnc/vncthread.h
index a5b52b1..a75ca0f 100644
--- a/src/client/vnc/vncthread.h
+++ b/src/client/vnc/vncthread.h
@@ -34,7 +34,7 @@ extern "C"
*/
class VncThread : public QThread
{
-Q_OBJECT
+ Q_OBJECT
private:
rfbClient *_client;
diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp
index f18fadc..818b22f 100644
--- a/src/client/vnc/vncwindow.cpp
+++ b/src/client/vnc/vncwindow.cpp
@@ -41,19 +41,17 @@ VncWindow::~VncWindow()
*/
void VncWindow::terminateVncThread()
{
- if(_vncWorker == NULL)
+ if (_vncWorker == NULL)
return;
_vncWorker->blockSignals(true);
_vncWorker->stop();
_vncWorker = NULL;
- if(_redrawTimer != 0)
- {
+ if (_redrawTimer != 0) {
killTimer(_redrawTimer);
_redrawTimer = 0;
}
- if(_tcpTimeoutTimer != 0)
- {
+ if (_tcpTimeoutTimer != 0) {
killTimer(_tcpTimeoutTimer);
_tcpTimeoutTimer = 0;
}
@@ -101,8 +99,8 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool
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);
+ SLOT(onUpdateImage(const int, const int, const int, const int)),
+ Qt::QueuedConnection);
setWindowTitle(caption);
@@ -110,15 +108,12 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool
_remoteThumb.loadFromData(rawThumb);
- if (fullscreen)
- {
+ if (fullscreen) {
setWindowFlags(Qt::WindowStaysOnTopHint);
showFullScreen();
activateWindow();
raise();
- }
- else
- {
+ } else {
resize(800, 600);
showNormal();
}
@@ -207,23 +202,18 @@ void VncWindow::onProjectionStopped()
*/
void VncWindow::timerEvent(QTimerEvent *event)
{
- if (event->timerId() == _redrawTimer)
- {
+ if (event->timerId() == _redrawTimer) {
killTimer(_redrawTimer);
_redrawTimer = 0;
if (this->isVisible())
this->repaint();
- }
- else if (event->timerId() == _tcpTimeoutTimer)
- {
+ } else if (event->timerId() == _tcpTimeoutTimer) {
killTimer(_tcpTimeoutTimer);
_tcpTimeoutTimer = 0;
- if (_vncWorker != NULL && !_vncWorker->isConnected())
- {
+ if (_vncWorker != NULL && !_vncWorker->isConnected()) {
this->close();
}
- }
- else
+ } else
killTimer(event->timerId());
}
@@ -237,24 +227,18 @@ void VncWindow::timerEvent(QTimerEvent *event)
*/
void VncWindow::paintEvent(QPaintEvent *event)
{
- if (_vncWorker == NULL || !_vncWorker->isConnected())
- {
+ if (_vncWorker == NULL || !_vncWorker->isConnected()) {
QPainter painter(this);
- if (!_remoteThumb.isNull() && _remoteThumb.height() > 0)
- {
+ if (!_remoteThumb.isNull() && _remoteThumb.height() > 0) {
painter.drawPixmap(0, 0, this->width(), this->height(), _remoteThumb);
- }
- else
- {
+ } else {
painter.fillRect(event->rect(), QColor(60, 63, 66));
}
QFontInfo fi = painter.fontInfo();
painter.setPen(QColor(200, 100, 10));
painter.setFont(QFont(fi.family(), 28, fi.weight(), fi.italic()));
painter.drawText(this->contentsRect(), Qt::AlignCenter, tr("Connecting..."));
- }
- else
- {
+ } else {
const QRect &r = event->rect();
this->draw(r.left(), r.top(), r.width(), r.height());
}
@@ -268,8 +252,7 @@ void VncWindow::paintEvent(QPaintEvent *event)
*/
void VncWindow::resizeEvent(QResizeEvent* event)
{
- if (_vncWorker != NULL)
- {
+ if (_vncWorker != NULL) {
_vncWorker->setTargetSize(event->size());
}
this->repaint();
diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h
index 797ca90..2b91c0e 100644
--- a/src/client/vnc/vncwindow.h
+++ b/src/client/vnc/vncwindow.h
@@ -21,7 +21,7 @@ class QPainter;
class VncWindow : public QWidget
{
-Q_OBJECT
+ Q_OBJECT
public:
VncWindow(QWidget *parent = 0);