qmljsclientproxy.cpp 18.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
29

30
#include "qmljsclientproxy.h"
31
#include "qmljsprivateapi.h"
32
#include "qmljsobserverclient.h"
33
#include "qmljsinspector.h"
34

35
36
37
#include <debugger/debuggerplugin.h>
#include <debugger/debuggerrunner.h>
#include <debugger/qml/qmlengine.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
38
#include <debugger/qml/qmladapter.h>
39
#include <extensionsystem/pluginmanager.h>
40
#include <utils/qtcassert.h>
41
#include <projectexplorer/project.h>
42
43
44
45
46

#include <QUrl>
#include <QAbstractSocket>
#include <QDebug>

47
48
49
50
enum {
    debug = false
};

51
52
using namespace QmlJSInspector::Internal;

53
ClientProxy::ClientProxy(Debugger::QmlAdapter *adapter, QObject *parent)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
54
55
    : QObject(parent)
    , m_adapter(adapter)
Kai Koehne's avatar
Kai Koehne committed
56
57
    , m_engineClient(m_adapter->client())
    , m_observerClient(0)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
58
59
    , m_engineQuery(0)
    , m_contextQuery(0)
60
    , m_isConnected(false)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
61
{
62
63
    m_requestObjectsTimer.setSingleShot(true);
    m_requestObjectsTimer.setInterval(3000);
Kai Koehne's avatar
Kai Koehne committed
64
    connect(m_engineClient, SIGNAL(newObjects()), this, SLOT(newObjects()));
65
    connect(&m_requestObjectsTimer, SIGNAL(timeout()), this, SLOT(refreshObjectTree()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
66
67
68
69
70
    connectToServer();
}

void ClientProxy::connectToServer()
{
Kai Koehne's avatar
Kai Koehne committed
71
    m_observerClient = new QmlJSObserverClient(m_adapter->connection(), this);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
72

73

Kai Koehne's avatar
Kai Koehne committed
74
    m_adapter->logServiceStatusChange(m_observerClient->name(), m_observerClient->status());
75

Kai Koehne's avatar
Kai Koehne committed
76
    connect(m_observerClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)),
77
             this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
Kai Koehne's avatar
Kai Koehne committed
78
    connect(m_observerClient, SIGNAL(currentObjectsChanged(QList<int>)),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
79
        SLOT(onCurrentObjectsChanged(QList<int>)));
Kai Koehne's avatar
Kai Koehne committed
80
    connect(m_observerClient, SIGNAL(colorPickerActivated()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
81
        SIGNAL(colorPickerActivated()));
Kai Koehne's avatar
Kai Koehne committed
82
    connect(m_observerClient, SIGNAL(zoomToolActivated()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
83
        SIGNAL(zoomToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
84
    connect(m_observerClient, SIGNAL(selectToolActivated()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
85
        SIGNAL(selectToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
86
    connect(m_observerClient, SIGNAL(selectMarqueeToolActivated()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
87
        SIGNAL(selectMarqueeToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
88
    connect(m_observerClient, SIGNAL(animationSpeedChanged(qreal)),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
89
        SIGNAL(animationSpeedChanged(qreal)));
Kai Koehne's avatar
Kai Koehne committed
90
    connect(m_observerClient, SIGNAL(designModeBehaviorChanged(bool)),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
91
        SIGNAL(designModeBehaviorChanged(bool)));
92
93
    connect(m_observerClient, SIGNAL(showAppOnTopChanged(bool)),
        SIGNAL(showAppOnTopChanged(bool)));
Kai Koehne's avatar
Kai Koehne committed
94
    connect(m_observerClient, SIGNAL(reloaded()), this,
Lasse Holmstedt's avatar
Lasse Holmstedt committed
95
        SIGNAL(serverReloaded()));
Kai Koehne's avatar
Kai Koehne committed
96
    connect(m_observerClient, SIGNAL(selectedColorChanged(QColor)),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
97
        SIGNAL(selectedColorChanged(QColor)));
Kai Koehne's avatar
Kai Koehne committed
98
    connect(m_observerClient, SIGNAL(contextPathUpdated(QStringList)),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
99
        SIGNAL(contextPathUpdated(QStringList)));
100
101

    updateConnected();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
102
103
}

104
105
106
107
108
109
110
111
112
void ClientProxy::clientStatusChanged(QDeclarativeDebugClient::Status status)
{
    QString serviceName;
    if (QDeclarativeDebugClient *client = qobject_cast<QDeclarativeDebugClient*>(sender())) {
        serviceName = client->name();
    }

    m_adapter->logServiceStatusChange(serviceName, status);

113
    updateConnected();
114
115
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
116
void ClientProxy::disconnectFromServer()
117
{
Kai Koehne's avatar
Kai Koehne committed
118
119
    if (m_observerClient) {
        disconnect(m_observerClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)),
120
                 this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
Kai Koehne's avatar
Kai Koehne committed
121
        disconnect(m_observerClient, SIGNAL(currentObjectsChanged(QList<int>)),
hjk's avatar
hjk committed
122
            this, SLOT(onCurrentObjectsChanged(QList<int>)));
Kai Koehne's avatar
Kai Koehne committed
123
        disconnect(m_observerClient, SIGNAL(colorPickerActivated()),
hjk's avatar
hjk committed
124
            this, SIGNAL(colorPickerActivated()));
Kai Koehne's avatar
Kai Koehne committed
125
        disconnect(m_observerClient, SIGNAL(zoomToolActivated()),
hjk's avatar
hjk committed
126
            this, SIGNAL(zoomToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
127
        disconnect(m_observerClient, SIGNAL(selectToolActivated()),
hjk's avatar
hjk committed
128
            this, SIGNAL(selectToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
129
        disconnect(m_observerClient, SIGNAL(selectMarqueeToolActivated()),
hjk's avatar
hjk committed
130
            this, SIGNAL(selectMarqueeToolActivated()));
Kai Koehne's avatar
Kai Koehne committed
131
        disconnect(m_observerClient, SIGNAL(animationSpeedChanged(qreal)),
hjk's avatar
hjk committed
132
            this, SIGNAL(animationSpeedChanged(qreal)));
Kai Koehne's avatar
Kai Koehne committed
133
        disconnect(m_observerClient, SIGNAL(designModeBehaviorChanged(bool)),
hjk's avatar
hjk committed
134
            this, SIGNAL(designModeBehaviorChanged(bool)));
Kai Koehne's avatar
Kai Koehne committed
135
        disconnect(m_observerClient, SIGNAL(selectedColorChanged(QColor)),
hjk's avatar
hjk committed
136
            this, SIGNAL(selectedColorChanged(QColor)));
Kai Koehne's avatar
Kai Koehne committed
137
        disconnect(m_observerClient, SIGNAL(contextPathUpdated(QStringList)),
hjk's avatar
hjk committed
138
            this, SIGNAL(contextPathUpdated(QStringList)));
139

Kai Koehne's avatar
Kai Koehne committed
140
141
        delete m_observerClient;
        m_observerClient = 0;
142
143
    }

Lasse Holmstedt's avatar
Lasse Holmstedt committed
144
145
146
    if (m_engineQuery)
        delete m_engineQuery;
    m_engineQuery = 0;
147

Lasse Holmstedt's avatar
Lasse Holmstedt committed
148
149
150
    if (m_contextQuery)
        delete m_contextQuery;
    m_contextQuery = 0;
151

152
153
    qDeleteAll(m_objectTreeQuery);
    m_objectTreeQuery.clear();
154
155

    updateConnected();
156
157
}

158
159
void ClientProxy::refreshObjectTree()
{
160
    if (!m_contextQuery) {
161
        m_requestObjectsTimer.stop();
162
163
164
        qDeleteAll(m_objectTreeQuery);
        m_objectTreeQuery.clear();
        queryEngineContext(m_engines.value(0).debugId());
165
166
167
    }
}

Kai Koehne's avatar
Kai Koehne committed
168
void ClientProxy::onCurrentObjectsChanged(const QList<int> &debugIds, bool requestIfNeeded)
169
170
171
{
    QList<QDeclarativeDebugObjectReference> selectedItems;

hjk's avatar
hjk committed
172
    foreach (int debugId, debugIds) {
173
174
175
        QDeclarativeDebugObjectReference ref = objectReferenceForId(debugId);
        if (ref.debugId() != -1) {
            selectedItems << ref;
176
        } else if (requestIfNeeded) {
177
            // ### FIXME right now, there's no way in the protocol to
hjk's avatar
hjk committed
178
179
            // a) get some item and know its parent (although that's possible
            //    by adding it to a separate plugin)
180
            // b) add children to part of an existing tree.
hjk's avatar
hjk committed
181
182
            // So the only choice that remains is to update the complete
            // tree when we have an unknown debug id.
183
            // break;
184
185
186
        }
    }

187
    emit selectedItemsChanged(selectedItems);
188
189
}

190
191
void ClientProxy::setSelectedItemsByObjectId(const QList<QDeclarativeDebugObjectReference> &objectRefs)
{
Kai Koehne's avatar
Kai Koehne committed
192
193
194
195
196
197
198
    if (isConnected()) {
        QList<int> debugIds;

        foreach (const QDeclarativeDebugObjectReference &ref, objectRefs) {
            debugIds << ref.debugId();
        }

Kai Koehne's avatar
Kai Koehne committed
199
        m_observerClient->setCurrentObjects(debugIds);
Kai Koehne's avatar
Kai Koehne committed
200
    }
201
202
203
204
}

QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(int debugId) const
{
205
206
207
208
209
210
    foreach (const QDeclarativeDebugObjectReference& it, m_rootObjects) {
        QDeclarativeDebugObjectReference result = objectReferenceForId(debugId, it);
        if (result.debugId() == debugId)
            return result;
    }
    return QDeclarativeDebugObjectReference();
211
212
}

213
QList<QDeclarativeDebugObjectReference> QmlJSInspector::Internal::ClientProxy::rootObjectReference() const
214
{
215
    return m_rootObjects;
216
217
}

218
219
QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(int debugId,
                                                                   const QDeclarativeDebugObjectReference &objectRef) const
220
{
221
222
223
224
225
226
227
228
229
230
    if (objectRef.debugId() == debugId)
        return objectRef;

    foreach(const QDeclarativeDebugObjectReference &child, objectRef.children()) {
        QDeclarativeDebugObjectReference result = objectReferenceForId(debugId, child);
        if (result.debugId() == debugId)
            return result;
    }

    return QDeclarativeDebugObjectReference();
231
232
}

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(const QString &objectId) const
{
    if (!objectId.isEmpty() && objectId[0].isLower()) {
        const QList<QDeclarativeDebugObjectReference> refs = objectReferences();
        foreach (const QDeclarativeDebugObjectReference &ref, refs) {
            if (ref.idString() == objectId)
                return ref;
        }
    }
    return QDeclarativeDebugObjectReference();
}

QDeclarativeDebugObjectReference ClientProxy::objectReferenceForLocation(const int line, const int column) const
{
    const QList<QDeclarativeDebugObjectReference> refs = objectReferences();
    foreach (const QDeclarativeDebugObjectReference &ref, refs) {
        if (ref.source().lineNumber() == line && ref.source().columnNumber() == column)
            return ref;
    }

    return QDeclarativeDebugObjectReference();
}

256
QList<QDeclarativeDebugObjectReference> ClientProxy::objectReferences() const
257
{
258
259
    QList<QDeclarativeDebugObjectReference> result;
    foreach(const QDeclarativeDebugObjectReference &it, m_rootObjects) {
260
        result.append(objectReferences(it));
261
262
    }
    return result;
263
264
}

265
QList<QDeclarativeDebugObjectReference> ClientProxy::objectReferences(const QDeclarativeDebugObjectReference &objectRef) const
266
267
{
    QList<QDeclarativeDebugObjectReference> result;
268
    result.append(objectRef);
269
270

    foreach(const QDeclarativeDebugObjectReference &child, objectRef.children()) {
271
        result.append(objectReferences(child));
272
273
274
275
276
    }

    return result;
}

Roberto Raggi's avatar
Roberto Raggi committed
277
278
279
280
bool ClientProxy::setBindingForObject(int objectDebugId,
                                      const QString &propertyName,
                                      const QVariant &value,
                                      bool isLiteralValue)
281
{
282
283
    if (debug)
        qDebug() << "setBindingForObject():" << objectDebugId << propertyName << value;
284
    if (objectDebugId == -1)
285
286
        return false;

287
288
    if (propertyName == QLatin1String("id"))
        return false; // Crashes the QMLViewer.
289

Kai Koehne's avatar
Kai Koehne committed
290
    bool result = m_engineClient->setBindingForObject(objectDebugId, propertyName, value.toString(), isLiteralValue);
291
292

    return result;
293
294
}

295
296
bool ClientProxy::setMethodBodyForObject(int objectDebugId, const QString &methodName, const QString &methodBody)
{
297
298
    if (debug)
        qDebug() << "setMethodBodyForObject():" << objectDebugId << methodName << methodBody;
299
300
    if (objectDebugId == -1)
        return 0;
Kai Koehne's avatar
Kai Koehne committed
301
    return m_engineClient->setMethodBody(objectDebugId, methodName, methodBody);
302
303
}

304
305
bool ClientProxy::resetBindingForObject(int objectDebugId, const QString& propertyName)
{
306
307
    if (debug)
        qDebug() << "resetBindingForObject():" << objectDebugId << propertyName;
308
309
310
    if (objectDebugId == -1)
        return false;
    //    if (propertyName == QLatin1String("id"))  return false;
Kai Koehne's avatar
Kai Koehne committed
311
    return m_engineClient->resetBindingForObject(objectDebugId, propertyName);
312
313
}

314
315
QDeclarativeDebugExpressionQuery *ClientProxy::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
{
316
317
    if (debug)
        qDebug() << "queryExpressionResult():" << objectDebugId << expr << parent;
318
    if (objectDebugId != -1)
Kai Koehne's avatar
Kai Koehne committed
319
        return m_engineClient->queryExpressionResult(objectDebugId,expr,parent);
320
321
322
    return 0;
}

323
324
void ClientProxy::clearComponentCache()
{
325
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
326
        m_observerClient->clearComponentCache();
327
}
328

329
330
331
332
333
334
335
336
337
338
void ClientProxy::queryEngineContext(int id)
{
    if (id < 0)
        return;

    if (m_contextQuery) {
        delete m_contextQuery;
        m_contextQuery = 0;
    }

Kai Koehne's avatar
Kai Koehne committed
339
    m_contextQuery = m_engineClient->queryRootContexts(QDeclarativeDebugEngineReference(id), this);
340
341
342
    if (!m_contextQuery->isWaiting())
        contextChanged();
    else
Roberto Raggi's avatar
Roberto Raggi committed
343
344
        connect(m_contextQuery, SIGNAL(stateChanged(QDeclarativeDebugQuery::State)),
                this, SLOT(contextChanged()));
345
346
347
348
349
}

void ClientProxy::contextChanged()
{
    if (m_contextQuery) {
350
351
        m_rootObjects.clear();
        QDeclarativeDebugContextReference rootContext = m_contextQuery->rootContext();
Roberto Raggi's avatar
Roberto Raggi committed
352
353
        delete m_contextQuery;
        m_contextQuery = 0;
354

355
356
        qDeleteAll(m_objectTreeQuery);
        m_objectTreeQuery.clear();
357
        m_requestObjectsTimer.stop();
358

359
        fetchContextObjectRecursive(rootContext);
360
    }
361
}
362

363
void ClientProxy::fetchContextObjectRecursive(const QDeclarativeDebugContextReference& context)
364
365
{
    foreach (const QDeclarativeDebugObjectReference & obj, context.objects()) {
Kai Koehne's avatar
Kai Koehne committed
366
        QDeclarativeDebugObjectQuery* query = m_engineClient->queryObjectRecursive(obj, this);
367
368
369
370
371
372
373
374
375
376
        if (!query->isWaiting()) {
            query->deleteLater(); //ignore errors;
        } else {
            m_objectTreeQuery << query;
            connect(query,
                    SIGNAL(stateChanged(QDeclarativeDebugQuery::State)),
                    SLOT(objectTreeFetched(QDeclarativeDebugQuery::State)));
        }
    }
    foreach (const QDeclarativeDebugContextReference& child, context.contexts()) {
377
        fetchContextObjectRecursive(child);
378
    }
379
380
}

381

382
383
void ClientProxy::objectTreeFetched(QDeclarativeDebugQuery::State state)
{
384
385
386
    QDeclarativeDebugObjectQuery *query = qobject_cast<QDeclarativeDebugObjectQuery *>(sender());
    if (!query || state == QDeclarativeDebugQuery::Error) {
        delete query;
387
388
389
        return;
    }

390
    m_rootObjects.append(query->object());
391

392
393
394
395
    int removed = m_objectTreeQuery.removeAll(query);
    Q_ASSERT(removed == 1);
    Q_UNUSED(removed);
    delete query;
396

397
    if (m_objectTreeQuery.isEmpty()) {
398
399
400
401
402
        int old_count = m_debugIdHash.count();
        m_debugIdHash.clear();
        m_debugIdHash.reserve(old_count + 1);
        foreach(const QDeclarativeDebugObjectReference &it, m_rootObjects)
            buildDebugIdHashRecursive(it);
403
        emit objectTreeUpdated();
404

405
        if (isConnected()) {
Kai Koehne's avatar
Kai Koehne committed
406
407
            if (!m_observerClient->currentObjects().isEmpty())
                onCurrentObjectsChanged(m_observerClient->currentObjects(), false);
408

Kai Koehne's avatar
Kai Koehne committed
409
            m_observerClient->setObjectIdList(m_rootObjects);
410
        }
411
    }
412
413
}

414
415
416
417
418
419
void ClientProxy::buildDebugIdHashRecursive(const QDeclarativeDebugObjectReference& ref)
{
    QString filename = ref.source().url().toLocalFile();
    int lineNum = ref.source().lineNumber();
    int colNum = ref.source().columnNumber();
    int rev = 0;
420
421

    // handle the case where the url contains the revision number encoded. (for object created by the debugger)
422
    static QRegExp rx("(.*)_(\\d+):(\\d+)$");
423
424
425
426
427
428
    if (rx.exactMatch(filename)) {
        filename = rx.cap(1);
        rev = rx.cap(2).toInt();
        lineNum += rx.cap(3).toInt() - 1;
    }

Olivier Goffart's avatar
Olivier Goffart committed
429
    //convert the filename to a canonical filename in case of shadow build.
430
431
432
433
434
435
436
437
438
439
    bool isShadowBuild = InspectorUi::instance()->isShadowBuildProject();
    if (isShadowBuild && rev == 0) {
        QString shadowBuildDir = InspectorUi::instance()->debugProjectBuildDirectory();

        if (filename.startsWith(shadowBuildDir)) {
            ProjectExplorer::Project *debugProject = InspectorUi::instance()->debugProject();
            filename = debugProject->projectDirectory() + filename.mid(shadowBuildDir.length());
        }
    }

440
    // append the debug ids in the hash
441
442
443
444
445
446
447
    m_debugIdHash[qMakePair<QString, int>(filename, rev)][qMakePair<int, int>(lineNum, colNum)].append(ref.debugId());

    foreach(const QDeclarativeDebugObjectReference &it, ref.children())
        buildDebugIdHashRecursive(it);
}


448
void ClientProxy::reloadQmlViewer()
449
{
450
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
451
        m_observerClient->reloadViewer();
452
453
}

454
455
void ClientProxy::setDesignModeBehavior(bool inDesignMode)
{
456
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
457
        m_observerClient->setDesignModeBehavior(inDesignMode);
458
459
}

460
461
void ClientProxy::setAnimationSpeed(qreal slowdownFactor)
{
462
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
463
        m_observerClient->setAnimationSpeed(slowdownFactor);
464
465
466
467
}

void ClientProxy::changeToColorPickerTool()
{
468
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
469
        m_observerClient->changeToColorPickerTool();
470
471
472
473
}

void ClientProxy::changeToZoomTool()
{
474
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
475
        m_observerClient->changeToZoomTool();
476
477
478
}
void ClientProxy::changeToSelectTool()
{
479
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
480
        m_observerClient->changeToSelectTool();
481
482
}

483
484
void ClientProxy::changeToSelectMarqueeTool()
{
485
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
486
        m_observerClient->changeToSelectMarqueeTool();
487
488
}

489
490
491
492
493
494
void ClientProxy::showAppOnTop(bool showOnTop)
{
    if (isConnected())
        m_observerClient->showAppOnTop(showOnTop);
}

495
void ClientProxy::createQmlObject(const QString &qmlText, int parentDebugId,
496
497
                                  const QStringList &imports, const QString &filename)
{
498
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
499
        m_observerClient->createQmlObject(qmlText, parentDebugId, imports, filename);
500
501
}

502
void ClientProxy::destroyQmlObject(int debugId)
503
{
504
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
505
        m_observerClient->destroyQmlObject(debugId);
506
507
}

508
509
void ClientProxy::reparentQmlObject(int debugId, int newParent)
{
510
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
511
        m_observerClient->reparentQmlObject(debugId, newParent);
512
513
}

514
515
void ClientProxy::setContextPathIndex(int contextIndex)
{
516
    if (isConnected())
Kai Koehne's avatar
Kai Koehne committed
517
        m_observerClient->setContextPathIndex(contextIndex);
518
519
}

520
521
void ClientProxy::updateConnected()
{
Kai Koehne's avatar
Kai Koehne committed
522
523
    bool isConnected = m_observerClient && m_observerClient->status() == QDeclarativeDebugClient::Enabled
            && m_engineClient && m_engineClient->status() == QDeclarativeEngineDebug::Enabled;
524
525
526
527
528

    if (isConnected != m_isConnected) {
        m_isConnected = isConnected;
        if (isConnected) {
            emit connected();
529
            reloadEngines();
530
531
532
533
534
535
        } else {
            emit disconnected();
        }
    }
}

536
537
538
539
540
541
542
543
544
void ClientProxy::reloadEngines()
{
    if (m_engineQuery) {
        emit connectionStatusMessage("[Inspector] Waiting for response to previous engine query");
        return;
    }

    emit aboutToReloadEngines();

Kai Koehne's avatar
Kai Koehne committed
545
    m_engineQuery = m_engineClient->queryAvailableEngines(this);
546
547
548
    if (!m_engineQuery->isWaiting())
        updateEngineList();
    else
Roberto Raggi's avatar
Roberto Raggi committed
549
        connect(m_engineQuery, SIGNAL(stateChanged(QDeclarativeDebugQuery::State)),
550
551
552
553
554
555
556
557
558
559
560
                         this, SLOT(updateEngineList()));
}

QList<QDeclarativeDebugEngineReference> ClientProxy::engines() const
{
    return m_engines;
}

void ClientProxy::updateEngineList()
{
    m_engines = m_engineQuery->engines();
Roberto Raggi's avatar
Roberto Raggi committed
561
562
    delete m_engineQuery;
    m_engineQuery = 0;
563
564
565

    emit enginesChanged();
}
Lasse Holmstedt's avatar
Lasse Holmstedt committed
566

567
Debugger::QmlAdapter *ClientProxy::qmlAdapter() const
Lasse Holmstedt's avatar
Lasse Holmstedt committed
568
569
570
571
572
573
{
    return m_adapter;
}

bool ClientProxy::isConnected() const
{
574
    return m_isConnected;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
575
}
576
577
578
579
580
581

void ClientProxy::newObjects()
{
    if (!m_requestObjectsTimer.isActive())
        m_requestObjectsTimer.start();
}