qmlengine.cpp 22.3 KB
Newer Older
1 2 3 4 5 6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
30 31 32 33
**
**************************************************************************/

#include "qmlengine.h"
Lasse Holmstedt's avatar
Lasse Holmstedt committed
34
#include "qmladapter.h"
35

Friedemann Kleint's avatar
Friedemann Kleint committed
36
#include "debuggerstartparameters.h"
37
#include "debuggeractions.h"
38
#include "debuggerconstants.h"
hjk's avatar
hjk committed
39
#include "debuggercore.h"
40
#include "debuggerdialogs.h"
41
#include "debuggermainwindow.h"
hjk's avatar
hjk committed
42
#include "debuggerrunner.h"
43
#include "debuggerstringutils.h"
44
#include "debuggertooltipmanager.h"
45

46 47 48 49 50 51 52
#include "breakhandler.h"
#include "moduleshandler.h"
#include "registerhandler.h"
#include "stackhandler.h"
#include "watchhandler.h"
#include "watchutils.h"

Lasse Holmstedt's avatar
Lasse Holmstedt committed
53
#include <extensionsystem/pluginmanager.h>
54
#include <projectexplorer/applicationlauncher.h>
55

56
#include <utils/environment.h>
57
#include <utils/qtcassert.h>
58
#include <utils/fileinprojectfinder.h>
59

60
#include <coreplugin/icore.h>
61 62
#include <coreplugin/helpmanager.h>

63 64 65 66 67 68 69 70 71 72 73
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>

#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QToolTip>
74
#include <QtGui/QTextDocument>
75 76

#include <QtNetwork/QTcpSocket>
77 78
#include <QtNetwork/QHostAddress>

79 80 81 82 83 84 85 86
#define DEBUG_QML 1
#if DEBUG_QML
#   define SDEBUG(s) qDebug() << s
#else
#   define SDEBUG(s)
#endif
# define XSDEBUG(s) qDebug() << s

hjk's avatar
hjk committed
87 88
using namespace ProjectExplorer;

89 90 91
namespace Debugger {
namespace Internal {

92 93
class QmlEnginePrivate
{
94
public:
95 96
    explicit QmlEnginePrivate(QmlEngine *q);

97
private:
98
    friend class QmlEngine;
hjk's avatar
hjk committed
99 100
    QmlAdapter m_adapter;
    ApplicationLauncher m_applicationLauncher;
101
    Utils::FileInProjectFinder fileFinder;
102
    QTimer m_noDebugOutputTimer;
103 104
};

105
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *q)
106
    : m_adapter(q)
107 108
{}

109

110 111 112 113 114 115
///////////////////////////////////////////////////////////////////////
//
// QmlEngine
//
///////////////////////////////////////////////////////////////////////

116 117 118 119
QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters,
        DebuggerEngine *masterEngine)
  : DebuggerEngine(startParameters, masterEngine),
    d(new QmlEnginePrivate(this))
120
{
Friedemann Kleint's avatar
Friedemann Kleint committed
121
    setObjectName(QLatin1String("QmlEngine"));
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

    ExtensionSystem::PluginManager *pluginManager =
        ExtensionSystem::PluginManager::instance();
    pluginManager->addObject(this);

    connect(&d->m_adapter, SIGNAL(connectionError(QAbstractSocket::SocketError)),
        SLOT(connectionError(QAbstractSocket::SocketError)));
    connect(&d->m_adapter, SIGNAL(serviceConnectionError(QString)),
        SLOT(serviceConnectionError(QString)));
    connect(&d->m_adapter, SIGNAL(connected()),
        SLOT(connectionEstablished()));
    connect(&d->m_adapter, SIGNAL(connectionStartupFailed()),
        SLOT(connectionStartupFailed()));

    connect(&d->m_applicationLauncher,
        SIGNAL(processExited(int)),
        SLOT(disconnected()));
    connect(&d->m_applicationLauncher,
        SIGNAL(appendMessage(QString,Utils::OutputFormat)),
        SLOT(appendMessage(QString,Utils::OutputFormat)));
142 143 144 145 146 147

// Only wait 8 seconds for the 'Waiting for connection' on application ouput, then just try to connect
    // (application output might be redirected / blocked)
    d->m_noDebugOutputTimer.setSingleShot(true);
    d->m_noDebugOutputTimer.setInterval(8000);
    connect(&d->m_noDebugOutputTimer, SIGNAL(timeout()), this, SLOT(beginConnection()));
148 149 150
}

QmlEngine::~QmlEngine()
hjk's avatar
hjk committed
151
{
152 153 154 155 156 157
    ExtensionSystem::PluginManager *pluginManager =
        ExtensionSystem::PluginManager::instance();

    if (pluginManager->allObjects().contains(this)) {
        pluginManager->removeObject(this);
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
158

hjk's avatar
hjk committed
159 160
    delete d;
}
161

hjk's avatar
hjk committed
162
void QmlEngine::setupInferior()
163
{
hjk's avatar
hjk committed
164
    QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
Lasse Holmstedt's avatar
Lasse Holmstedt committed
165

166
    if (startParameters().startMode == AttachToRemote) {
167 168 169 170
        if (startParameters().qmlServerPort != quint16(-1))
            notifyInferiorSetupOk();
        else
            emit requestRemoteSetup();
171 172 173 174 175 176
    } else {
        d->m_applicationLauncher.setEnvironment(startParameters().environment);
        d->m_applicationLauncher.setWorkingDirectory(startParameters().workingDirectory);

        notifyInferiorSetupOk();
    }
hjk's avatar
hjk committed
177
}
hjk's avatar
hjk committed
178

con's avatar
con committed
179
void QmlEngine::appendMessage(const QString &msg, Utils::OutputFormat /* format */)
hjk's avatar
hjk committed
180
{
181
    showMessage(msg, AppOutput); // FIXME: Redirect to RunControl
hjk's avatar
hjk committed
182 183
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
184 185 186 187
void QmlEngine::connectionEstablished()
{
    attemptBreakpointSynchronization();

188
    showMessage(tr("QML Debugger connected."), StatusBar);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
189

190 191 192 193
    if (!watchHandler()->watcherNames().isEmpty()) {
        synchronizeWatchers();
    }
    connect(watchersModel(),SIGNAL(layoutChanged()),this,SLOT(synchronizeWatchers()));
Christiaan Janssen's avatar
Christiaan Janssen committed
194

Lasse Holmstedt's avatar
Lasse Holmstedt committed
195 196
    notifyEngineRunAndInferiorRunOk();
}
197

198 199 200 201
void QmlEngine::beginConnection()
{
    d->m_noDebugOutputTimer.stop();
    d->m_adapter.beginConnection();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
202 203 204 205
}

void QmlEngine::connectionStartupFailed()
{
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    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("Could not connect to the in-process QML debugger.\n"
                        "Do you want to retry?"));
    infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help);
    infoBox->setDefaultButton(QMessageBox::Retry);
    infoBox->setModal(true);

    connect(infoBox, SIGNAL(finished(int)),
            this, SLOT(retryMessageBoxFinished(int)));

    infoBox->show();
}

void QmlEngine::retryMessageBoxFinished(int result)
{
    switch (result) {
225
    case QMessageBox::Retry: {
226
        beginConnection();
227 228 229 230 231
        break;
    }
    case QMessageBox::Help: {
        Core::HelpManager *helpManager = Core::HelpManager::instance();
        helpManager->handleHelpRequest("qthelp://com.nokia.qtcreator/doc/creator-debugging-qml.html");
232
        // fall through
233 234 235
    }
    default:
        notifyEngineRunFailed();
Kai Koehne's avatar
Kai Koehne committed
236
        break;
237
    }
Lasse Holmstedt's avatar
Lasse Holmstedt committed
238 239
}

240
void QmlEngine::connectionError(QAbstractSocket::SocketError socketError)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
241
{
hjk's avatar
hjk committed
242
    if (socketError == QAbstractSocket::RemoteHostClosedError)
243
        showMessage(tr("QML Debugger: Remote host closed connection."), StatusBar);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
244 245
}

246 247
void QmlEngine::serviceConnectionError(const QString &serviceName)
{
248 249
    showMessage(tr("QML Debugger: Could not connect to service '%1'.")
        .arg(serviceName), StatusBar);
250 251
}

252 253 254 255 256
bool QmlEngine::canDisplayTooltip() const
{
    return state() == InferiorRunOk || state() == InferiorStopOk;
}

257 258
void QmlEngine::filterApplicationMessage(const QString &msg, int /*channel*/)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
259
    static const QString qddserver = QLatin1String("QDeclarativeDebugServer: ");
260
    static const QString cannotRetrieveDebuggingOutput = ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput();
261

262
    const int index = msg.indexOf(qddserver);
263
    if (index != -1) {
264 265 266
        // we're actually getting debug output
        d->m_noDebugOutputTimer.stop();

267 268 269
        QString status = msg;
        status.remove(0, index + qddserver.length()); // chop of 'QDeclarativeDebugServer: '

270 271 272
        static QString waitingForConnection = QLatin1String("Waiting for connection ");
        static QString unableToListen = QLatin1String("Unable to listen ");
        static QString debuggingNotEnabled = QLatin1String("Ignoring \"-qmljsdebugger=");
273
        static QString debuggingNotEnabled2 = QLatin1String("Ignoring\"-qmljsdebugger="); // There is (was?) a bug in one of the error strings - safest to handle both
274 275 276 277
        static QString connectionEstablished = QLatin1String("Connection established");

        QString errorMessage;
        if (status.startsWith(waitingForConnection)) {
278
            beginConnection();
279
        } else if (status.startsWith(unableToListen)) {
280
            //: Error message shown after 'Could not connect ... debugger:"
281
            errorMessage = tr("The port seems to be in use.");
282
        } else if (status.startsWith(debuggingNotEnabled) || status.startsWith(debuggingNotEnabled2)) {
283 284
            //: Error message shown after 'Could not connect ... debugger:"
            errorMessage = tr("The application is not set up for QML/JS debugging.");
285 286 287 288 289 290 291 292 293 294 295 296 297
        } 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"));
Friedemann Kleint's avatar
Friedemann Kleint committed
298 299
            //: %1 is detailed error message
            infoBox->setText(tr("Could not connect to the in-process QML debugger:\n%1")
300 301 302 303 304 305
                             .arg(errorMessage));
            infoBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
            infoBox->setDefaultButton(QMessageBox::Ok);
            infoBox->setModal(true);

            connect(infoBox, SIGNAL(finished(int)),
306
                    this, SLOT(wrongSetupMessageBoxFinished(int)));
307 308 309

            infoBox->show();
        }
Friedemann Kleint's avatar
Friedemann Kleint committed
310
    } else if (msg.contains(cannotRetrieveDebuggingOutput)) {
311
        // we won't get debugging output, so just try to connect ...
312
        beginConnection();
313 314 315 316 317 318 319 320 321 322 323
    }
}

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);
}

324 325 326 327 328
bool QmlEngine::acceptsWatchesWhileRunning() const
{
    return true;
}

329 330
void QmlEngine::closeConnection()
{
331
    disconnect(watchersModel(),SIGNAL(layoutChanged()),this,SLOT(synchronizeWatchers()));
332
    d->m_adapter.closeConnection();
333 334
}

hjk's avatar
hjk committed
335 336 337
void QmlEngine::runEngine()
{
    QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
Lasse Holmstedt's avatar
Lasse Holmstedt committed
338

339
    if (!isSlaveEngine() && startParameters().startMode != AttachToRemote)
340
        startApplicationLauncher();
341
    d->m_noDebugOutputTimer.start();
342 343 344 345 346
}

void QmlEngine::startApplicationLauncher()
{
    if (!d->m_applicationLauncher.isRunning()) {
347 348 349 350
        appendMessage(tr("Starting %1 %2").arg(
                          QDir::toNativeSeparators(startParameters().executable),
                          startParameters().processArgs)
                      + QLatin1Char('\n')
con's avatar
con committed
351
                     , Utils::NormalMessageFormat);
hjk's avatar
hjk committed
352
        d->m_applicationLauncher.start(ApplicationLauncher::Gui,
353 354 355
                                    startParameters().executable,
                                    startParameters().processArgs);
    }
356
}
Lasse Holmstedt's avatar
Lasse Holmstedt committed
357

358 359 360 361 362 363
void QmlEngine::stopApplicationLauncher()
{
    if (d->m_applicationLauncher.isRunning()) {
        disconnect(&d->m_applicationLauncher, SIGNAL(processExited(int)), this, SLOT(disconnected()));
        d->m_applicationLauncher.stop();
    }
364 365
}

Christian Kandeler's avatar
Christian Kandeler committed
366
void QmlEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
367
{
Christian Kandeler's avatar
Christian Kandeler committed
368 369 370
    Q_UNUSED(gdbServerPort);
    if (qmlPort != -1)
        startParameters().qmlServerPort = qmlPort;
371 372 373 374 375 376 377 378 379 380
    notifyInferiorSetupOk();
}

void QmlEngine::handleRemoteSetupFailed(const QString &message)
{
    QMessageBox::critical(0,tr("Failed to start application"),
        tr("Application startup failed: %1").arg(message));
    notifyInferiorSetupFailed();
}

hjk's avatar
hjk committed
381
void QmlEngine::shutdownInferior()
382
{
383 384
    if (isSlaveEngine()) {
        resetLocation();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
385
    }
386
    stopApplicationLauncher();
hjk's avatar
hjk committed
387 388 389 390 391
    notifyInferiorShutdownOk();
}

void QmlEngine::shutdownEngine()
{
392
    closeConnection();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
393

394 395
    // double check (ill engine?):
    stopApplicationLauncher();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
396

397
    notifyEngineShutdownOk();
398 399
    if (!isSlaveEngine())
        showMessage(QString(), StatusBar);
400 401
}

hjk's avatar
hjk committed
402
void QmlEngine::setupEngine()
403
{
404 405 406
    connect(&d->m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
            runControl(), SLOT(bringApplicationToForeground(qint64)),
            Qt::UniqueConnection);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
407

408
    notifyEngineSetupOk();
409 410
}

411 412
void QmlEngine::continueInferior()
{
hjk's avatar
hjk committed
413
    QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
414 415
    logMessage(LogSend, "CONTINUE");
    d->m_adapter.activeDebuggerClient()->continueInferior();
416
    resetLocation();
hjk's avatar
hjk committed
417 418
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
419 420 421 422
}

void QmlEngine::interruptInferior()
{
423 424 425
    logMessage(LogSend, "INTERRUPT");
    d->m_adapter.activeDebuggerClient()->interruptInferior();

426 427 428 429
}

void QmlEngine::executeStep()
{
430 431
    logMessage(LogSend, "STEPINTO");
    d->m_adapter.activeDebuggerClient()->executeStep();
432
    resetLocation();
hjk's avatar
hjk committed
433 434
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
435 436 437 438
}

void QmlEngine::executeStepI()
{
439 440
    logMessage(LogSend, "STEPINTO");
    d->m_adapter.activeDebuggerClient()->executeStepI();
441
    resetLocation();
hjk's avatar
hjk committed
442 443
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
444 445 446 447
}

void QmlEngine::executeStepOut()
{
448 449
    logMessage(LogSend, "STEPOUT");
    d->m_adapter.activeDebuggerClient()->executeStepOut();
450
    resetLocation();
hjk's avatar
hjk committed
451 452
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
453 454 455 456
}

void QmlEngine::executeNext()
{
457 458
    logMessage(LogSend, "STEPOVER");
    d->m_adapter.activeDebuggerClient()->executeNext();
459
    resetLocation();
hjk's avatar
hjk committed
460 461
    notifyInferiorRunRequested();
    notifyInferiorRunOk();
462 463 464 465
}

void QmlEngine::executeNextI()
{
466
    SDEBUG("QmlEngine::executeNextI()");
467 468
}

469
void QmlEngine::executeRunToLine(const ContextData &data)
470
{
471
    Q_UNUSED(data)
472 473 474 475 476 477 478 479 480
    SDEBUG("FIXME:  QmlEngine::executeRunToLine()");
}

void QmlEngine::executeRunToFunction(const QString &functionName)
{
    Q_UNUSED(functionName)
    XSDEBUG("FIXME:  QmlEngine::executeRunToFunction()");
}

481
void QmlEngine::executeJumpToLine(const ContextData &data)
482
{
483
    Q_UNUSED(data)
484 485 486 487 488
    XSDEBUG("FIXME:  QmlEngine::executeJumpToLine()");
}

void QmlEngine::activateFrame(int index)
{
489 490
    logMessage(LogSend, QString("%1 %2").arg(QString("ACTIVATE_FRAME"), QString::number(index)));
    d->m_adapter.activeDebuggerClient()->activateFrame(index);
491
    gotoLocation(stackHandler()->frames().value(index));
492 493 494 495 496 497 498 499 500
}

void QmlEngine::selectThread(int index)
{
    Q_UNUSED(index)
}

void QmlEngine::attemptBreakpointSynchronization()
{
hjk's avatar
hjk committed
501
    BreakHandler *handler = breakHandler();
502

503
    foreach (BreakpointModelId id, handler->unclaimedBreakpointIds()) {
504 505 506 507 508
        // Take ownership of the breakpoint. Requests insertion.
        if (acceptsBreakpoint(id))
            handler->setEngine(id, this);
    }

509
    QStringList breakPointsStr;
510
    foreach (BreakpointModelId id, handler->engineBreakpointIds(this)) {
511 512
        if (handler->state(id) == BreakpointRemoveRequested) {
            handler->notifyBreakpointRemoveProceeding(id);
513 514 515 516 517 518 519
            if (d->m_adapter.activeDebuggerClient())
                d->m_adapter.activeDebuggerClient()->removeBreakpoints(&id);
            else {
                foreach (QmlDebuggerClient *client, d->m_adapter.debuggerClients()) {
                    client->removeBreakpoints(&id);
                }
            }
520 521 522 523 524
            handler->notifyBreakpointRemoveOk(id);
        } else {
            if (handler->state(id) == BreakpointInsertRequested) {
                handler->notifyBreakpointInsertProceeding(id);
            }
525 526 527 528 529 530 531
            if (d->m_adapter.activeDebuggerClient())
                d->m_adapter.activeDebuggerClient()->insertBreakpoints(handler,&id);
            else {
                foreach (QmlDebuggerClient *client, d->m_adapter.debuggerClients()) {
                    client->insertBreakpoints(handler,&id);
                }
            }
532 533 534
            if (handler->state(id) == BreakpointInsertProceeding) {
                handler->notifyBreakpointInsertOk(id);
            }
535 536
            breakPointsStr << QString("('%1' '%2' %3)").arg(QString(handler->functionName(id).toUtf8()),
                                      QString(QUrl::fromLocalFile(handler->fileName(id)).toString().toUtf8()), QString::number(handler->lineNumber(id)));
537
        }
538 539
    }

540
    logMessage(LogSend, QString("%1 [%2]").arg(QString("BREAKPOINTS"), breakPointsStr.join(", ")));
541

542 543 544 545 546 547
    if (d->m_adapter.activeDebuggerClient()) {
        d->m_adapter.activeDebuggerClient()->setBreakpoints();
    }
    else {
        foreach (QmlDebuggerClient *client, d->m_adapter.debuggerClients())
            client->setBreakpoints();
548
    }
549 550
}

551
bool QmlEngine::acceptsBreakpoint(BreakpointModelId id) const
552
{
553
    return !DebuggerEngine::isCppBreakpoint(breakHandler()->breakpointData(id));
554 555
}

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
void QmlEngine::loadSymbols(const QString &moduleName)
{
    Q_UNUSED(moduleName)
}

void QmlEngine::loadAllSymbols()
{
}

void QmlEngine::reloadModules()
{
}

void QmlEngine::requestModuleSymbols(const QString &moduleName)
{
    Q_UNUSED(moduleName)
}

//////////////////////////////////////////////////////////////////////
//
// Tooltip specific stuff
//
//////////////////////////////////////////////////////////////////////

580
bool QmlEngine::setToolTipExpression(const QPoint &mousePos,
581
    TextEditor::ITextEditor *editor, const DebuggerToolTipContext &ctx)
582
{
hjk's avatar
hjk committed
583 584
    // This is processed by QML inspector, which has dependencies to 
    // the qml js editor. Makes life easier.
585
    emit tooltipRequested(mousePos, editor, ctx.position);
586
    return true;
587 588 589 590 591 592 593 594
}

//////////////////////////////////////////////////////////////////////
//
// Watch specific stuff
//
//////////////////////////////////////////////////////////////////////

595
void QmlEngine::assignValueInDebugger(const WatchData *data,
hjk's avatar
hjk committed
596
    const QString &expression, const QVariant &valueV)
597
{
598 599 600 601 602 603
    quint64 objectId =  data->id;
    if (objectId > 0 && !expression.isEmpty()) {
        logMessage(LogSend, QString("%1 %2 %3 %4 %5").arg(
                             QString("SET_PROPERTY"), QString::number(objectId), QString(expression),
                             valueV.toString()));
        d->m_adapter.activeDebuggerClient()->assignValueInDebugger(expression.toUtf8(), objectId, expression, valueV.toString());
604
    }
605 606
}

hjk's avatar
hjk committed
607 608
void QmlEngine::updateWatchData(const WatchData &data,
    const WatchUpdateFlags &)
609
{
Olivier Goffart's avatar
Olivier Goffart committed
610
//    qDebug() << "UPDATE WATCH DATA" << data.toString();
611
    //watchHandler()->rebuildModel();
612
    showStatusMessage(tr("Stopped."), 5000);
613

614
    if (!data.name.isEmpty() && data.isValueNeeded()) {
615
        logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString(data.iname),
616
                                                          QString(data.name)));
617
         d->m_adapter.activeDebuggerClient()->updateWatchData(&data);
618 619
    }

620
    if (!data.name.isEmpty() && data.isChildrenNeeded()
Christiaan Janssen's avatar
Christiaan Janssen committed
621
            && watchHandler()->isExpandedIName(data.iname)) {
622
        d->m_adapter.activeDebuggerClient()->expandObject(data.iname, data.id);
Christiaan Janssen's avatar
Christiaan Janssen committed
623 624 625
    }

    synchronizeWatchers();
626

Christiaan Janssen's avatar
Christiaan Janssen committed
627 628 629 630 631 632
    if (!data.isSomethingNeeded())
        watchHandler()->insertData(data);
}

void QmlEngine::synchronizeWatchers()
{
633
    QStringList watchedExpressions = watchHandler()->watchedExpressions();
634 635
    // send watchers list
    logMessage(LogSend, QString("%1 %2").arg(
636 637 638 639 640 641 642 643
                   QString("WATCH_EXPRESSIONS"), watchedExpressions.join(", ")));
    if (d->m_adapter.activeDebuggerClient()) {
        d->m_adapter.activeDebuggerClient()->synchronizeWatchers(watchedExpressions);
    }
    else {
        foreach (QmlDebuggerClient *client, d->m_adapter.debuggerClients())
            client->synchronizeWatchers(watchedExpressions);
    }
644 645
}

646 647 648 649 650 651 652 653 654 655 656 657
unsigned QmlEngine::debuggerCapabilities() const
{
    return AddWatcherCapability;
    /*ReverseSteppingCapability | SnapshotCapability
        | AutoDerefPointersCapability | DisassemblerCapability
        | RegisterCapability | ShowMemoryCapability
        | JumpToLineCapability | ReloadModuleCapability
        | ReloadModuleSymbolsCapability | BreakOnThrowAndCatchCapability
        | ReturnFromFunctionCapability
        | CreateFullBacktraceCapability
        | WatchpointCapability
        | AddWatcherCapability;*/
658 659
}

660
QString QmlEngine::toFileInProject(const QUrl &fileUrl)
661
{
662 663 664
    if (d->fileFinder.projectDirectory().isEmpty()) {
        d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
        d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
665 666
    }

667
    return d->fileFinder.findFile(fileUrl);
668 669
}

670
void QmlEngine::inferiorSpontaneousStop()
671
{
672 673 674 675
    if (state() == InferiorRunOk)
        notifyInferiorSpontaneousStop();
    else
        notifyInferiorStopOk();
676 677
}

678 679
void QmlEngine::disconnected()
{
680
    showMessage(tr("QML Debugger disconnected."), StatusBar);
681 682 683
    notifyInferiorExited();
}

684
void QmlEngine::wrongSetupMessageBoxFinished(int result)
685 686 687 688 689 690 691 692
{
    if (result == QMessageBox::Help) {
        Core::HelpManager *helpManager = Core::HelpManager::instance();
        helpManager->handleHelpRequest(
                    QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-debugging-qml.html"));
    }
}

693 694
void QmlEngine::executeDebuggerCommand(const QString& command)
{
695
    logMessage(LogSend, QString("%1 %2 %3").arg(QString("EXEC"), QString("console"),
696
                                                      QString(command)));
697
    d->m_adapter.activeDebuggerClient()->executeDebuggerCommand(command);
698 699
}

700 701 702

QString QmlEngine::qmlImportPath() const
{
703
    return startParameters().environment.value("QML_IMPORT_PATH");
704 705
}

706 707
void QmlEngine::logMessage(LogDirection direction, const QString &message)
{
708
    QString msg = "QmlDebugger";
709 710 711 712 713 714 715 716 717
    if (direction == LogSend) {
        msg += " sending ";
    } else {
        msg += " receiving ";
    }
    msg += message;
    showMessage(msg, LogDebug);
}

718
QmlEngine *createQmlEngine(const DebuggerStartParameters &sp,
719 720 721 722 723
    DebuggerEngine *masterEngine)
{
    return new QmlEngine(sp, masterEngine);
}

724
} // namespace Internal
725
} // namespace Debugger
726