diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp index a0af7a65181bcb4db14c619030551286ce421c57..6bbe091c5b8d7f6e579b384f51c666207c13081d 100644 --- a/src/libs/qmldebug/qmldebugclient.cpp +++ b/src/libs/qmldebug/qmldebugclient.cpp @@ -75,11 +75,40 @@ public: public slots: void connected(); void disconnected(); - void error(QAbstractSocket::SocketError error); void readyRead(); - void stateChanged(QAbstractSocket::SocketState state); }; +QString QmlDebugConnection::socketStateToString(QAbstractSocket::SocketState state) +{ + switch (state) { + case QAbstractSocket::UnconnectedState: + return tr("Network connection dropped"); + case QAbstractSocket::HostLookupState: + return tr("Resolving host"); + case QAbstractSocket::ConnectingState: + return tr("Establishing network connection ..."); + case QAbstractSocket::ConnectedState: + return tr("Network connection established"); + case QAbstractSocket::ClosingState: + return tr("Network connection closing"); + case QAbstractSocket::BoundState: + return tr("Socket state changed to BoundState. This should not happen!"); + case QAbstractSocket::ListeningState: + return tr("Socket state changed to ListeningState. This should not happen!"); + default: + return tr("Unknown state %1").arg(state); + } +} + +QString QmlDebugConnection::socketErrorToString(QAbstractSocket::SocketError error) +{ + if (error == QAbstractSocket::RemoteHostClosedError) { + return tr("Error: Remote host closed the connection"); + } else { + return tr("Error: Unknown socket error %1").arg(error); + } +} + QmlDebugConnectionPrivate::QmlDebugConnectionPrivate(QmlDebugConnection *c) : QObject(c), q(c), protocol(0), device(0), gotHello(false), currentDataStreamVersion(QDataStream::Qt_4_7), @@ -124,17 +153,6 @@ void QmlDebugConnectionPrivate::disconnected() } } -void QmlDebugConnectionPrivate::error(QAbstractSocket::SocketError socketError) -{ - //: %1=error code, %2=error message - emit q->errorMessage(tr("Error: (%1) %2").arg(socketError) - .arg(device ? device->errorString() : tr(""))); - if (socketError == QAbstractSocket::RemoteHostClosedError) - emit q->error(QDebugSupport::RemoteClosedConnectionError); - else - emit q->error(QDebugSupport::UnknownError); -} - void QmlDebugConnectionPrivate::readyRead() { if (!gotHello) { @@ -252,33 +270,6 @@ void QmlDebugConnectionPrivate::readyRead() } } -void QmlDebugConnectionPrivate::stateChanged(QAbstractSocket::SocketState state) -{ - switch (state) { - case QAbstractSocket::UnconnectedState: - emit q->stateMessage(tr("Network connection dropped")); - break; - case QAbstractSocket::HostLookupState: - emit q->stateMessage(tr("Resolving host")); - break; - case QAbstractSocket::ConnectingState: - emit q->stateMessage(tr("Establishing network connection ...")); - break; - case QAbstractSocket::ConnectedState: - emit q->stateMessage(tr("Network connection established")); - break; - case QAbstractSocket::ClosingState: - emit q->stateMessage(tr("Network connection closing")); - break; - case QAbstractSocket::BoundState: - emit q->errorMessage(tr("Socket state changed to BoundState. This should not happen!")); - break; - case QAbstractSocket::ListeningState: - emit q->errorMessage(tr("Socket state changed to ListeningState. This should not happen!")); - break; - } -} - QmlDebugConnection::QmlDebugConnection(QObject *parent) : QObject(parent), d(new QmlDebugConnectionPrivate(this)) { @@ -326,17 +317,14 @@ void QmlDebugConnectionPrivate::flush() void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) { d->disconnected(); - emit stateMessage(tr("Connecting to debug server at %1:%2 ...") - .arg(hostName).arg(QString::number(port))); QTcpSocket *socket = new QTcpSocket(d); socket->setProxy(QNetworkProxy::NoProxy); d->device = socket; d->protocol = new QPacketProtocol(d->device, this); connect(d->protocol, &QPacketProtocol::readyRead, d, &QmlDebugConnectionPrivate::readyRead); - connect(socket, &QAbstractSocket::stateChanged, - d, &QmlDebugConnectionPrivate::stateChanged); + connect(socket, &QAbstractSocket::stateChanged, this, &QmlDebugConnection::socketStateChanged); connect(socket, static_cast - (&QAbstractSocket::error), d, &QmlDebugConnectionPrivate::error); + (&QAbstractSocket::error), this, &QmlDebugConnection::socketError); connect(socket, &QAbstractSocket::connected, d, &QmlDebugConnectionPrivate::connected); connect(socket, &QAbstractSocket::disconnected, d, &QmlDebugConnectionPrivate::disconnected); socket->connectToHost(hostName, port); diff --git a/src/libs/qmldebug/qmldebugclient.h b/src/libs/qmldebug/qmldebugclient.h index 13d4d79ce1782a57655637f68120c836105d27e1..b87cc08b53e065468736aaac3ad48997b5b5816d 100644 --- a/src/libs/qmldebug/qmldebugclient.h +++ b/src/libs/qmldebug/qmldebugclient.h @@ -36,13 +36,6 @@ #include -namespace QDebugSupport { -enum Error { - RemoteClosedConnectionError, - UnknownError -}; -} - namespace QmlDebug { class QmlDebugConnectionPrivate; @@ -64,12 +57,14 @@ public: void close(); float serviceVersion(const QString &serviceName) const; + static QString socketStateToString(QAbstractSocket::SocketState state); + static QString socketErrorToString(QAbstractSocket::SocketError error); + signals: void connected(); void disconnected(); - void error(QDebugSupport::Error); - void stateMessage(const QString &message); - void errorMessage(const QString &message); + void socketError(QAbstractSocket::SocketError error); + void socketStateChanged(QAbstractSocket::SocketState state); private: friend class QmlDebugConnectionPrivate; diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index a8ac02e147545c521b05a1425b50735f5262b9bf..9d290e8c2c42ac4272aeb29b6bf5e30fc1e01c1b 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -291,11 +291,9 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin connect(&d->connectionTimer, &QTimer::timeout, this, &QmlEngine::checkConnectionState); - connect(d->connection, &QmlDebugConnection::stateMessage, - this, &QmlEngine::showConnectionStateMessage); - connect(d->connection, &QmlDebugConnection::errorMessage, - this, &QmlEngine::showConnectionErrorMessage); - connect(d->connection, &QmlDebugConnection::error, + connect(d->connection, &QmlDebugConnection::socketStateChanged, + this, &QmlEngine::connectionStateChanged); + connect(d->connection, &QmlDebugConnection::socketError, this, &QmlEngine::connectionErrorOccurred); connect(d->connection, &QmlDebugConnection::connected, &d->connectionTimer, &QTimer::stop); @@ -1213,11 +1211,11 @@ bool QmlEnginePrivate::canEvaluateScript(const QString &script) return interpreter.canEvaluate(); } -void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error) +void QmlEngine::connectionErrorOccurred(QAbstractSocket::SocketError error) { // this is only an error if we are already connected and something goes wrong. if (isConnected()) { - if (error == QDebugSupport::RemoteClosedConnectionError) + if (error == QAbstractSocket::RemoteHostClosedError) showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar); if (!isSlaveEngine()) { // normal flow for slave engine when gdb exits @@ -1230,6 +1228,11 @@ void QmlEngine::connectionErrorOccurred(QDebugSupport::Error error) } } +void QmlEngine::connectionStateChanged(QAbstractSocket::SocketState socketState) +{ + showConnectionStateMessage(QmlDebugConnection::socketStateToString(socketState)); +} + void QmlEngine::clientStateChanged(QmlDebugClient::State state) { QString serviceName; @@ -1260,11 +1263,6 @@ void QmlEngine::showConnectionStateMessage(const QString &message) showMessage(_("QML Debugger: ") + message, LogStatus); } -void QmlEngine::showConnectionErrorMessage(const QString &message) -{ - showMessage(_("QML Debugger: ") + message, LogError); -} - void QmlEngine::logServiceStateChange(const QString &service, float version, QmlDebugClient::State newState) { diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index 479dddb74630e957b895518c142c21a2cc211a9d..24942b8febe8bae9cc8cb3d0310d03cf3124b4a1 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -142,11 +141,12 @@ private: void startApplicationLauncher(); void stopApplicationLauncher(); - void connectionErrorOccurred(QDebugSupport::Error socketError); + void connectionErrorOccurred(QAbstractSocket::SocketError socketError); + void connectionStateChanged(QAbstractSocket::SocketState socketState); + void clientStateChanged(QmlDebug::QmlDebugClient::State state); void checkConnectionState(); void showConnectionStateMessage(const QString &message); - void showConnectionErrorMessage(const QString &message); bool isConnected() const; private: diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp index f104dda4e447f07fb15bc3029c864261e909f343..887ba0f3b749cae17b20766380ccd0a302a05670 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.cpp @@ -32,7 +32,6 @@ #include "qmlprofilertool.h" #include "qmlprofilerplugin.h" -#include #include #include @@ -132,16 +131,14 @@ void QmlProfilerClientManager::connectClient(quint16 port) d->connection = new QmlDebugConnection; enableServices(); - connect(d->connection, &QmlDebugConnection::stateMessage, - this, &QmlProfilerClientManager::logState); - connect(d->connection, &QmlDebugConnection::errorMessage, - this, &QmlProfilerClientManager::logState); connect(d->connection, &QmlDebugConnection::connected, this, &QmlProfilerClientManager::qmlDebugConnectionOpened); connect(d->connection, &QmlDebugConnection::disconnected, this, &QmlProfilerClientManager::qmlDebugConnectionClosed); - connect(d->connection, &QmlDebugConnection::error, + connect(d->connection, &QmlDebugConnection::socketError, this, &QmlProfilerClientManager::qmlDebugConnectionError); + connect(d->connection, &QmlDebugConnection::socketStateChanged, + this, &QmlProfilerClientManager::qmlDebugConnectionStateChanged); d->connectionTimer.start(); d->tcpPort = port; } @@ -273,9 +270,9 @@ void QmlProfilerClientManager::qmlDebugConnectionClosed() emit connectionClosed(); } -void QmlProfilerClientManager::qmlDebugConnectionError(QDebugSupport::Error error) +void QmlProfilerClientManager::qmlDebugConnectionError(QAbstractSocket::SocketError error) { - logState(tr("Debug connection error %1").arg(error)); + logState(QmlDebugConnection::socketErrorToString(error)); if (d->connection->isConnected()) { disconnectClient(); emit connectionClosed(); @@ -284,6 +281,11 @@ void QmlProfilerClientManager::qmlDebugConnectionError(QDebugSupport::Error erro } } +void QmlProfilerClientManager::qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state) +{ + logState(QmlDebugConnection::socketStateToString(state)); +} + void QmlProfilerClientManager::logState(const QString &msg) { QString state = QLatin1String("QML Profiler: ") + msg; diff --git a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h index 0cbf88dc565fbbc75c228ee1dd948855e9f7e19c..9eae3e0cad53ad0d9282cffabb98156d17cdd22d 100644 --- a/src/plugins/qmlprofiler/qmlprofilerclientmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerclientmanager.h @@ -33,10 +33,10 @@ #include "qmlprofilerstatemanager.h" #include -#include #include #include +#include namespace QmlProfiler { class QmlProfilerModelManager; @@ -72,7 +72,8 @@ private slots: void tryToConnect(); void qmlDebugConnectionOpened(); void qmlDebugConnectionClosed(); - void qmlDebugConnectionError(QDebugSupport::Error error); + void qmlDebugConnectionError(QAbstractSocket::SocketError error); + void qmlDebugConnectionStateChanged(QAbstractSocket::SocketState state); void logState(const QString &); void retryMessageBoxFinished(int result);