5#include <QNetworkProxy>
7#include <QLoggingCategory>
9#include "ConnectLibVNCServer.h"
11static Q_LOGGING_CATEGORY(log,
"LibVNCServer.Connect")
12static Q_LOGGING_CATEGORY(logger, "LibVNCServer.Connect.log")
13static Q_LOGGING_CATEGORY(logKey, "LibVNCServer.Connect.Key")
14static Q_LOGGING_CATEGORY(logMouse, "LibVNCServer.Connect.Mouse")
16const
char* gThis = "This pointer";
17#define LOG_BUFFER_LENGTH 1024
18static void rfbQtClientLog(
const char *format, ...)
22 char buf[LOG_BUFFER_LENGTH];
24 if(!rfbEnableClientLogging)
27 va_start(args, format);
28 nRet = vsnprintf(buf, LOG_BUFFER_LENGTH, format, args);
32 qCritical(log) <<
"vsnprintf fail";
35 if(nRet >= LOG_BUFFER_LENGTH)
37 qCritical(log) <<
"vsprintf buf is short,"
38 << nRet <<
">" << LOG_BUFFER_LENGTH
39 <<
". Truncated it:" << nRet - LOG_BUFFER_LENGTH;
40 buf[LOG_BUFFER_LENGTH - 1] = 0;
42 qDebug(logger) << buf;
53 rfbClientLog = rfbQtClientLog;
55 if(!m_pParameter->GetLocalCursor())
57 emit sigUpdateCursor(QCursor(Qt::BlankCursor));
61CConnectLibVNCServer::~CConnectLibVNCServer()
63 qDebug(log) <<
"CConnectLibVNCServer::~CConnectLibVNCServer()";
74 qDebug(log) <<
"CConnectLibVNCServer::OnInit()";
75 if(m_pClient) Q_ASSERT(
false);
77 m_pClient = rfbGetClient(8, 3, 4);
81 szErr = tr(
"Protocol version error");
83 qCritical(log) <<
"rfbGetClient fail";
84 return OnInitReturnValue::Fail;
88 m_pClient->programName = strdup(qApp->applicationName().toStdString().c_str());
89 m_pClient->appData.shareDesktop = m_pParameter->GetShared();
90 m_pClient->appData.viewOnly = m_pParameter->GetOnlyView();
91 m_pClient->appData.useRemoteCursor = m_pParameter->GetLocalCursor();
130 m_pClient->appData.enableJPEG = m_pParameter->GetJpeg();
131 if(m_pClient->appData.enableJPEG)
132 m_pClient->appData.qualityLevel = m_pParameter->GetQualityLevel();
133 if(m_pParameter->GetEnableCompressLevel())
134 m_pClient->appData.compressLevel = m_pParameter->GetCompressLevel();
137 m_pClient->MallocFrameBuffer = cb_resize;
138 m_pClient->GotFrameBufferUpdate = cb_update;
139 m_pClient->HandleKeyboardLedState = cb_kbd_leds;
140 m_pClient->Bell = cb_bell;
141 m_pClient->HandleTextChat = cb_text_chat;
142 m_pClient->GotXCutText = cb_got_selection;
143 m_pClient->GetCredential = cb_get_credential;
144 m_pClient->GetPassword = cb_get_password;
145 m_pClient->HandleCursorPos = cb_cursor_pos;
146 m_pClient->GotCursorShape = cb_got_cursor_shape;
148 m_pClient->canHandleNewFBSize = TRUE;
149 rfbClientSetClientData(m_pClient, (
void*)gThis,
this);
152 switch(m_pParameter->m_Proxy.GetUsedType())
154 case CParameterProxy::TYPE::None:
157 if(m_pParameter->m_Net.GetHost().isEmpty())
160 szErr = tr(
"The server is empty, please input it");
161 qCritical(log) << szErr;
163 return OnInitReturnValue::Fail;
165 auto &net = m_pParameter->m_Net;
166 m_pClient->serverHost = strdup(net.GetHost().toStdString().c_str());
167 m_pClient->serverPort = net.GetPort();
169 if(!rfbInitClient(m_pClient,
nullptr,
nullptr))
172 szErr = tr(
"Connect to %1:%2 fail").arg(m_pParameter->m_Net.GetHost(),
173 QString::number(m_pParameter->m_Net.GetPort()));
174 qCritical(log) << szErr;
176 return OnInitReturnValue::Fail;
179 QString szInfo = QString(
"Connect to ") + m_pClient->desktopName;
180 qInfo(log) << szInfo;
182 emit sigSetDesktopSize(m_pClient->width, m_pClient->height);
183 emit sigServerName(m_pClient->desktopName);
186 return OnInitReturnValue::UseOnProcess;
230 case CParameterProxy::TYPE::SSHTunnel:
234 auto &ssh = m_pParameter->m_Proxy.m_SSH;
235 parameter->setServer(ssh.GetHost());
236 parameter->setPort(ssh.GetPort());
238 parameter->SetUser(user.GetUser());
239 parameter->SetUseSystemFile(user.GetUseSystemFile());
240 if(CParameterUser::TYPE::UserPassword == user.GetUsedType()) {
241 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PASSWORD);
242 parameter->SetPassword(user.GetPassword());
244 if(CParameterUser::TYPE::PublicKey == user.GetUsedType()) {
245 parameter->SetAuthenticationMethod(SSH_AUTH_METHOD_PUBLICKEY);
246 parameter->SetPublicKeyFile(user.GetPublicKeyFile());
247 parameter->SetPrivateKeyFile(user.GetPrivateKeyFile());
248 parameter->SetPassphrase(user.GetPassphrase());
250 auto &net = m_pParameter->m_Net;
251 parameter->SetRemoteHost(net.GetHost());
252 parameter->SetRemotePort(net.GetPort());
258 return OnInitReturnValue::Fail;
259 bool check = connect(m_pThread, SIGNAL(sigServer(QString, quint16)),
262#if defined(HAVE_UNIX_DOMAIN_SOCKET) && defined(Q_OS_UNIX)
263 check = connect(m_pThread, SIGNAL(sigServer(QString)),
267 check = connect(m_pThread, SIGNAL(
sigError(
int,QString)),
268 this, SIGNAL(
sigError(
int,QString)));
275 return OnInitReturnValue::UseOnProcess;
283 return OnInitReturnValue::UseOnProcess;
288 qDebug(log) <<
"CConnectLibVNCServer::OnClean()";
300 rfbClientCleanup(m_pClient);
329 struct timeval timeout = {0, 50000};
332 if(RFB_INVALID_SOCKET != m_pClient->sock)
334 FD_SET(m_pClient->sock, &set);
336 rfbSocket eventFd = m_Event.GetFd();
337 if(RFB_INVALID_SOCKET != eventFd)
339 FD_SET(eventFd, &set);
341 rfbSocket fd = RFB_INVALID_SOCKET;
342 fd = std::max(eventFd, m_pClient->sock);
344 nRet = select(fd + 1, &set, NULL, NULL, &timeout);
347 qCritical(log) <<
"select fail:" << nRet <<
"errno" << errno << strerror(errno);
357 if(RFB_INVALID_SOCKET != eventFd && FD_ISSET(eventFd, &set))
363 if(RFB_INVALID_SOCKET != m_pClient->sock
364 && FD_ISSET(m_pClient->sock, &set)) {
366 if(!HandleRFBServerMessage(m_pClient))
368 qCritical(log) <<
"HandleRFBServerMessage fail";
378 return m_Event.WakeUp();
381void CConnectLibVNCServer::slotClipBoardChanged()
383 if(!m_pParameter || !m_pParameter->GetClipboard() || !m_pClient)
return;
384 QClipboard* pClipboard = QApplication::clipboard();
387 QString szText = pClipboard->text();
388 if(!szText.isEmpty() && m_pClient)
389 SendClientCutText(m_pClient,
390 (
char*)szText.toStdString().c_str(),
391 szText.toStdString().length());
395rfbBool CConnectLibVNCServer::cb_resize(rfbClient* client)
399 if(pThis->OnSize())
return FALSE;
403void CConnectLibVNCServer::cb_update(rfbClient *client,
int x,
int y,
int w,
int h)
409 QRect rect(x, y, w, h);
410 QImage img = pThis->m_Image.copy(rect);
414void CConnectLibVNCServer::cb_got_selection(rfbClient *client,
const char *text,
int len)
418 if(!pThis->m_pParameter->GetClipboard())
return;
419 QClipboard* pClipboard = QApplication::clipboard();
421 pClipboard->setText(text);
424void CConnectLibVNCServer::cb_kbd_leds(rfbClient *client,
int value,
int pad)
426 qDebug(log) <<
"CConnectLibVnc::cb_kbd_leds";
429void CConnectLibVNCServer::cb_bell(
struct _rfbClient *client)
434void CConnectLibVNCServer::cb_text_chat(rfbClient *client,
int value,
char *text)
436 qDebug(log) <<
"CConnectLibVnc::cb_text_chat";
439rfbCredential* CConnectLibVNCServer::cb_get_credential(rfbClient *cl,
int credentialType)
441 qDebug(log) <<
"CConnectLibVnc::cb_get_credential";
443 rfbCredential *c = (rfbCredential*)malloc(
sizeof(rfbCredential));
444 c->userCredential.username = (
char*)malloc(RFB_BUF_SIZE);
445 memset(c->userCredential.username, 0, RFB_BUF_SIZE);
446 c->userCredential.password = (
char*)malloc(RFB_BUF_SIZE);
447 memset(c->userCredential.password, 0, RFB_BUF_SIZE);
449 if(credentialType != rfbCredentialTypeUser) {
450 qCritical(log) <<
"something else than username and password required for authentication";
454 qDebug(log) <<
"Username and password required for authentication!";
456 memcpy(c->userCredential.username,
457 pThis->m_pParameter->m_Net.
m_User.GetUser().toStdString().c_str(),
458 pThis->m_pParameter->m_Net.
m_User.GetUser().toStdString().length());
459 memcpy(c->userCredential.password,
460 pThis->m_pParameter->m_Net.
m_User.GetPassword().toStdString().c_str(),
461 pThis->m_pParameter->m_Net.
m_User.GetPassword().toStdString().length());
466char* CConnectLibVNCServer::cb_get_password(rfbClient *client)
470 QString szPassword = pThis->m_pParameter->m_Net.
m_User.GetPassword();
471 if(szPassword.isEmpty())
473 int nRet = QDialog::Rejected;
474 emit pThis->
sigBlockShowWidget(
"CDlgLibVNCServerPassword", nRet, pThis->m_pParameter);
475 if(QDialog::Accepted == nRet)
477 szPassword = pThis->m_pParameter->m_Net.
m_User.GetPassword();
479 if(szPassword.isEmpty())
482 return strdup(szPassword.toStdString().c_str());
485int CConnectLibVNCServer::OnSize()
488 int nWidth = m_pClient->width;
489 int nHeight = m_pClient->height;
491 m_Image = QImage(nWidth, nHeight, QImage::Format_RGB32);
493 m_pClient->frameBuffer = m_Image.bits();
495 m_pClient->format.bitsPerPixel = 32;
496 m_pClient->format.depth = m_Image.depth();
497 m_pClient->format.redShift = 16;
498 m_pClient->format.greenShift = 8;
499 m_pClient->format.blueShift = 0;
500 m_pClient->format.redMax = 255;
501 m_pClient->format.greenMax = 255;
502 m_pClient->format.blueMax = 255;
503 SetFormatAndEncodings(m_pClient);
505 emit sigSetDesktopSize(m_pClient->width, m_pClient->height);
509rfbBool CConnectLibVNCServer::cb_cursor_pos(rfbClient *client,
int x,
int y)
517void CConnectLibVNCServer::cb_got_cursor_shape(rfbClient *client,
519 int width,
int height,
525 if(!client->rcSource)
527 qCritical(log) <<
"client->rcSource is null";
531 if ((width == 0) || (height == 0)) {
532 QImage cursor(1, 1, QImage::Format_ARGB32);
533 uchar* buffer = cursor.bits();
534 memset(buffer, 0, 4);
535 emit pThis->sigUpdateCursor(QCursor(QPixmap::fromImage(cursor), xhot, yhot));
537 switch (bytesPerPixel) {
540 QImage cursor(width, height, QImage::Format_ARGB32);
541 uchar *buffer = cursor.bits();
542 memcpy(buffer, client->rcSource, width * height * 4);
543 uchar* pMask = client->rcMask;
546 uchar* pDest = buffer;
547 for(
int y = 0; y < height; y++)
549 for(
int w = 0; w < width; w++)
555 QColor c = cursor.pixel(w, y);
557 cursor.setPixelColor(w,y,c);
560 *((uint32_t*)pDest) = 0;
566 emit pThis->sigUpdateCursor(QCursor(QPixmap::fromImage(cursor), xhot, yhot));
575void CConnectLibVNCServer::mousePressEvent(QMouseEvent *event)
577 if(!m_pClient)
return;
578 if(m_pParameter && m_pParameter->GetOnlyView())
return;
580 unsigned char mask = 0;
581 if(event->button() & Qt::MouseButton::LeftButton)
583 if(event->button() & Qt::MouseButton::MiddleButton)
585 if(event->button() & Qt::MouseButton::RightButton)
587 if(event->button() & Qt::MouseButton::BackButton)
589 QPoint pos =
event->pos();
591 qDebug(logMouse) << Q_FUNC_INFO <<
event->buttons() <<
event->button() << pos << mask;
593 SendPointerEvent(m_pClient, pos.x(), pos.y(), mask);
596void CConnectLibVNCServer::mouseReleaseEvent(QMouseEvent *event)
598 if(!m_pClient)
return;
599 if(m_pParameter && m_pParameter->GetOnlyView())
return;
601 QPoint pos =
event->pos();
602 qDebug(logMouse) << Q_FUNC_INFO <<
event->buttons() <<
event->button() << pos << mask;
603 SendPointerEvent(m_pClient, pos.x(), pos.y(), mask);
606void CConnectLibVNCServer::mouseMoveEvent(QMouseEvent *event)
608 if(!m_pClient)
return;
609 if(m_pParameter && m_pParameter->GetOnlyView())
return;
611 if(event->buttons() & Qt::MouseButton::LeftButton)
613 if(event->buttons() & Qt::MouseButton::MiddleButton)
615 if(event->buttons() & Qt::MouseButton::RightButton)
617 if(event->buttons() & Qt::MouseButton::BackButton)
619 QPoint pos =
event->pos();
620 qDebug(logMouse) << Q_FUNC_INFO <<
event->buttons() <<
event->button() << pos << mask;
621 SendPointerEvent(m_pClient, pos.x(), pos.y(), mask);
625void CConnectLibVNCServer::wheelEvent(QWheelEvent *event)
627 if(!m_pClient)
return;
628 if(m_pParameter && m_pParameter->GetOnlyView())
return;
630 if(event->buttons() & Qt::MouseButton::LeftButton)
632 if(event->buttons() & Qt::MouseButton::MiddleButton)
634 if(event->buttons() & Qt::MouseButton::RightButton)
636 if(event->buttons() & Qt::MouseButton::BackButton)
639 QPoint d =
event->angleDelta();
650#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
651 pos =
event->position();
656 qDebug(logMouse) << Q_FUNC_INFO <<
event->buttons() <<
event->angleDelta() << pos;
658 SendPointerEvent(m_pClient, pos.x(), pos.y(), mask);
668uint32_t TranslateRfbKey(quint32 inkey,
bool modifier)
674 case Qt::Key_Backspace: k = XK_BackSpace;
break;
675 case Qt::Key_Tab: k = XK_Tab;
break;
676 case Qt::Key_Clear: k = XK_Clear;
break;
677 case Qt::Key_Return: k = XK_Return;
break;
678 case Qt::Key_Pause: k = XK_Pause;
break;
679 case Qt::Key_Escape: k = XK_Escape;
break;
680 case Qt::Key_Space: k = XK_space;
break;
681 case Qt::Key_Delete: k = XK_Delete;
break;
682 case Qt::Key_Period: k = XK_period;
break;
685 case Qt::Key_Multi_key: k = XK_Multi_key;
break;
686 case Qt::Key_SingleCandidate: k = XK_SingleCandidate;
break;
687 case Qt::Key_MultipleCandidate: k = XK_MultipleCandidate;
break;
688 case Qt::Key_PreviousCandidate: k = XK_PreviousCandidate;
break;
691 case Qt::Key_Kanji: k = XK_Kanji;
break;
692 case Qt::Key_Muhenkan: k = XK_Muhenkan;
break;
693 case Qt::Key_Henkan: k = XK_Henkan;
break;
694 case Qt::Key_Romaji: k = XK_Romaji;
break;
695 case Qt::Key_Hiragana: k = XK_Hiragana;
break;
696 case Qt::Key_Katakana: k = XK_Katakana;
break;
697 case Qt::Key_Hiragana_Katakana: k = XK_Hiragana_Katakana;
break;
698 case Qt::Key_Zenkaku: k = XK_Zenkaku;
break;
699 case Qt::Key_Hankaku: k = XK_Hankaku;
break;
700 case Qt::Key_Zenkaku_Hankaku: k = XK_Zenkaku_Hankaku;
break;
701 case Qt::Key_Touroku: k = XK_Touroku;
break;
702 case Qt::Key_Massyo: k = XK_Massyo;
break;
703 case Qt::Key_Kana_Lock: k = XK_Kana_Lock;
break;
704 case Qt::Key_Kana_Shift: k = XK_Kana_Shift;
break;
705 case Qt::Key_Eisu_Shift: k = XK_Eisu_Shift;
break;
706 case Qt::Key_Eisu_toggle: k = XK_Eisu_toggle;
break;
709 case Qt::Key_Exclam: k = XK_exclam;
break;
710 case Qt::Key_QuoteDbl: k = XK_quotedbl;
break;
711 case Qt::Key_NumberSign: k = XK_numbersign;
break;
712 case Qt::Key_Percent: k = XK_percent;
break;
713 case Qt::Key_Dollar: k = XK_dollar;
break;
714 case Qt::Key_Ampersand: k = XK_ampersand;
break;
715 case Qt::Key_Apostrophe: k = XK_apostrophe;
break;
716 case Qt::Key_ParenLeft: k = XK_parenleft;
break;
717 case Qt::Key_ParenRight: k = XK_parenright;
break;
719 case Qt::Key_Slash: k = XK_slash;
break;
720 case Qt::Key_Asterisk: k = XK_asterisk;
break;
721 case Qt::Key_Minus: k = XK_minus;
break;
722 case Qt::Key_Plus: k = XK_plus;
break;
723 case Qt::Key_Enter: k = XK_Return;
break;
724 case Qt::Key_Equal: k = XK_equal;
break;
725 case Qt::Key_Comma:
return XK_comma;
727 case Qt::Key_Colon: k = XK_colon;
break;
728 case Qt::Key_Semicolon: k = XK_semicolon;
break;
729 case Qt::Key_Less: k = XK_less;
break;
730 case Qt::Key_Greater: k = XK_greater;
break;
731 case Qt::Key_Question: k = XK_question;
break;
732 case Qt::Key_At: k = XK_at;
break;
734 case Qt::Key_BracketLeft: k = XK_bracketleft;
break;
735 case Qt::Key_Backslash: k = XK_backslash;
break;
736 case Qt::Key_BracketRight: k = XK_bracketright;
break;
737 case Qt::Key_AsciiCircum: k = XK_asciicircum;
break;
738 case Qt::Key_Underscore: k = XK_underscore;
break;
739 case Qt::Key_QuoteLeft: k = XK_quoteleft;
break;
740 case Qt::Key_BraceLeft: k = XK_braceleft;
break;
741 case Qt::Key_Bar: k = XK_bar;
break;
742 case Qt::Key_BraceRight: k = XK_braceright;
break;
743 case Qt::Key_AsciiTilde: k = XK_asciitilde;
break;
744 case Qt::Key_nobreakspace: k = XK_nobreakspace;
break;
745 case Qt::Key_exclamdown: k = XK_exclamdown;
break;
746 case Qt::Key_cent: k = XK_cent;
break;
747 case Qt::Key_sterling: k = XK_sterling;
break;
748 case Qt::Key_currency: k = XK_currency;
break;
749 case Qt::Key_yen: k = XK_yen;
break;
750 case Qt::Key_brokenbar: k = XK_brokenbar;
break;
751 case Qt::Key_section: k = XK_section;
break;
752 case Qt::Key_diaeresis: k = XK_diaeresis;
break;
753 case Qt::Key_copyright: k = XK_copyright;
break;
754 case Qt::Key_ordfeminine: k = XK_ordfeminine;
break;
755 case Qt::Key_guillemotleft: k = XK_guillemotleft;
break;
756 case Qt::Key_guillemotright: k = XK_guillemotright;
break;
757 case Qt::Key_notsign: k = XK_notsign;
break;
758 case Qt::Key_hyphen: k = XK_hyphen;
break;
759 case Qt::Key_registered: k = XK_registered;
break;
761 case Qt::Key_Up: k = XK_Up;
break;
762 case Qt::Key_Down: k = XK_Down;
break;
763 case Qt::Key_Right: k = XK_Right;
break;
764 case Qt::Key_Left: k = XK_Left;
break;
765 case Qt::Key_Insert: k = XK_Insert;
break;
766 case Qt::Key_Home: k = XK_Home;
break;
767 case Qt::Key_End: k = XK_End;
break;
768 case Qt::Key_PageUp: k = XK_Page_Up;
break;
769 case Qt::Key_PageDown: k = XK_Page_Down;
break;
770 case Qt::Key_MediaPrevious: k = XK_Prior;
break;
771 case Qt::Key_MediaNext: k = XK_Next;
break;
772 case Qt::Key_MediaPlay: k = XK_Begin;
break;
775 case Qt::Key_Select: k = XK_Select;
break;
776 case Qt::Key_Printer: k = XK_Print;
break;
777 case Qt::Key_Execute: k = XK_Execute;
break;
778 case Qt::Key_Undo: k = XK_Undo;
break;
779 case Qt::Key_Redo: k = XK_Redo;
break;
780 case Qt::Key_Menu: k = XK_Menu;
break;
781 case Qt::Key_Find: k = XK_Find;
break;
787 case Qt::Key_Mode_switch: k = XK_Mode_switch;
break;
789 case Qt::Key_F1: k = XK_F1;
break;
790 case Qt::Key_F2: k = XK_F2;
break;
791 case Qt::Key_F3: k = XK_F3;
break;
792 case Qt::Key_F4: k = XK_F4;
break;
793 case Qt::Key_F5: k = XK_F5;
break;
794 case Qt::Key_F6: k = XK_F6;
break;
795 case Qt::Key_F7: k = XK_F7;
break;
796 case Qt::Key_F8: k = XK_F8;
break;
797 case Qt::Key_F9: k = XK_F9;
break;
798 case Qt::Key_F10: k = XK_F10;
break;
799 case Qt::Key_F11: k = XK_F11;
break;
800 case Qt::Key_F12: k = XK_F12;
break;
801 case Qt::Key_F13: k = XK_F13;
break;
802 case Qt::Key_F14: k = XK_F14;
break;
803 case Qt::Key_F15: k = XK_F15;
break;
804 case Qt::Key_F16: k = XK_F16;
break;
805 case Qt::Key_F17: k = XK_F17;
break;
806 case Qt::Key_F18: k = XK_F18;
break;
807 case Qt::Key_F19: k = XK_F19;
break;
808 case Qt::Key_F20: k = XK_F20;
break;
809 case Qt::Key_F21: k = XK_F21;
break;
810 case Qt::Key_F22: k = XK_F22;
break;
811 case Qt::Key_F23: k = XK_F23;
break;
812 case Qt::Key_F24: k = XK_F24;
break;
813 case Qt::Key_F25: k = XK_F25;
break;
814 case Qt::Key_F26: k = XK_F26;
break;
815 case Qt::Key_F27: k = XK_F27;
break;
816 case Qt::Key_F28: k = XK_F28;
break;
817 case Qt::Key_F29: k = XK_F29;
break;
818 case Qt::Key_F30: k = XK_F30;
break;
819 case Qt::Key_F31: k = XK_F31;
break;
820 case Qt::Key_F32: k = XK_F32;
break;
821 case Qt::Key_F33: k = XK_F33;
break;
822 case Qt::Key_F34: k = XK_F34;
break;
823 case Qt::Key_F35: k = XK_F35;
break;
825 case Qt::Key_NumLock: k = XK_Num_Lock;
break;
826 case Qt::Key_CapsLock: k = XK_Caps_Lock;
break;
827 case Qt::Key_ScrollLock: k = XK_Scroll_Lock;
break;
829 case Qt::Key_Shift: k = XK_Shift_R;
break;
830 case Qt::Key_Control: k = XK_Control_R;
break;
831 case Qt::Key_Alt: k = XK_Alt_R;
break;
832 case Qt::Key_Meta: k = XK_Meta_R;
break;
834 case Qt::Key_Super_L: k = XK_Super_L;
break;
835 case Qt::Key_Super_R: k = XK_Super_R;
break;
837 case Qt::Key_Help: k = XK_Help;
break;
838 case Qt::Key_Print: k = XK_Print;
break;
839 case Qt::Key_SysReq: k = XK_Sys_Req;
break;
840 case Qt::Key_0: k = XK_0;
break;
841 case Qt::Key_1: k = XK_1;
break;
842 case Qt::Key_2: k = XK_2;
break;
843 case Qt::Key_3: k = XK_3;
break;
844 case Qt::Key_4: k = XK_4;
break;
845 case Qt::Key_5: k = XK_5;
break;
846 case Qt::Key_6: k = XK_6;
break;
847 case Qt::Key_7: k = XK_7;
break;
848 case Qt::Key_8: k = XK_8;
break;
849 case Qt::Key_9: k = XK_9;
break;
859 case Qt::Key_A: k = XK_a;
break;
860 case Qt::Key_B: k = XK_b;
break;
861 case Qt::Key_C: k = XK_c;
break;
862 case Qt::Key_D: k = XK_d;
break;
863 case Qt::Key_E: k = XK_e;
break;
864 case Qt::Key_F: k = XK_f;
break;
865 case Qt::Key_G: k = XK_g;
break;
866 case Qt::Key_H: k = XK_h;
break;
867 case Qt::Key_I: k = XK_i;
break;
868 case Qt::Key_J: k = XK_j;
break;
869 case Qt::Key_K: k = XK_k;
break;
870 case Qt::Key_L: k = XK_l;
break;
871 case Qt::Key_M: k = XK_m;
break;
872 case Qt::Key_N: k = XK_n;
break;
873 case Qt::Key_O: k = XK_o;
break;
874 case Qt::Key_P: k = XK_p;
break;
875 case Qt::Key_Q: k = XK_q;
break;
876 case Qt::Key_R: k = XK_r;
break;
877 case Qt::Key_S: k = XK_s;
break;
878 case Qt::Key_T: k = XK_t;
break;
879 case Qt::Key_U: k = XK_u;
break;
880 case Qt::Key_V: k = XK_v;
break;
881 case Qt::Key_W: k = XK_w;
break;
882 case Qt::Key_X: k = XK_x;
break;
883 case Qt::Key_Y: k = XK_y;
break;
884 case Qt::Key_Z: k = XK_z;
break;
891 case Qt::Key_A: k = XK_A;
break;
892 case Qt::Key_B: k = XK_B;
break;
893 case Qt::Key_C: k = XK_C;
break;
894 case Qt::Key_D: k = XK_D;
break;
895 case Qt::Key_E: k = XK_E;
break;
896 case Qt::Key_F: k = XK_F;
break;
897 case Qt::Key_G: k = XK_G;
break;
898 case Qt::Key_H: k = XK_H;
break;
899 case Qt::Key_I: k = XK_I;
break;
900 case Qt::Key_J: k = XK_J;
break;
901 case Qt::Key_K: k = XK_K;
break;
902 case Qt::Key_L: k = XK_L;
break;
903 case Qt::Key_M: k = XK_M;
break;
904 case Qt::Key_N: k = XK_N;
break;
905 case Qt::Key_O: k = XK_O;
break;
906 case Qt::Key_P: k = XK_P;
break;
907 case Qt::Key_Q: k = XK_Q;
break;
908 case Qt::Key_R: k = XK_R;
break;
909 case Qt::Key_S: k = XK_S;
break;
910 case Qt::Key_T: k = XK_T;
break;
911 case Qt::Key_U: k = XK_U;
break;
912 case Qt::Key_V: k = XK_V;
break;
913 case Qt::Key_W: k = XK_W;
break;
914 case Qt::Key_X: k = XK_X;
break;
915 case Qt::Key_Y: k = XK_Y;
break;
916 case Qt::Key_Z: k = XK_Z;
break;
924void CConnectLibVNCServer::keyPressEvent(QKeyEvent *event)
926 if(!m_pClient)
return;
927 if(m_pParameter && m_pParameter->GetOnlyView())
return;
928 bool modifier =
false;
929 if (event->modifiers() & Qt::ShiftModifier)
931 uint32_t k = TranslateRfbKey(event->key(), modifier);
932 qDebug(logKey) << Q_FUNC_INFO <<
event << k << modifier;
933 SendKeyEvent(m_pClient, k, TRUE);
936void CConnectLibVNCServer::keyReleaseEvent(QKeyEvent *event)
938 if(!m_pClient)
return;
939 if(m_pParameter && m_pParameter->GetOnlyView())
return;
940 bool modifier =
false;
941 if (event->modifiers() & Qt::ShiftModifier)
943 uint32_t k = TranslateRfbKey(event->key(), modifier);
944 qDebug(logKey) << Q_FUNC_INFO <<
event << k << modifier;
945 SendKeyEvent(m_pClient, k, FALSE);
952 qDebug(log) <<
"CConnectLibVNCServer::slotConnectServer" << nPort;
954 m_pClient->serverHost = strdup(szHost.toStdString().c_str());
955 m_pClient->serverPort = nPort;
956 szErr = tr(
"Connect to local socket server %1:%2")
957 .arg(m_pClient->serverHost,
958 QString::number(m_pClient->serverPort));
959 qDebug(log) << szErr;
960 if(!rfbInitClient(m_pClient,
nullptr,
nullptr))
962 szErr += tr(
" fail");
963 qCritical(log) << szErr;
968 QString szInfo = QString(
"Connect to ") + m_pClient->desktopName;
969 qInfo(log) << szInfo;
971 emit sigSetDesktopSize(m_pClient->width, m_pClient->height);
972 emit sigServerName(m_pClient->desktopName);
977#if defined(HAVE_UNIX_DOMAIN_SOCKET) && defined(Q_OS_UNIX)
981 qDebug(log) <<
"CConnectLibVNCServer::slotConnectServer" << szFile;
983 m_pClient->serverHost = strdup(szFile.toStdString().c_str());
984 szErr = tr(
"Connect to local socket server ") + szFile;
985 qDebug(log) << szErr;
986 if(!rfbInitClient(m_pClient,
nullptr,
nullptr))
988 szErr += +
" " + tr(
"fail");
989 qCritical(log) << szErr;
994 QString szInfo = QString(
"Connect to ") + m_pClient->desktopName;
995 qInfo(log) << szInfo;
997 emit sigSetDesktopSize(m_pClient->width, m_pClient->height);
998 emit sigServerName(m_pClient->desktopName);
Remote desktop connect interface.
void sigUpdateRect(const QRect &r, const QImage &image)
Notify the CFrmView update image.
void slotConnectProxyServer(QString szHost, quint16 nPort)
[connect local socket server]
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.
virtual int OnClean() override
Clean.
void sigError(const int nError, const QString &szError=QString())
Triggered when an error is generated.
void sigInformation(const QString &szInfo)
Triggering from a background thread displays information in the main thread without blocking the back...
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 sigBlockShowWidget(const QString &className, int &nRet, void *pContext)
Blocks the background thread and displays the window in the foreground thread.
CParameterUser m_User
[Instance user]
Data is forwarded over a local socket and SSH tunnel.