QmlDebug: Parse application output to track debugees state

Setting up the debugger connection might fail for a couple of reasons.
Check the application output to show the user a more detailed error
message.

Reviewed-by: hjk
This commit is contained in:
Kai Koehne
2011-02-21 17:01:40 +01:00
parent fa6fbcc83b
commit 1a3ed101cb
7 changed files with 102 additions and 9 deletions

View File

@@ -57,6 +57,7 @@
#include <utils/environment.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <QtCore/QDateTime>
@@ -216,7 +217,7 @@ void QmlEngine::setupInferior()
void QmlEngine::appendMessage(const QString &msg, OutputFormat /* format */)
{
showMessage(msg, AppStuff); // FIXME: Redirect to RunControl
showMessage(msg, AppOutput); // FIXME: Redirect to RunControl
}
void QmlEngine::connectionEstablished()
@@ -277,6 +278,70 @@ bool QmlEngine::canDisplayTooltip() const
return state() == InferiorRunOk || state() == InferiorStopOk;
}
void QmlEngine::filterApplicationMessage(const QString &msg, int /*channel*/)
{
static QString qddserver = QLatin1String("QDeclarativeDebugServer: ");
static QString cannotRetrieve = "Cannot retrieve debugging output!";
int index = msg.indexOf(qddserver);
if (index != -1) {
QString status = msg;
status.remove(0, index + qddserver.length()); // chop of 'QDeclarativeDebugServer: '
static QString waitingForConnection = QLatin1String("Waiting for connection on port");
static QString unableToListen = QLatin1String("Unable to listen on port");
static QString debuggingNotEnabled = QLatin1String("Ignoring \"-qmljsdebugger=port:");
static QString connectionEstablished = QLatin1String("Connection established");
QString errorMessage;
if (status.startsWith(waitingForConnection)) {
d->m_adapter.beginConnection();
} else if (status.startsWith(unableToListen)) {
errorMessage = tr("The port seems to be in use.");
} else if (status.startsWith(debuggingNotEnabled)) {
errorMessage = tr("The application isn't set up for QML/JS debugging.");
} else if (status.startsWith(connectionEstablished)) {
// nothing to do
} else {
qWarning() << "Unknown QDeclarativeDebugServer status message: " << status;
}
if (!errorMessage.isEmpty()) {
notifyEngineRunFailed();
Core::ICore * const core = Core::ICore::instance();
QMessageBox *infoBox = new QMessageBox(core->mainWindow());
infoBox->setIcon(QMessageBox::Critical);
infoBox->setWindowTitle(tr("Qt Creator"));
infoBox->setText(tr("Failed to connect to QML debugger\n\n"
"Qt Creator could not connect to the in-process debugger at %1:%2:\n"
"%3")
.arg(startParameters().qmlServerAddress)
.arg(startParameters().qmlServerPort)
.arg(errorMessage));
infoBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
infoBox->setDefaultButton(QMessageBox::Ok);
infoBox->setModal(true);
connect(infoBox, SIGNAL(finished(int)),
this, SLOT(messageBoxFinished(int)));
infoBox->show();
}
} else if (msg.contains(cannotRetrieve)) {
// we won't get debugging output, so just try to connect ...
d->m_adapter.beginConnection();
}
}
void QmlEngine::showMessage(const QString &msg, int channel, int timeout) const
{
if (channel == AppOutput || channel == AppError) {
const_cast<QmlEngine*>(this)->filterApplicationMessage(msg, channel);
}
DebuggerEngine::showMessage(msg, channel, timeout);
}
void QmlEngine::closeConnection()
{
disconnect(&d->m_adapter, SIGNAL(connectionStartupFailed()),
@@ -298,8 +363,6 @@ void QmlEngine::runEngine()
if (!isSlaveEngine())
startApplicationLauncher();
d->m_adapter.beginConnection();
}
void QmlEngine::startApplicationLauncher()
@@ -871,6 +934,15 @@ void QmlEngine::disconnected()
notifyInferiorExited();
}
void QmlEngine::messageBoxFinished(int result)
{
if (result == QMessageBox::Help) {
Core::HelpManager *helpManager = Core::HelpManager::instance();
helpManager->handleHelpRequest(
QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-debugging-qml.html"));
}
}
void QmlEngine::executeDebuggerCommand(const QString& command)
{
QByteArray reply;
@@ -959,7 +1031,7 @@ void QmlEngine::logMessage(LogDirection direction, const QString &message)
showMessage(msg, LogDebug);
}
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp,
QmlEngine *createQmlEngine(const DebuggerStartParameters &sp,
DebuggerEngine *masterEngine)
{
return new QmlEngine(sp, masterEngine);