diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-16 15:55:33 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-18 09:01:11 +0000 |
commit | c4bd6beca3e7c3e8cf31af2f3fdd08a1f7aeabcb (patch) | |
tree | 6edba5d8eae036fbe59b6b952b959a147662e94d /src/qmldebug/qqmldebugconnection.cpp | |
parent | fee44872dce081b3480f3cb3bb74d12940a92068 (diff) |
QmlDebug: Add some useful methods to QQmlDebugConnection
Change-Id: Iee2c09278f31ea93da9c02be6b2fc909b5f154d0
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qmldebug/qqmldebugconnection.cpp')
-rw-r--r-- | src/qmldebug/qqmldebugconnection.cpp | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/qmldebug/qqmldebugconnection.cpp b/src/qmldebug/qqmldebugconnection.cpp index e8650ebbff..3c207b7cc8 100644 --- a/src/qmldebug/qqmldebugconnection.cpp +++ b/src/qmldebug/qqmldebugconnection.cpp @@ -109,6 +109,7 @@ void QQmlDebugConnection::socketDisconnected() { Q_D(QQmlDebugConnection); d->gotHello = false; + emit disconnected(); } void QQmlDebugConnection::protocolReadyRead() @@ -273,6 +274,12 @@ bool QQmlDebugConnection::isConnected() const return d->gotHello; } +bool QQmlDebugConnection::isConnecting() const +{ + Q_D(const QQmlDebugConnection); + return !d->gotHello && d->device; +} + void QQmlDebugConnection::close() { Q_D(QQmlDebugConnection); @@ -372,7 +379,10 @@ void QQmlDebugConnection::connectToHost(const QString &hostName, quint16 port) d->device = socket; d->connectDeviceSignals(); connect(socket, SIGNAL(connected()), this, SLOT(socketConnected())); - connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); + connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SIGNAL(socketError(QAbstractSocket::SocketError))); + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), + this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); socket->connectToHost(hostName, port); } @@ -389,6 +399,34 @@ void QQmlDebugConnection::startLocalServer(const QString &fileName) d->server->listen(fileName); } +class LocalSocketSignalTranslator : public QObject +{ + Q_OBJECT +public: + LocalSocketSignalTranslator(QLocalSocket *parent) : QObject(parent) + { + connect(parent, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)), + this, SLOT(onStateChanged(QLocalSocket::LocalSocketState))); + connect(parent, SIGNAL(error(QLocalSocket::LocalSocketError)), + this, SLOT(onError(QLocalSocket::LocalSocketError))); + } + +signals: + void socketError(QAbstractSocket::SocketError error); + void socketStateChanged(QAbstractSocket::SocketState state); + +public slots: + void onError(QLocalSocket::LocalSocketError error) + { + emit socketError(static_cast<QAbstractSocket::SocketError>(error)); + } + + void onStateChanged(QLocalSocket::LocalSocketState state) + { + emit socketStateChanged(static_cast<QAbstractSocket::SocketState>(state)); + } +}; + void QQmlDebugConnection::newConnection() { Q_D(QQmlDebugConnection); @@ -397,6 +435,12 @@ void QQmlDebugConnection::newConnection() d->server->close(); d->device = socket; d->connectDeviceSignals(); + LocalSocketSignalTranslator *translator = new LocalSocketSignalTranslator(socket); + + QObject::connect(translator, SIGNAL(socketError(QAbstractSocket::SocketError)), + this, SIGNAL(socketError(QAbstractSocket::SocketError))); + QObject::connect(translator, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)), + this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); socketConnected(); } @@ -410,3 +454,5 @@ void QQmlDebugConnectionPrivate::connectDeviceSignals() } QT_END_NAMESPACE + +#include <qqmldebugconnection.moc> |