Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ConnectVnc.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "ConnectVnc.h"
4#include "ConnecterThread.h"
5
6#ifndef WIN32
7#include <string.h>
8#include "network/UnixSocket.h"
9#endif
10
11#include <rfb/CMsgWriter.h>
12#include <rfb/Hostname.h>
13#include "rfb/LogWriter.h"
14#include <rfb/util.h>
15#include <rfb/clipboardTypes.h>
16#include <rfb/LogWriter.h>
17#include <rfb/Logger_stdio.h>
18#include <rfb/fenceTypes.h>
19
20// the X11 headers on some systems
21#ifndef XK_VoidSymbol
22#define XK_LATIN1
23#define XK_MISCELLANY
24#define XK_XKB_KEYS
25#include <rfb/keysymdef.h>
26#endif
27
28#include "FramePixelBuffer.h"
29
30#include <QMimeData>
31#include <QClipboard>
32#include <QApplication>
33#include <QLoggingCategory>
34#include <QThread>
35#include <QKeyEvent>
36#include <QMouseEvent>
37#include <QNetworkProxy>
38#include <QMutex>
39#include <QInputDialog>
40
41#include "rfb/Security.h"
42#include "rfb/Exception.h"
43#ifdef HAVE_GNUTLS
44#include "rfb/CSecurityTLS.h"
45#endif
46
47#ifdef HAVE_ICE
48 #include "Ice.h"
49 #include "ChannelIce.h"
50#endif
51
52#ifdef HAVE_LIBSSH
53 #include "ChannelSSHTunnel.h"
54#endif
55
56static Q_LOGGING_CATEGORY(log, "VNC.Connect")
57static Q_LOGGING_CATEGORY(logVNC, "VNC.Log")
58
59class VncLogger: public rfb::Logger
60{
61public:
62 VncLogger(const char *name) : rfb::Logger(name)
63 {}
64 void write(int level, const char *logname, const char *text) override
65 {
66 if (level >= rfb::LogWriter::LEVEL_DEBUG) {
67 qDebug(logVNC) << logname << text;
68 } else if (level >= rfb::LogWriter::LEVEL_INFO) {
69 qInfo(logVNC) << logname << text;
70 } else if (level >= rfb::LogWriter::LEVEL_STATUS) {
71 qWarning(logVNC) << logname << text;
72 } else {
73 qCritical(logVNC) << logname << text;
74 }
75 }
76};
77
78static VncLogger g_logger("Rabbit");
79
80// 8 colours (1 bit per component)
81static const rfb::PixelFormat verylowColourPF(8, 3,false, true, 1, 1, 1, 2, 1, 0);
82// 64 colours (2 bits per component)
83static const rfb::PixelFormat lowColourPF(8, 6, false, true, 3, 3, 3, 4, 2, 0);
84// 256 colours (2-3 bits per component)
85static const rfb::PixelFormat mediumColourPF(8, 8, false, true, 7, 7, 3, 5, 2, 0);
86
87// RGB (4 bits per component)
88static const rfb::PixelFormat fullColourPF(32, 24, false, true, 255, 255, 255, 16, 8, 0);
89
90// Time new bandwidth estimates are weighted against (in ms)
91static const unsigned bpsEstimateWindow = 1000;
92
93CConnectVnc::CConnectVnc(CConnecterThread *pConnecter)
94 : CConnectDesktop(pConnecter),
95 m_pPara(nullptr)
96{
97 static bool initlog = false;
98 if(!initlog)
99 {
100 g_logger.registerLogger();
101 rfb::LogWriter::setLogParams("*:Rabbit:100");
102 /*rfb::initStdIOLoggers();
103 rfb::LogWriter::setLogParams("*:stderr:100");
104 QString szFile = RabbitCommon::CDir::Instance()->GetDirLog()
105 + QDir::separator()
106 + "TigerVnc.log";
107 rfb::initFileLogger(szFile.toStdString().c_str());
108 rfb::LogWriter::setLogParams("*:file:100");
109 */
110 initlog = true;
111 }
112 m_pPara = dynamic_cast<CParameterVnc*>(pConnecter->GetParameter());
113 Q_ASSERT(m_pPara);
114
115 if(!m_pPara->GetLocalCursor())
116 {
117 emit sigUpdateCursor(QCursor(Qt::BlankCursor));
118 }
119}
120
121CConnectVnc::~CConnectVnc()
122{
123 qDebug(log) << "CConnectVnc::~CConnectVnc()";
124}
125
126int CConnectVnc::SetPara()
127{
128 QDir d(os::getvncconfigdir());
129 if(!d.exists())
130 d.mkpath(os::getvncconfigdir());
131 QDir dstat(os::getvncstatedir());
132 if(!dstat.exists())
133 dstat.mkpath(os::getvncstatedir());
134 QDir dvnc(os::getvncdatadir());
135 if(!dvnc.exists())
136 dvnc.mkpath(os::getvncdatadir());
137
138 setServerName(m_pPara->m_Net.GetHost().toStdString().c_str());
139 setShared(m_pPara->GetShared());
140 supportsLocalCursor = m_pPara->GetLocalCursor();
141 supportsCursorPosition = m_pPara->GetCursorPosition();
142 supportsDesktopResize = m_pPara->GetSupportsDesktopResize();
143 supportsLEDState = m_pPara->GetLedState();
144
145 std::list<uint32_t> sec;
146 switch(m_pPara->m_Net.m_User.GetUsedType()) {
147 case CParameterUser::TYPE::None:
148 sec.push_back(rfb::secTypeNone);
149 break;
150 case CParameterUser::TYPE::OnlyPassword:
151 sec.push_back(rfb::secTypeVncAuth);
152 break;
153 case CParameterUser::TYPE::UserPassword:
154 sec.push_back(rfb::secTypePlain);
155 break;
157 sec.push_back(rfb::secTypeTLSVnc);
158 break;
159 case CParameterUser::TYPE::OnlyPasswordX509:
160 sec.push_back(rfb::secTypeX509Vnc);
161 break;
162 case CParameterUser::TYPE::UserPasswordX509None:
163 sec.push_back(rfb::secTypeTLSPlain);
164 break;
165 case CParameterUser::TYPE::UserPasswordX509:
166 sec.push_back(rfb::secTypeX509Plain);
167 break;
168 //TODO: add authentication
169 }
170 //*
171 qDebug(log) << "secTypes:" << security.GetEnabledSecTypes() << security.ToString()
172 << "new:" << sec; // << "Type:" << m_pPara->m_Net.m_User.GetType();//*/
173 security.SetSecTypes(sec);
174
175 // Set Preferred Encoding
176 setPreferredEncoding(m_pPara->GetPreferredEncoding());
177 setCompressLevel(m_pPara->GetCompressLevel());
178 setQualityLevel(m_pPara->GetQualityLevel());
179
180 // Set server pixmap format
181 updatePixelFormat();
182 return 0;
183}
184
185/*
186 * \return
187 * \li OnInitReturnValue::Fail: error
188 * \li OnInitReturnValue::UseOnProcess: Use OnProcess (non-Qt event loop)
189 * \li OnInitReturnValue::NotUseOnProcess: Don't use OnProcess (qt event loop)
190 */
191CConnect::OnInitReturnValue CConnectVnc::OnInit()
192{
193 qDebug(log) << "CConnectVnc::OnInit()";
194 int nRet = 0;
195
196 if(m_pPara->GetIce())
197 nRet = IceInit();
198 else {
199#ifdef HAVE_LIBSSH
200 if(m_pPara->m_Proxy.GetUsedType() == CParameterProxy::TYPE::SSHTunnel) {
201 nRet = SSHInit();
202 if(nRet) return OnInitReturnValue::Fail; // error
203 return OnInitReturnValue::UseOnProcess;
204 }
205#endif
206 nRet = SocketInit();
207 }
208 if(nRet) return OnInitReturnValue::Fail; // error
209 // Don't use OnProcess (qt event loop)
210 return OnInitReturnValue::NotUseOnProcess;
211}
212
213int CConnectVnc::IceInit()
214{
215#ifdef HAVE_ICE
216 CIceSignal* pSignal = CICE::Instance()->GetSignal().data();
217 if(!pSignal || !pSignal->IsConnected())
218 {
219 qCritical(log) << "The g_pSignal is null. or signal don't connect server";
220 return -1;
221 }
222
223 qInfo(log, "Connected to signal server:%s:%d; user:%s",
224 CICE::Instance()->GetParameter()->getSignalServer().toStdString().c_str(),
225 CICE::Instance()->GetParameter()->getSignalPort(),
226 CICE::Instance()->GetParameter()->getSignalUser().toStdString().c_str());
227 auto channel = QSharedPointer<CChannelIce>(new CChannelIce(pSignal));
228 if(!channel)
229 {
230 qCritical(log) << "new CDataChannelIce fail";
231 return -2;
232 }
233 m_DataChannel = channel;
234 SetChannelConnect(channel);
235
236 rtc::Configuration config;
237 rtc::IceServer stun(CICE::Instance()->GetParameter()->getStunServer().toStdString().c_str(),
238 CICE::Instance()->GetParameter()->getStunPort());
239 rtc::IceServer turn(CICE::Instance()->GetParameter()->getTurnServer().toStdString().c_str(),
240 CICE::Instance()->GetParameter()->getTurnPort(),
241 CICE::Instance()->GetParameter()->getTurnUser().toStdString().c_str(),
242 CICE::Instance()->GetParameter()->getTurnPassword().toStdString().c_str());
243 config.iceServers.push_back(stun);
244 config.iceServers.push_back(turn);
245 channel->SetConfigure(config);
246
247 bool bRet = channel->open(CICE::Instance()->GetParameter()->getSignalUser(),
248 m_pPara->GetPeerUser(), true);
249 if(!bRet)
250 {
251 emit sigError(-1, "Open channel fail");
252 }
253
254#endif
255 return 0;
256}
257
258int CConnectVnc::SocketInit()
259{
260 int nRet = 0;
261 try{
262 QTcpSocket* pSock = new QTcpSocket(this);
263 if(!pSock)
264 return -2;
265 m_DataChannel = QSharedPointer<CChannel>(new CChannel(pSock));
266 if(!m_DataChannel) {
267 qCritical(log) << "New CChannel fail";
268 return -1;
269 }
270
271 SetChannelConnect(m_DataChannel);
272
273 if(!m_DataChannel->open(QIODevice::ReadWrite))
274 {
275 qCritical(log) << "Open channel fail";
276 return -3;
277 }
278
279 QNetworkProxy::ProxyType type = QNetworkProxy::NoProxy;
280 // Set sock
281 switch(m_pPara->m_Proxy.GetUsedType())
282 {
283 case CParameterProxy::TYPE::SockesV5:
284 type = QNetworkProxy::Socks5Proxy;
285 break;
286 case CParameterProxy::TYPE::Default:
287 type = QNetworkProxy::DefaultProxy;
288 break;
289 case CParameterProxy::TYPE::None:
290 default:
291 break;
292 }
293
294 switch(type) {
295 case QNetworkProxy::DefaultProxy:
296 {
297 pSock->setProxy(QNetworkProxy::applicationProxy());
298 break;
299 }
300 case QNetworkProxy::Socks5Proxy:
301 {
302 QNetworkProxy proxy;
303 proxy.setType(type);
304 auto &net = m_pPara->m_Proxy.m_SockesV5;
305 if(net.GetHost().isEmpty())
306 {
307 QString szErr;
308 szErr = tr("The proxy server is empty, please input it");
309 qCritical(log) << szErr;
310 emit sigShowMessageBox(tr("Error"), szErr, QMessageBox::Critical);
311 return -4;
312 }
313 proxy.setHostName(net.GetHost());
314 proxy.setPort(net.GetPort());
315 auto &user = net.m_User;
316 proxy.setUser(user.GetUser());
317 proxy.setPassword(user.GetPassword());
318 pSock->setProxy(proxy);
319 break;
320 }
321 default:
322 break;
323 }
324
325 if(m_pPara->m_Net.GetHost().isEmpty())
326 {
327 QString szErr;
328 szErr = tr("The server is empty, please input it");
329 qCritical(log) << szErr;
330 emit sigShowMessageBox(tr("Error"), szErr, QMessageBox::Critical);
331 return -5;
332 }
333 pSock->connectToHost(m_pPara->m_Net.GetHost(), m_pPara->m_Net.GetPort());
334
335 QString serverHost;
336 serverHost = pSock->peerName();
337 qDebug(log) << "Server Host:" << serverHost;
338 setServerName(serverHost.toStdString().c_str());
339
340 return nRet;
341 } catch (rdr::Exception& e) {
342 qCritical(log) << "SocketInit exception:" << e.str();
343 emit sigError(-6, e.str());
344 nRet = -6;
345 }
346 return nRet;
347}
348
349int CConnectVnc::SSHInit()
350{
351 bool check = false;
352#ifdef HAVE_LIBSSH
353 QSharedPointer<CParameterChannelSSH> parameter(new CParameterChannelSSH());
354 auto &ssh = m_pPara->m_Proxy.m_SSH;
355 parameter->setServer(ssh.GetHost());
356 parameter->setPort(ssh.GetPort());
357 auto &user = ssh.m_User;
358 parameter->SetUser(user.GetUser());
359 parameter->SetUseSystemFile(user.GetUseSystemFile());
360 if(CParameterUser::TYPE::UserPassword == user.GetUsedType()) {
361 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PASSWORD);
362 parameter->SetPassword(user.GetPassword());
363 }
364 if(CParameterUser::TYPE::PublicKey == user.GetUsedType()) {
365 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PUBLICKEY);
366 parameter->SetPublicKeyFile(user.GetPublicKeyFile());
367 parameter->SetPrivateKeyFile(user.GetPrivateKeyFile());
368 parameter->SetPassphrase(user.GetPassphrase());
369 }
370 auto &net = m_pPara->m_Net;
371 parameter->SetRemoteHost(net.GetHost());
372 parameter->SetRemotePort(net.GetPort());
373
374 auto channel = QSharedPointer<CChannelSSHTunnel>(new CChannelSSHTunnel(parameter));
375 if(!channel) {
376 qCritical(log) << "New CChannelSSHTunnel fail";
377 return -1;
378 }
379 m_DataChannel = channel;
380 SetChannelConnect(m_DataChannel);
381 check = connect(channel.data(), SIGNAL(sigBlockShowMessageBox(const QString&, const QString&, QMessageBox::StandardButtons, QMessageBox::StandardButton&, bool&, QString)),
382 this, SIGNAL(sigBlockShowMessageBox(const QString&, const QString&, QMessageBox::StandardButtons, QMessageBox::StandardButton&, bool&, QString)));
383 Q_ASSERT(check);
384 check = connect(channel.data(), SIGNAL(sigBlockShowWidget(const QString&, int&, void*)),
385 this, SIGNAL(sigBlockShowWidget(const QString&, int&, void*)));
386 Q_ASSERT(check);
387 if(!channel->open(QIODevice::ReadWrite))
388 {
389 QString szErr;
390 szErr = tr("Failed to open SSH tunnel:");
391 szErr += "(" + m_pPara->m_Proxy.m_SSH.GetHost();
392 szErr += ":";
393 szErr += QString::number(m_pPara->m_Proxy.m_SSH.GetPort());
394 szErr += " - ";
395 szErr += m_pPara->m_Net.GetHost();
396 szErr += ":";
397 szErr += QString::number(m_pPara->m_Net.GetPort()) + ")";
398 QString szMsg = szErr + "\n" + channel->errorString();
399 emit sigShowMessageBox(tr("Error"), szMsg, QMessageBox::Critical);
400 return -2;
401 }
402#endif
403 return 0;
404}
405
406int CConnectVnc::SetChannelConnect(QSharedPointer<CChannel> channel)
407{
408 bool check = false;
409 check = connect(channel.data(), SIGNAL(sigConnected()),
410 this, SLOT(slotConnected()));
411 Q_ASSERT(check);
412 check = connect(channel.data(), SIGNAL(sigDisconnected()),
413 this, SLOT(slotDisConnected()));
414 Q_ASSERT(check);
415 check = connect(channel.data(), SIGNAL(readyRead()),
416 this, SLOT(slotReadyRead()));
417 Q_ASSERT(check);
418 check = connect(channel.data(), SIGNAL(sigError(int, const QString&)),
419 this, SLOT(slotChannelError(int, const QString&)));
420 Q_ASSERT(check);
421 return 0;
422}
423
425{
426 qDebug(log) << "CConnectVnc::OnClean()";
427 close();
428 setStreams(nullptr, nullptr);
429 if(m_DataChannel) {
430 m_DataChannel->close();
431 }
432 return 0;
433}
434
449{
450 int nRet = 0;
451#ifdef HAVE_LIBSSH
452 if(m_pPara->m_Proxy.GetUsedType() == CParameterProxy::TYPE::SSHTunnel) {
453 CChannelSSHTunnel* channel = (CChannelSSHTunnel*)m_DataChannel.data();
454 if(channel)
455 nRet = channel->Process();
456 }
457#endif
458
459 return nRet;
460}
461
463{
464#ifdef HAVE_LIBSSH
465 if(m_pPara->m_Proxy.GetUsedType() == CParameterProxy::TYPE::SSHTunnel) {
466 CChannelSSHTunnel* channel = (CChannelSSHTunnel*)m_DataChannel.data();
467 if(channel)
468 channel->WakeUp();
469 }
470#endif
471 return 0;
472}
473
474void CConnectVnc::slotConnected()
475{
476 //qDebug(log) << "CConnectVnc::slotConnected()";
477 if(m_pPara->GetIce())
478 qInfo(log) << "Connected to peer " + m_pPara->GetPeerUser();
479 else {
480 auto &net = m_pPara->m_Net;
481 QString szInfo = "Connected to "
482 + net.GetHost() + ":" + QString::number(net.GetPort());
483#ifdef HAVE_LIBSSH
484 if(CParameterProxy::TYPE::SSHTunnel == m_pPara->m_Proxy.GetUsedType())
485 {
486 auto &ssh = m_pPara->m_Proxy.m_SSH;
487 szInfo += " with ssh turnnel: " + ssh.GetHost()
488 + ":" + QString::number(ssh.GetPort());
489 }
490#endif
491 qInfo(log) << szInfo;
492 }
493 int nRet = SetPara();
494 if(nRet)
495 {
496 emit sigDisconnect();
497 return;
498 }
499 m_InStream = QSharedPointer<rdr::InStream>(new CInStreamChannel(m_DataChannel.data()));
500 m_OutStream = QSharedPointer<rdr::OutStream>(new COutStreamChannel(m_DataChannel.data()));
501 if(!(m_InStream && m_OutStream))
502 {
503 qCritical(log) << "m_InStream or m_OutStream is null";
504 emit sigDisconnect();
505 return;
506 }
507 setStreams(m_InStream.data(), m_OutStream.data());
508 initialiseProtocol();
509}
510
511void CConnectVnc::slotDisConnected()
512{
513 QString szInfo;
514 szInfo = "CConnectVnc::slotDisConnected() from "
515 + m_pPara->m_Net.GetHost() + ":"
516 + QString::number(m_pPara->m_Net.GetPort());
517#ifdef HAVE_LIBSSH
518 if(CParameterProxy::TYPE::SSHTunnel == m_pPara->m_Proxy.GetUsedType())
519 {
520 auto &ssh = m_pPara->m_Proxy.m_SSH;
521 szInfo += " with ssh turnnel: " + ssh.GetHost()
522 + ":" + QString::number(ssh.GetPort());
523 }
524#endif
525 qInfo(log) << szInfo;
526}
527
528void CConnectVnc::slotReadyRead()
529{
530 //qDebug(log) << "CConnectVnc::slotReadyRead";
531 QString szErr("processMsg exception: ");
532 int nRet = -1;
533 try {
534 getOutStream()->flush();
535
536 getOutStream()->cork(true);
537 while(processMsg())
538 ;
539 getOutStream()->cork(false);
540 return;
541 } catch (rfb::AuthFailureException& e) {
542 szErr = tr("Logon to ");
543 szErr += m_pPara->m_Net.GetHost();
544 szErr += ":";
545 szErr += QString::number(m_pPara->m_Net.GetPort());
546 szErr += tr(" fail.");
547 QString szMsg = szErr + "\n" + tr("Please check that the username and password are correct.") + "\n";
548 emit sigShowMessageBox(tr("Error"), szMsg, QMessageBox::Critical);
549
550 szErr += " [";
551 szErr += e.str();
552 szErr += "]";
553 } catch (rfb::ConnFailedException& e) {
554 QString szErr;
555 szErr = tr("Connect to ");
556 szErr += m_pPara->m_Net.GetHost();
557 szErr += ":";
558 szErr += QString::number(m_pPara->m_Net.GetPort());
559 szErr += tr(" fail.");
560 szErr += " [";
561 szErr += e.str();
562 szErr += "]";
563 emit sigShowMessageBox(tr("Error"), szErr, QMessageBox::Critical);
564 } catch (rdr::EndOfStream& e) {
565 szErr += e.str();
566 } catch(rdr::GAIException &e) {
567 nRet = e.err;
568 szErr += "[" + QString::number(e.err) + "] " + e.str();
569 } catch(rdr::SystemException &e) {
570 nRet = e.err;
571 szErr += "[" + QString::number(e.err) + "] " + e.str();
572 } catch (rdr::Exception& e) {
573 szErr += e.str();
574 } catch (std::exception &e) {
575 szErr += e.what();
576 } catch(...) {
577 szErr += "unknown exception";
578 }
579 qCritical(log) << szErr;
580 emit sigError(nRet, szErr);
581 emit sigDisconnect();
582}
583
584void CConnectVnc::slotChannelError(int nErr, const QString& szErr)
585{
586 qDebug(log) << "Channel error:" << nErr << "-" << szErr;
587 emit sigError(nErr, szErr);
588 emit sigDisconnect();
589}
590
591// initDone() is called when the serverInit message has been received. At
592// this point we create the desktop window and display it. We also tell the
593// server the pixel format and encodings to use and request the first update.
594void CConnectVnc::initDone()
595{
596 Q_ASSERT(m_pPara);
597 qDebug(log, "initDone:\n%s", ConnectInformation().toStdString().c_str());
598
599 emit sigSetDesktopSize(server.width(), server.height());
600 QString szName = QString::fromUtf8(server.name());
601 emit sigServerName(szName);
602
603 //Set viewer frame buffer
604 setFramebuffer(new CFramePixelBuffer(server.width(), server.height()));
605
606 // Force a switch to the format and encoding we'd like
607 // Set Preferred Encoding
608 setPreferredEncoding(m_pPara->GetPreferredEncoding());
609 updatePixelFormat();
610
611 emit sigConnected();
612}
613
614void CConnectVnc::resizeFramebuffer()
615{
616 rfb::ModifiablePixelBuffer* buffer = getFramebuffer();
617
618 qDebug(log) << "CConnectVnc::resizeFramebuffer: new:"
619 << server.width() << server.height()
620 << "old:" << buffer->width() << buffer->height();
621
622 if(server.width() == buffer->width() && server.height() == buffer->height())
623 return;
624
625 //Set viewer frame buffer
626 setFramebuffer(new CFramePixelBuffer(server.width(), server.height()));
627 emit sigSetDesktopSize(server.width(), server.height());
628}
629
630void CConnectVnc::setColourMapEntries(int firstColour, int nColours, uint16_t *rgbs)
631{
632 qCritical(log) << "Invalid SetColourMapEntries from server!";
633}
634
635void CConnectVnc::bell()
636{
637 qApp->beep();
638}
639
640void CConnectVnc::setLEDState(unsigned int state)
641{
642 qDebug(log) << "CConnectVnc::setLEDState" << state;
643 CConnection::setLEDState(state);
644 emit sigUpdateLedState(state);
645}
646
647void CConnectVnc::setCursor(int width, int height, const rfb::Point &hotspot, const uint8_t *data)
648{
649 //qDebug(log) << "CConnectVnc::setCursor x:" << hotspot.x << ";y:" << hotspot.y;
650 if ((width == 0) || (height == 0)) {
651 QImage cursor(1, 1, QImage::Format_ARGB32);
652 uint8_t *buffer = cursor.bits();
653 memset(buffer, 0, 4);
654 emit sigUpdateCursor(QCursor(QPixmap::fromImage(cursor), hotspot.x, hotspot.y));
655 } else {
656 QImage cursor(width, height, QImage::Format_ARGB32);
657 uint8_t *buffer = cursor.bits();
658 memcpy(buffer, data, width * height * 4);
659 emit sigUpdateCursor(QCursor(QPixmap::fromImage(cursor), hotspot.x, hotspot.y));
660 }
661}
662
663void CConnectVnc::setCursorPos(const rfb::Point &pos)
664{
665 //qDebug(log) << "CConnectVnc::setCursorPos x:" << pos.x << ";y:" << pos.y;
666 emit sigUpdateCursorPosition(QPoint(pos.x, pos.y));
667}
668
669void CConnectVnc::fence(uint32_t flags, unsigned int len, const uint8_t data[])
670{
671 //qDebug(log, "CConnectVnc::fence:flags:0x%X; len:%d", flags, len);
672 CMsgHandler::fence(flags, len, data);
673 if (!(flags & rfb::fenceFlagRequest))
674 return;
675
676 // We handle everything synchronously so we trivially honor these modes
677 flags = flags & (rfb::fenceFlagBlockBefore | rfb::fenceFlagBlockAfter);
678 writer()->writeFence(flags, len, data);
679 return;
680}
681
682void CConnectVnc::getUserPasswd(bool secure, std::string *user, std::string *password)
683{
684 if(password)
685 {
686 auto &user = m_pPara->m_Net.m_User;
687 *password = user.GetPassword().toStdString();
688 if(user.GetPassword().isEmpty())
689 {
690 int nRet = QDialog::Rejected;
691 emit sigBlockShowWidget("CDlgGetPasswordVNC", nRet, m_pPara);
692 if(QDialog::Accepted == nRet)
693 {
694 *password = user.GetPassword().toStdString();
695 }
696 }
697 }
698}
699
700int CConnectVnc::getX509File(std::string *ca, std::string *crl)
701{
702 auto &user = m_pPara->m_Net.m_User;
703 if(ca)
704 *ca = user.GetCAFile().toStdString().c_str();
705 if(crl)
706 *crl = user.GetCRLFile().toStdString().c_str();
707 return 0;
708}
709
710bool CConnectVnc::showMsgBox(rfb::MsgBoxFlags flags, const char *title, const char *text)
711{
712 qDebug(log) << title << text;
713 QMessageBox::StandardButton nRet = QMessageBox::No;
714 QMessageBox::StandardButtons fgBtn = QMessageBox::No;
715 bool bCheckBox = 0;
716 if((int)flags & (int)rfb::MsgBoxFlags::M_OK)
717 fgBtn |= QMessageBox::Ok;
718
719 if((int)flags & (int)rfb::MsgBoxFlags::M_OKCANCEL)
720 fgBtn |= QMessageBox::Ok | QMessageBox::Cancel;
721 if((int)flags & (int)rfb::MsgBoxFlags::M_YESNO)
722 fgBtn |= QMessageBox::Yes | QMessageBox::No;
723
724 emit sigBlockShowMessageBox(QString(title), QString(text),
725 fgBtn, nRet, bCheckBox);
726 if(QMessageBox::Ok == nRet
727 || QMessageBox::Yes == nRet)
728 return true;
729 return false;
730}
731
732// setName() is called when the desktop name changes
733void CConnectVnc::setName(const char *name)
734{
735 qDebug(log) << "CConnectVnc::setName:" << name;
736 CConnection::setName(name);
737 QString szName = QString::fromUtf8(server.name());
738 emit sigServerName(szName);
739}
740
741// framebufferUpdateStart() is called at the beginning of an update.
742// Here we try to send out a new framebuffer update request so that the
743// next update can be sent out in parallel with us decoding the current
744// one.
745void CConnectVnc::framebufferUpdateStart()
746{
747 //qDebug(log) << "CConnectVnc::framebufferUpdateStart()";
748 CConnection::framebufferUpdateStart();
749}
750
751// framebufferUpdateEnd() is called at the end of an update.
752// For each rectangle, the FdInStream will have timed the speed
753// of the connection, allowing us to select format and encoding
754// appropriately, and then request another incremental update.
755void CConnectVnc::framebufferUpdateEnd()
756{
757 //qDebug(log) << "CConnectVnc::framebufferUpdateEnd()";
758 rfb::CConnection::framebufferUpdateEnd();
759
760 if(m_pPara /*&& m_pPara->GetBufferEndRefresh()*/)
761 {
762 const QImage& img = dynamic_cast<CFramePixelBuffer*>(getFramebuffer())->getImage();
763 emit sigUpdateRect(img);
764 }
765}
766
767// requestNewUpdate() requests an update from the server, having set the
768// format and encoding appropriately.
769void CConnectVnc::updatePixelFormat()
770{
771 Q_ASSERT(m_pPara);
772
773 if(!m_pPara) return;
774 rfb::PixelFormat pf;
775
776 switch (m_pPara->GetColorLevel()) {
777 case CParameterVnc::Full:
778 pf = fullColourPF;
779 break;
780 case CParameterVnc::Medium:
781 pf = mediumColourPF;
782 break;
783 case CParameterVnc::Low:
784 pf = lowColourPF;
785 break;
786 case CParameterVnc::VeryLow:
787 pf = verylowColourPF;
788 break;
789 }
790
791 char str[256];
792 pf.print(str, 256);
793 qInfo(log) << "Update pixel format:" << str;
794 setPF(pf);
795}
796
797void CConnectVnc::mousePressEvent(QMouseEvent *event)
798{
799 if(!writer()) return;
800 if(m_pPara && m_pPara->GetOnlyView()) return;
801
802 unsigned char mask = 0;
803 if(event->button() & Qt::MouseButton::LeftButton)
804 mask |= 0x1;
805 if(event->button() & Qt::MouseButton::MiddleButton)
806 mask |= 0x2;
807 if(event->button() & Qt::MouseButton::RightButton)
808 mask |= 0x4;
809
810 QPoint pos = event->pos();
811 rfb::Point p(pos.x(), pos.y());
812
813 /*
814 qDebug(log) << "CConnectVnc::slotMousePressEvent buttons:"
815 << event->buttons() << event->button() << pos << mask;//*/
816 try{
817 writer()->writePointerEvent(p, mask);
818 } catch (rdr::Exception& e) {
819 emit sigError(-1, e.str());
820 }
821}
822
823void CConnectVnc::mouseReleaseEvent(QMouseEvent *event)
824{
825 if(!writer()) return;
826 if(m_pPara && m_pPara->GetOnlyView()) return;
827 int mask = 0;
828 QPoint pos = event->pos();
829 rfb::Point p(pos.x(), pos.y());
830 /*
831 qDebug(log) << "CConnectVnc::slotMouseReleaseEvent buttons:"
832 << event->buttons() << event->button() << pos << mask;//*/
833 try{
834 writer()->writePointerEvent(p, mask);
835 } catch (rdr::Exception& e) {
836 emit sigError(-1, e.str());
837 }
838}
839
840void CConnectVnc::mouseMoveEvent(QMouseEvent *event)
841{
842 if(!writer()) return;
843 if(m_pPara && m_pPara->GetOnlyView()) return;
844 int mask = 0;
845 QPoint pos = event->pos();
846 rfb::Point p(pos.x(), pos.y());
847 if(event->buttons() & Qt::MouseButton::LeftButton)
848 mask |= 0x1;
849 if(event->buttons() & Qt::MouseButton::MiddleButton)
850 mask |= 0x2;
851 if(event->buttons() & Qt::MouseButton::RightButton)
852 mask |= 0x4;
853 /*
854 qDebug(log) << "CConnectVnc::slotMouseMoveEvent buttons:"
855 << event->buttons() << event->button() << pos << mask;//*/
856 try{
857 writer()->writePointerEvent(p, mask);
858 } catch (rdr::Exception& e) {
859 emit sigError(-1, e.str());
860 }
861}
862
863// https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#pointerevent
864void CConnectVnc::wheelEvent(QWheelEvent *event)
865{
866 /*
867 qDebug(log) << "CConnectVnc::slotWheelEvent buttons:"
868 << event->buttons() << event->angleDelta() << pos;//*/
869 if(!writer()) return;
870 if(m_pPara && m_pPara->GetOnlyView()) return;
871 int mask = 0;
872
873 if(event->buttons() & Qt::MouseButton::LeftButton)
874 mask |= 0x1;
875 if(event->buttons() & Qt::MouseButton::MiddleButton)
876 mask |= 0x2;
877 if(event->buttons() & Qt::MouseButton::RightButton)
878 mask |= 0x4;
879
880 QPoint d = event->angleDelta();
881 if(d.y() > 0)
882 mask |= 0x8;
883 if(d.y() < 0)
884 mask |= 0x10;
885 if(d.x() < 0)
886 mask |= 0x20;
887 if(d.x() > 0)
888 mask |= 0x40;
889
890 QPointF pos;
891#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
892 pos = event->position();
893#else
894 pos = event->pos();
895#endif
896
897 rfb::Point p(pos.x(), pos.y());
898
899 try{
900 writer()->writePointerEvent(p, mask);
901 } catch (rdr::Exception& e) {
902 emit sigError(-1, e.str());
903 }
904}
905
906void CConnectVnc::keyPressEvent(QKeyEvent *event)
907{
908 if(!writer()) return;
909 if(m_pPara && m_pPara->GetOnlyView()) return;
910 bool modifier = false;
911 if (event->modifiers() & Qt::ShiftModifier)
912 modifier = true;
913 //qDebug(log) << "slotKeyPressEvent key:" << key << modifiers;
914 uint32_t k = TranslateRfbKey(event->key(), modifier);
915
916 try{
917 writer()->writeKeyEvent(k, 0, true);
918 } catch (rdr::Exception& e) {
919 emit sigError(-1, e.str());
920 }
921
922}
923
924void CConnectVnc::keyReleaseEvent(QKeyEvent *event)
925{
926 if(m_pPara && m_pPara->GetOnlyView()) return;
927 if(!writer()) return;
928 bool modifier = false;
929 if (event->modifiers() & Qt::ShiftModifier)
930 modifier = true;
931 //qDebug(log) << "slotKeyReleaseEvent key:" << key << modifiers;
932 uint32_t k = TranslateRfbKey(event->key(), modifier);
933
934 try{
935 writer()->writeKeyEvent(k, 0, false);
936 } catch (rdr::Exception& e) {
937 emit sigError(-1, e.str());
938 }
939
940}
941
942QString CConnectVnc::ConnectInformation()
943{
944 const int len = 128;
945 char buf[len];
946 QString szInfo;
947 szInfo = QString("Desktop name: ") + server.name() + "\n";
948 szInfo += QString("Size: %1 x %2").arg(server.width()).arg(server.height()) + "\n";
949
950 // TRANSLATORS: Will be filled in with a string describing the
951 // protocol pixel format in a fairly language neutral way
952 server.pf().print(buf, len);
953 szInfo += QString("Pixel format: ") + buf + "\n";
954 szInfo += QString("Requested encoding: ") + rfb::encodingName(getPreferredEncoding()) + "\n";
955 szInfo += QString("Protocol version: %1.%2").arg(server.majorVersion).arg(server.minorVersion) + "\n";
956 szInfo += QString("Security method: ") + rfb::secTypeName(csecurity->getType()) + "\n";
957 szInfo += QString("Support local cursor: %1").arg(supportsLocalCursor) + "\n";
958 szInfo += QString("Support cursor position: %1").arg(supportsCursorPosition) + "\n";
959 szInfo += QString("Support desktop resize: %1").arg(supportsDesktopResize) + "\n";
960 szInfo += QString("Support LED state: %1").arg(supportsLEDState) + "\n";
961 szInfo += QString("Led state: %1").arg(server.ledState()) + "\n";
962 szInfo += QString("Supports QEMU KeyEvent: %1").arg(server.supportsQEMUKeyEvent) + "\n";
963 szInfo += QString("Supports Set Desktop Size: %1").arg(server.supportsSetDesktopSize) + "\n";
964 szInfo += QString("Support fance: %1").arg(server.supportsFence) + "\n";
965 szInfo += QString("Support continue updates: %1").arg(server.supportsContinuousUpdates) + "\n";
966
967 return szInfo;
968}
969
977quint32 CConnectVnc::TranslateRfbKey(quint32 inkey, bool modifier)
978{
979 quint32 k = 5000;
980
981 switch (inkey)
982 {
983 case Qt::Key_Backspace: k = XK_BackSpace; break;
984 case Qt::Key_Tab: k = XK_Tab; break;
985 case Qt::Key_Clear: k = XK_Clear; break;
986 case Qt::Key_Return: k = XK_Return; break;
987 case Qt::Key_Pause: k = XK_Pause; break;
988 case Qt::Key_Escape: k = XK_Escape; break;
989 case Qt::Key_Space: k = XK_space; break;
990 case Qt::Key_Delete: k = XK_Delete; break;
991 case Qt::Key_Period: k = XK_period; break;
992
993 /* International & multi-key character composition */
994 case Qt::Key_Multi_key: k = XK_Multi_key; break;
995 case Qt::Key_Codeinput: k = XK_Codeinput; break;
996 case Qt::Key_SingleCandidate: k = XK_SingleCandidate; break;
997 case Qt::Key_MultipleCandidate: k = XK_MultipleCandidate; break;
998 case Qt::Key_PreviousCandidate: k = XK_PreviousCandidate; break;
999
1000 /* Japanese keyboard support */
1001 case Qt::Key_Kanji: k = XK_Kanji; break;
1002 case Qt::Key_Muhenkan: k = XK_Muhenkan; break;
1003 case Qt::Key_Henkan: k = XK_Henkan; break;
1004 case Qt::Key_Romaji: k = XK_Romaji; break;
1005 case Qt::Key_Hiragana: k = XK_Hiragana; break;
1006 case Qt::Key_Katakana: k = XK_Katakana; break;
1007 case Qt::Key_Hiragana_Katakana: k = XK_Hiragana_Katakana;break;
1008 case Qt::Key_Zenkaku: k = XK_Zenkaku; break;
1009 case Qt::Key_Hankaku: k = XK_Hankaku; break;
1010 case Qt::Key_Zenkaku_Hankaku: k = XK_Zenkaku_Hankaku; break;
1011 case Qt::Key_Touroku: k = XK_Touroku; break;
1012 case Qt::Key_Massyo: k = XK_Massyo; break;
1013 case Qt::Key_Kana_Lock: k = XK_Kana_Lock; break;
1014 case Qt::Key_Kana_Shift: k = XK_Kana_Shift; break;
1015 case Qt::Key_Eisu_Shift: k = XK_Eisu_Shift; break;
1016 case Qt::Key_Eisu_toggle: k = XK_Eisu_toggle; break;
1017
1018 //special keyboard char
1019 case Qt::Key_Exclam: k = XK_exclam; break;
1020 case Qt::Key_QuoteDbl: k = XK_quotedbl; break; //"
1021 case Qt::Key_NumberSign: k = XK_numbersign; break; //#
1022 case Qt::Key_Percent: k = XK_percent; break; //%
1023 case Qt::Key_Dollar: k = XK_dollar; break; //$
1024 case Qt::Key_Ampersand: k = XK_ampersand; break; //&
1025 case Qt::Key_Apostrophe: k = XK_apostrophe; break;
1026 case Qt::Key_ParenLeft: k = XK_parenleft; break; // (
1027 case Qt::Key_ParenRight: k = XK_parenright; break; // )
1028
1029 case Qt::Key_Slash: k = XK_slash; break; // /
1030 case Qt::Key_Asterisk: k = XK_asterisk; break; //*
1031 case Qt::Key_Minus: k = XK_minus; break; //-
1032 case Qt::Key_Plus: k = XK_plus; break; //+
1033 case Qt::Key_Enter: k = XK_Return; break; //
1034 case Qt::Key_Equal: k = XK_equal; break; //=
1035 case Qt::Key_Comma: return XK_comma; //,
1036
1037 case Qt::Key_Colon: k = XK_colon;break; // :
1038 case Qt::Key_Semicolon: k = XK_semicolon; break; //;
1039 case Qt::Key_Less: k = XK_less; break; // <
1040 case Qt::Key_Greater: k = XK_greater; break; // >
1041 case Qt::Key_Question: k = XK_question; break; //?
1042 case Qt::Key_At: k = XK_at; break; //@
1043
1044 case Qt::Key_BracketLeft: k = XK_bracketleft; break;
1045 case Qt::Key_Backslash: k = XK_backslash;break;
1046 case Qt::Key_BracketRight: k = XK_bracketright;break;
1047 case Qt::Key_AsciiCircum: k = XK_asciicircum;break;
1048 case Qt::Key_Underscore: k = XK_underscore;break;
1049 case Qt::Key_QuoteLeft: k = XK_quoteleft;break;
1050 case Qt::Key_BraceLeft: k = XK_braceleft;break;
1051 case Qt::Key_Bar: k = XK_bar; break;
1052 case Qt::Key_BraceRight: k = XK_braceright;break;
1053 case Qt::Key_AsciiTilde: k = XK_asciitilde;break;
1054 case Qt::Key_nobreakspace: k = XK_nobreakspace;break;
1055 case Qt::Key_exclamdown: k = XK_exclamdown;break;
1056 case Qt::Key_cent: k = XK_cent;break;
1057 case Qt::Key_sterling: k = XK_sterling;break;
1058 case Qt::Key_currency: k = XK_currency;break;
1059 case Qt::Key_yen: k = XK_yen;break;
1060 case Qt::Key_brokenbar: k = XK_brokenbar;break;
1061 case Qt::Key_section: k = XK_section;break;
1062 case Qt::Key_diaeresis: k = XK_diaeresis;break;
1063 case Qt::Key_copyright: k = XK_copyright; break;
1064 case Qt::Key_ordfeminine: k = XK_ordfeminine; break;
1065 case Qt::Key_guillemotleft: k = XK_guillemotleft; break;
1066 case Qt::Key_guillemotright: k = XK_guillemotright; break;
1067 case Qt::Key_notsign: k = XK_notsign; break;
1068 case Qt::Key_hyphen: k = XK_hyphen; break;
1069 case Qt::Key_registered: k = XK_registered; break;
1070
1071 case Qt::Key_Up: k = XK_Up; break;
1072 case Qt::Key_Down: k = XK_Down; break;
1073 case Qt::Key_Right: k = XK_Right; break;
1074 case Qt::Key_Left: k = XK_Left; break;
1075 case Qt::Key_Insert: k = XK_Insert; break;
1076 case Qt::Key_Home: k = XK_Home; break;
1077 case Qt::Key_End: k = XK_End; break;
1078 case Qt::Key_PageUp: k = XK_Page_Up; break;
1079 case Qt::Key_PageDown: k = XK_Page_Down; break;
1080 case Qt::Key_MediaPrevious: k = XK_Prior; break;
1081 case Qt::Key_MediaNext: k = XK_Next; break;
1082 case Qt::Key_MediaPlay: k = XK_Begin; break;
1083
1084 /* Misc Functions */
1085 case Qt::Key_Select: k = XK_Select; break;
1086 case Qt::Key_Printer: k = XK_Print; break;
1087 case Qt::Key_Execute: k = XK_Execute; break;
1088 case Qt::Key_Undo: k = XK_Undo; break;
1089 case Qt::Key_Redo: k = XK_Redo; break;
1090 case Qt::Key_Menu: k = XK_Menu; break;
1091 case Qt::Key_Find: k = XK_Find; break;
1092 case Qt::Key_Exit:
1093 case Qt::Key_Cancel:
1094 case Qt::Key_Stop:
1095 k = XK_Cancel;
1096 break;
1097 case Qt::Key_Mode_switch: k = XK_Mode_switch; break;
1098
1099 case Qt::Key_F1: k = XK_F1; break;
1100 case Qt::Key_F2: k = XK_F2; break;
1101 case Qt::Key_F3: k = XK_F3; break;
1102 case Qt::Key_F4: k = XK_F4; break;
1103 case Qt::Key_F5: k = XK_F5; break;
1104 case Qt::Key_F6: k = XK_F6; break;
1105 case Qt::Key_F7: k = XK_F7; break;
1106 case Qt::Key_F8: k = XK_F8; break;
1107 case Qt::Key_F9: k = XK_F9; break;
1108 case Qt::Key_F10: k = XK_F10; break;
1109 case Qt::Key_F11: k = XK_F11; break;
1110 case Qt::Key_F12: k = XK_F12; break;
1111 case Qt::Key_F13: k = XK_F13; break;
1112 case Qt::Key_F14: k = XK_F14; break;
1113 case Qt::Key_F15: k = XK_F15; break;
1114 case Qt::Key_F16: k = XK_F16; break;
1115 case Qt::Key_F17: k = XK_F17; break;
1116 case Qt::Key_F18: k = XK_F18; break;
1117 case Qt::Key_F19: k = XK_F19; break;
1118 case Qt::Key_F20: k = XK_F20; break;
1119 case Qt::Key_F21: k = XK_F21; break;
1120 case Qt::Key_F22: k = XK_F22; break;
1121 case Qt::Key_F23: k = XK_F23; break;
1122 case Qt::Key_F24: k = XK_F24; break;
1123 case Qt::Key_F25: k = XK_F25; break;
1124 case Qt::Key_F26: k = XK_F26; break;
1125 case Qt::Key_F27: k = XK_F27; break;
1126 case Qt::Key_F28: k = XK_F28; break;
1127 case Qt::Key_F29: k = XK_F29; break;
1128 case Qt::Key_F30: k = XK_F30; break;
1129 case Qt::Key_F31: k = XK_F31; break;
1130 case Qt::Key_F32: k = XK_F32; break;
1131 case Qt::Key_F33: k = XK_F33; break;
1132 case Qt::Key_F34: k = XK_F34; break;
1133 case Qt::Key_F35: k = XK_F35; break;
1134
1135 case Qt::Key_NumLock: k = XK_Num_Lock; break;
1136 case Qt::Key_CapsLock: k = XK_Caps_Lock; break;
1137 case Qt::Key_ScrollLock: k = XK_Scroll_Lock; break;
1138
1139 case Qt::Key_Shift: k = XK_Shift_R; break; //k = XK_Shift_L; break;
1140 case Qt::Key_Control: k = XK_Control_R; break;// k = XK_Control_L; break;
1141 case Qt::Key_Alt: k = XK_Alt_R; break;//k = XK_Alt_L; break;
1142 case Qt::Key_Meta: k = XK_Meta_R; break;//k = XK_Meta_L; break;*/
1143
1144 case Qt::Key_Super_L: k = XK_Super_L; break; /* left "windows" key */
1145 case Qt::Key_Super_R: k = XK_Super_R; break; /* right "windows" key */
1146
1147 case Qt::Key_Hyper_L: k = XK_Hyper_L; break;
1148 case Qt::Key_Hyper_R: k = XK_Hyper_R; break;
1149
1150 case Qt::Key_Help: k = XK_Help; break;
1151 case Qt::Key_Print: k = XK_Print; break;
1152 case Qt::Key_SysReq: k = XK_Sys_Req; break;
1153 case Qt::Key_0: k = XK_0;break;
1154 case Qt::Key_1: k = XK_1;break;
1155 case Qt::Key_2: k = XK_2;break;
1156 case Qt::Key_3: k = XK_3;break;
1157 case Qt::Key_4: k = XK_4;break;
1158 case Qt::Key_5: k = XK_5;break;
1159 case Qt::Key_6: k = XK_6;break;
1160 case Qt::Key_7: k = XK_7;break;
1161 case Qt::Key_8: k = XK_8;break;
1162 case Qt::Key_9: k = XK_9;break;
1163 }
1164
1165 if (k == 5000)
1166 {
1167
1168 if (!modifier)
1169 {
1170 switch (inkey)
1171 {
1172 case Qt::Key_A: k = XK_a;break;
1173 case Qt::Key_B: k = XK_b;break;
1174 case Qt::Key_C: k = XK_c;break;
1175 case Qt::Key_D: k = XK_d;break;
1176 case Qt::Key_E: k = XK_e;break;
1177 case Qt::Key_F: k = XK_f;break;
1178 case Qt::Key_G: k = XK_g;break;
1179 case Qt::Key_H: k = XK_h;break;
1180 case Qt::Key_I: k = XK_i;break;
1181 case Qt::Key_J: k = XK_j;break;
1182 case Qt::Key_K: k = XK_k;break;
1183 case Qt::Key_L: k = XK_l;break;
1184 case Qt::Key_M: k = XK_m;break;
1185 case Qt::Key_N: k = XK_n;break;
1186 case Qt::Key_O: k = XK_o;break;
1187 case Qt::Key_P: k = XK_p;break;
1188 case Qt::Key_Q: k = XK_q;break;
1189 case Qt::Key_R: k = XK_r;break;
1190 case Qt::Key_S: k = XK_s;break;
1191 case Qt::Key_T: k = XK_t;break;
1192 case Qt::Key_U: k = XK_u;break;
1193 case Qt::Key_V: k = XK_v;break;
1194 case Qt::Key_W: k = XK_w;break;
1195 case Qt::Key_X: k = XK_x;break;
1196 case Qt::Key_Y: k = XK_y;break;
1197 case Qt::Key_Z: k = XK_z;break;
1198 }
1199 }
1200 else
1201 {
1202 switch (inkey)
1203 {
1204 case Qt::Key_A: k = XK_A;break;
1205 case Qt::Key_B: k = XK_B;break;
1206 case Qt::Key_C: k = XK_C;break;
1207 case Qt::Key_D: k = XK_D;break;
1208 case Qt::Key_E: k = XK_E;break;
1209 case Qt::Key_F: k = XK_F;break;
1210 case Qt::Key_G: k = XK_G;break;
1211 case Qt::Key_H: k = XK_H;break;
1212 case Qt::Key_I: k = XK_I;break;
1213 case Qt::Key_J: k = XK_J;break;
1214 case Qt::Key_K: k = XK_K;break;
1215 case Qt::Key_L: k = XK_L;break;
1216 case Qt::Key_M: k = XK_M;break;
1217 case Qt::Key_N: k = XK_N;break;
1218 case Qt::Key_O: k = XK_O;break;
1219 case Qt::Key_P: k = XK_P;break;
1220 case Qt::Key_Q: k = XK_Q;break;
1221 case Qt::Key_R: k = XK_R;break;
1222 case Qt::Key_S: k = XK_S;break;
1223 case Qt::Key_T: k = XK_T;break;
1224 case Qt::Key_U: k = XK_U;break;
1225 case Qt::Key_V: k = XK_V;break;
1226 case Qt::Key_W: k = XK_W;break;
1227 case Qt::Key_X: k = XK_X;break;
1228 case Qt::Key_Y: k = XK_Y;break;
1229 case Qt::Key_Z: k = XK_Z;break;
1230 }
1231 }
1232 }
1233
1234 return k;
1235
1236}
1237
1238void CConnectVnc::slotClipBoardChanged()
1239{
1240 //qDebug(log) << "CConnectVnc::slotClipBoardChanged()";
1241 if(!m_pPara->GetClipboard() || !getOutStream() || !writer()) return;
1242 QClipboard* pClip = QApplication::clipboard();
1243 if(pClip->ownsClipboard()) return;
1244 announceClipboard(true);
1245}
1246
1247void CConnectVnc::handleClipboardRequest()
1248{
1249 //qDebug(log) << "CConnectVnc::handleClipboardRequest";
1250 if(!m_pPara->GetClipboard() || !getOutStream() || !writer()) return;
1251 const QClipboard *clipboard = QApplication::clipboard();
1252 const QMimeData *mimeData = clipboard->mimeData();
1253
1254 /*if (mimeData->hasImage()) {
1255 // setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
1256 } else */if (mimeData->hasText()) {
1257 QString szText = mimeData->text();
1258 qDebug(log)
1259 << "CConnectVnc::handleClipboardRequest:szText:" << szText;
1260 try{
1261 sendClipboardData(szText.toStdString().c_str());
1262 } catch (rdr::Exception& e) {
1263 qCritical(log) << "sendClipboardData exception" << e.str();
1264 }
1265 } /*else if (mimeData->hasHtml()) {
1266 QString szHtml = mimeData->html();
1267 qDebug(log)
1268 << "CConnectVnc::handleClipboardRequest:html:" << szHtml;
1269 try{
1270 sendClipboardData(mimeData->html().toStdString().c_str());
1271 } catch (rdr::Exception& e) {
1272 qCritical(log) << "sendClipboardData exception" << e.str();
1273 }
1274 }*/ else {
1275 qCritical(log) << "Cannot display data";
1276 }
1277}
1278
1279void CConnectVnc::handleClipboardAnnounce(bool available)
1280{
1281 //qDebug(log) << "CConnectVnc::handleClipboardAnnounce";
1282 if(!m_pPara->GetClipboard() || !getOutStream() || !writer()) return;
1283 if(available)
1284 this->requestClipboard();
1285}
1286
1287void CConnectVnc::handleClipboardData(const char *data)
1288{
1289 //qDebug(log) << "CConnectVnc::handleClipboardData";
1290 if(!m_pPara->GetClipboard() || !getOutStream() || !writer()) return;
1291
1292 QMimeData* pData = new QMimeData();
1293 pData->setText(QString::fromUtf8(data));
1294 emit sigSetClipboard(pData);
1295}
1296
1297void CConnectVnc::authSuccess()
1298{
1299 qDebug(log) << "CConnectVnc::authSuccess";
1300}
The ICE channel interface class.
Definition ChannelIce.h:27
ssh tunnel class
The channel interface class.
Definition Channel.h:25
Remote desktop connect interface.
void sigUpdateRect(const QRect &r, const QImage &image)
Notify the CFrmView update image.
virtual int OnClean() override
Clean.
quint32 TranslateRfbKey(quint32 inkey, bool modifier)
CConnectVnc::TranslateRfbKey.
virtual int OnProcess() override
Specific operation processing of plug-in connection.
virtual int WakeUp() override
Wake up Connect thread(background thread)
virtual OnInitReturnValue OnInit() override
Specific plug-in realizes connection initialization.
void sigError(const int nError, const QString &szError=QString())
Triggered when an error is generated.
void sigBlockShowMessageBox(const QString &szTitle, const QString &szMessage, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton &nRet, bool &checkBox, QString checkBoxContext=QString())
Block background threads and display message dialogs in foreground threads (QMessageBox)
void sigShowMessageBox(const QString &szTitle, const QString &szMessage, const QMessageBox::Icon &icon=QMessageBox::Information)
Trigger the display of a message dialog (QMessageBox) in the main thread from a background thread wit...
void sigConnected()
Emitted when the plugin is successfully connected.
void sigDisconnect()
Notify the user to call disconnect.
void sigDisconnected()
Successful disconnection signal.
void sigBlockShowWidget(const QString &className, int &nRet, void *pContext)
Blocks the background thread and displays the window in the foreground thread.
virtual CParameterBase * GetParameter()
Get parameter.
It starts a background thread by default.
static CICE * Instance()
Single instance.
Definition Ice.cpp:55
The ICE signal interface class.
Definition IceSignal.h:26
CParameterUser m_User
[Instance user]
@ OnlyPasswordX509None
Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.