diff options
author | Manuel Schneider | 2014-04-23 18:10:36 +0200 |
---|---|---|
committer | Manuel Schneider | 2014-04-23 18:10:36 +0200 |
commit | b487c8b74252ac995d183da8908414238b00cb72 (patch) | |
tree | a678f29a19d28c270dde6ac8dad9402f3b118fb4 /src/client/vnc/vncwindow.cpp | |
parent | Proper translated concect string (diff) | |
download | pvs2-b487c8b74252ac995d183da8908414238b00cb72.tar.gz pvs2-b487c8b74252ac995d183da8908414238b00cb72.tar.xz pvs2-b487c8b74252ac995d183da8908414238b00cb72.zip |
Made vnc thread stoppable from outside. Thread kills itself. If the vnc
connection cannot be established a timeout kills the thread after a short
period of time.
Diffstat (limited to 'src/client/vnc/vncwindow.cpp')
-rw-r--r-- | src/client/vnc/vncwindow.cpp | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp index f55aa28..34cbab7 100644 --- a/src/client/vnc/vncwindow.cpp +++ b/src/client/vnc/vncwindow.cpp @@ -35,11 +35,13 @@ VncWindow::~VncWindow() void VncWindow::open(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId) { // start thread for vnc-updates - this->onThreadFinished(); + this->onProjectionStopped(); _clientId = clientId; _vncWorker = new VncThread(host, port, passwd, 1); - connect(_vncWorker, SIGNAL(finished()), this, SLOT(onThreadFinished()), Qt::QueuedConnection); + connect(_vncWorker, SIGNAL(projectionStopped()), this, SLOT(onProjectionStopped()), Qt::QueuedConnection); connect(_vncWorker, SIGNAL(projectionStarted()), this, SLOT(onProjectionStarted()), Qt::QueuedConnection); + + _tcpTimeoutTimer = startTimer(4000); _vncWorker->start(QThread::LowPriority); //_rfbclient = _thread->getRfbClient(); //installEventFilter(this); @@ -67,7 +69,7 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool _vncWorker->setTargetSize(this->size()); connect(_vncWorker, SIGNAL(imageUpdated(const int, const int, const int, const int)), this, - SLOT(onUpdateImage(const int, const int, const int, const int)), + SLOT(onUpdateImage(const int, const int, const int, const int)), Qt::QueuedConnection); } @@ -76,7 +78,7 @@ void VncWindow::closeEvent(QCloseEvent *e) e->ignore(); qDebug("Closing VNC viewer window."); this->setVisible(false); - this->onThreadFinished(); + this->onProjectionStopped(); emit running(false, _clientId); } @@ -86,34 +88,29 @@ void VncWindow::onUpdateImage(const int x, const int y, const int w, const int h } /** - * Thread finished, clean up and close window - */ -void VncWindow::onThreadFinished() -{ - if (_vncWorker) - { - 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, SIGNAL(finished()), this, SLOT(onThreadFinished())); - _vncWorker->stop(); - delete _vncWorker; - _vncWorker = NULL; - this->close(); - } - if(_redrawTimer != 0) - { - killTimer(_redrawTimer); - _redrawTimer = 0; - } -} - -/** * VNC Thread successfully connected to remote end - projection will start */ void VncWindow::onProjectionStarted() { emit running(true, _clientId); - //_redrawTimer = startTimer(5000); + _redrawTimer = startTimer(5000); +} + +void VncWindow::onProjectionStopped() +{ + if(_vncWorker == NULL) + return; + + _vncWorker->blockSignals(true); + _vncWorker->stop(); + _vncWorker = NULL; + if(_redrawTimer != 0) + { + killTimer(_redrawTimer); + _redrawTimer = 0; + } + this->close(); + } //////////////////////////////////////////////////////////////////////////////// @@ -126,6 +123,13 @@ void VncWindow::timerEvent(QTimerEvent *event) if (this->isVisible()) this->repaint(); } + else if (event->timerId() == _tcpTimeoutTimer) + { + killTimer(_tcpTimeoutTimer); + if (_vncWorker != NULL && !_vncWorker->isConnected()){ + this->onProjectionStopped(); + } + } else killTimer(event->timerId()); } |