#ifndef _PVSSERVERCONNECTION_H_ #define _PVSSERVERCONNECTION_H_ #include #include "../../shared/networkmessage.h" #include "../connectwindow/connectwindow.h" class BlankScreen; class ServerConnection : public QObject { Q_OBJECT private: QSslSocket *_socket; BlankScreen *_blank; int _timerId, _timerDelete, _timerConnectionCheck; int _jpegQuality; int _authed; bool _autoConnect; int _isLocalConnection; qint64 _lastData; NetworkMessage _fromServer, _toServer; QByteArray _expectedFingerprint; QString _passwd; QByteArray _myChallenge; QByteArray _sessionName; QByteArray _certHash; void handleMsg(); void checkLocalConnection(); public: ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); void disconnectFromServer(); ~ServerConnection(); inline bool isConnected() const { return _socket != nullptr && _socket->state() == QAbstractSocket::ConnectedState; } const inline QString getPeerAdress() const { return _socket->peerAddress().toString(); } bool isLocalConnection() { if (_isLocalConnection == -1) { checkLocalConnection(); } return _isLocalConnection == 1; } void sendMessage(NetworkMessage& message); void sendAttention(bool on); protected: void timerEvent(QTimerEvent *event); private slots: void sslErrors(const QList & errors); // triggered for errors that occur during SSL negotiation void sock_dataArrival(); // triggered if data is available for reading void sock_closed(); // triggered if the socket is closed void sock_error(QAbstractSocket::SocketError errcode); // triggered if an error occurs on the socket void sock_connected(); // triggered if the connection is established and ready to use void onVncServerStartStop(int port, QString& ropass, QString& rwpass); // triggered if the local vnc server was started void onVncViewerStartStop(const bool started, const int clientId); signals: void openVnc(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId, const QByteArray& rawThumb); void closeVnc(); void stateChange(ConnectWindow::ConnectionState state); void disconnected(ServerConnection* connection); void attentionChanged(bool state); }; #endif