1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtGui module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QVNCCLIENT_H 41 #define QVNCCLIENT_H 42 43 #include <QObject> 44 45 #include "qvnc_p.h" 46 47 QT_BEGIN_NAMESPACE 48 49 class QTcpSocket; 50 class QVncServer; 51 52 class QVncClient : public QObject 53 { 54 Q_OBJECT 55 public: 56 enum ClientMsg { 57 SetPixelFormat = 0, 58 FixColourMapEntries = 1, 59 SetEncodings = 2, 60 FramebufferUpdateRequest = 3, 61 KeyEvent = 4, 62 PointerEvent = 5, 63 ClientCutText = 6 64 }; 65 66 explicit QVncClient(QTcpSocket *clientSocket, QVncServer *server); 67 ~QVncClient(); 68 QTcpSocket *clientSocket() const; server()69 QVncServer *server() const { return m_server; } 70 71 void setDirty(const QRegion ®ion); setDirtyCursor()72 void setDirtyCursor() { m_dirtyCursor = true; scheduleUpdate(); } dirtyRegion()73 QRegion dirtyRegion() const { return m_dirtyRegion; } isConnected()74 inline bool isConnected() const { return m_state == Connected; } 75 clientBytesPerPixel()76 inline int clientBytesPerPixel() const { 77 return m_pixelFormat.bitsPerPixel / 8; 78 } 79 80 void convertPixels(char *dst, const char *src, int count) const; doPixelConversion()81 inline bool doPixelConversion() const { return m_needConversion; } 82 83 signals: 84 85 private slots: 86 void readClient(); 87 void discardClient(); 88 void checkUpdate(); 89 void scheduleUpdate(); 90 91 protected: 92 bool event(QEvent *event) override; 93 94 private: 95 enum ClientState { 96 Disconnected, 97 Protocol, 98 Authentication, 99 Init, 100 Connected 101 }; 102 enum ProtocolVersion { 103 V3_3, 104 V3_7, 105 V3_8 106 }; 107 108 void setPixelFormat(); 109 void setEncodings(); 110 void frameBufferUpdateRequest(); 111 void pointerEvent(); 112 void keyEvent(); 113 void clientCutText(); 114 bool pixelConversionNeeded() const; 115 116 QVncServer *m_server; 117 QTcpSocket *m_clientSocket; 118 QRfbEncoder *m_encoder; 119 120 // Client State 121 ClientState m_state; 122 quint8 m_msgType; 123 bool m_handleMsg; 124 QRfbPixelFormat m_pixelFormat; 125 bool m_sameEndian; 126 bool m_needConversion; 127 int m_encodingsPending; 128 int m_cutTextPending; 129 uint m_supportCopyRect : 1; 130 uint m_supportRRE : 1; 131 uint m_supportCoRRE : 1; 132 uint m_supportHextile : 1; 133 uint m_supportZRLE : 1; 134 uint m_supportCursor : 1; 135 uint m_supportDesktopSize : 1; 136 bool m_wantUpdate; 137 Qt::KeyboardModifiers m_keymod; 138 bool m_dirtyCursor; 139 bool m_updatePending; 140 #if Q_BYTE_ORDER == Q_BIG_ENDIAN 141 bool m_swapBytes; 142 #endif 143 QRegion m_dirtyRegion; 144 ProtocolVersion m_protocolVersion; 145 }; 146 147 QT_END_NAMESPACE 148 149 #endif // QVNCCLIENT_H 150