-
Notifications
You must be signed in to change notification settings - Fork 1
/
VNCWindow.cpp
68 lines (60 loc) · 1.42 KB
/
VNCWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <QCloseEvent>
#include <QErrorMessage>
#include "SSHPortConnection.h"
#include "vncview.h"
#include "VNCWindow.moc"
VNCWindow::VNCWindow(SSHCredentials *credentials,
int screen_,
QString const& host,
int port,
QWidget *parent)
: QMainWindow(parent)
, ssh(credentials)
, screen(screen_)
{
connect(&ssh, SIGNAL(failure(QString const&)), this, SLOT(portFailure(QString const&)));
ssh.ForwardPort(5900+screen, host, port);
QUrl url = QString("vnc://localhost:%1").arg(screen);
qDebug() << url;
vnc = new VncView(this, url);
setCentralWidget(vnc);
setWindowTitle(QString("VNC Connection [%1:%2]")
.arg(host)
.arg(port - 5900));
}
VNCWindow::~VNCWindow()
{
}
void VNCWindow::show()
{
QMainWindow::show();
ssh.start();
while(!ssh.isInitialized()) {
usleep(100);
if(ssh.isFinished()) {
/* something happened */
ssh.stop();
hide();
emit closed(screen);
return;
}
}
vnc->start();
}
void VNCWindow::closeEvent(QCloseEvent *event)
{
qDebug() << "closed";
vnc->startQuitting();
while(vnc->status() != RemoteView::Disconnected) {
usleep(100);
}
ssh.stop();
event->accept();
emit closed(screen);
}
void VNCWindow::portFailure(QString const& errmsg)
{
QErrorMessage msg;
msg.showMessage(errmsg);
msg.exec();
}