Commit 514ba53b authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Add capturing for qml puppet streams

Change-Id: I094e01b85cfe1ddafb0590f56d9d5b810a390cb4
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 90ce3aec
......@@ -20,4 +20,7 @@ will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.</license>
<description>Visual Designer for QML files.</description>
<url>http://www.qt-project.org</url>
$$dependencyList
<argumentList>
<argument name=\"-capture-puppet-stream\" parameter=\"capture file\">Captures the Qml Puppet stream</argument>
</argumentList>
</plugin>
......@@ -38,6 +38,7 @@
#include <QDir>
#include <QTimer>
#include <QTextStream>
#include <QMessageBox>
#include "createinstancescommand.h"
#include "createscenecommand.h"
......@@ -240,6 +241,13 @@ NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceV
} else {
QMessageBox::warning(0, tr("Cannot Find QML Puppet Executable"), missingQmlPuppetErrorMessage(applicationPath));
}
int indexOfCapturePuppetStream = QCoreApplication::arguments().indexOf("-capture-puppet-stream");
if (indexOfCapturePuppetStream > 0) {
m_captureFileForTest.setFileName(QCoreApplication::arguments().at(indexOfCapturePuppetStream + 1));
bool isOpen = m_captureFileForTest.open(QIODevice::WriteOnly);
qDebug() << "file is open: " << isOpen;
}
}
NodeInstanceServerProxy::~NodeInstanceServerProxy()
......@@ -333,9 +341,9 @@ QString NodeInstanceServerProxy::missingQmlPuppetErrorMessage(const QString &app
return message;
}
static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket, unsigned int commandCounter)
static void writeCommandToIODecive(const QVariant &command, QIODevice *ioDevice, unsigned int commandCounter)
{
if (socket) {
if (ioDevice) {
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
......@@ -345,22 +353,29 @@ static void writeCommandToSocket(const QVariant &command, QLocalSocket *socket,
out.device()->seek(0);
out << quint32(block.size() - sizeof(quint32));
socket->write(block);
ioDevice->write(block);
}
}
void NodeInstanceServerProxy::writeCommand(const QVariant &command)
{
writeCommandToSocket(command, m_firstSocket.data(), m_writeCommandCounter);
writeCommandToSocket(command, m_secondSocket.data(), m_writeCommandCounter);
writeCommandToSocket(command, m_thirdSocket.data(), m_writeCommandCounter);
writeCommandToIODecive(command, m_firstSocket.data(), m_writeCommandCounter);
writeCommandToIODecive(command, m_secondSocket.data(), m_writeCommandCounter);
writeCommandToIODecive(command, m_thirdSocket.data(), m_writeCommandCounter);
if (m_captureFileForTest.isWritable()) {
qDebug() << "Write strean to file: " << m_captureFileForTest.fileName();
writeCommandToIODecive(command, &m_captureFileForTest, m_writeCommandCounter);
qDebug() << "\twrite file: " << m_captureFileForTest.pos();
}
m_writeCommandCounter++;
if (m_runModus == TestModus) {
static int synchronizeId = 0;
synchronizeId++;
SynchronizeCommand synchronizeCommand(synchronizeId);
writeCommandToSocket(QVariant::fromValue(synchronizeCommand), m_firstSocket.data(), m_writeCommandCounter);
writeCommandToIODecive(QVariant::fromValue(synchronizeCommand), m_firstSocket.data(), m_writeCommandCounter);
m_writeCommandCounter++;
while (m_firstSocket->waitForReadyRead(100)) {
......@@ -375,6 +390,14 @@ void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitSt
{
qDebug() << "Process finished:" << sender();
if (m_captureFileForTest.isOpen()) {
m_captureFileForTest.close();
m_captureFileForTest.remove();
QMessageBox::warning(0, tr("Qml Puppet crashes"), tr("Your are recording a Puppet stream and the puppet crashes. "
"It is recommended to reopen the Qml Designer and start again."));
}
writeCommand(QVariant::fromValue(EndPuppetCommand()));
if (m_firstSocket)
......
......@@ -34,6 +34,7 @@
#include <QWeakPointer>
#include <QProcess>
#include <QFile>
QT_BEGIN_NAMESPACE
class QLocalServer;
......@@ -75,6 +76,8 @@ protected:
void dispatchCommand(const QVariant &command);
NodeInstanceClientInterface *nodeInstanceClient() const;
QString missingQmlPuppetErrorMessage(const QString &applicationPath) const;
QString qmlPuppetApplicationName() const;
QString macOSBundlePath(const QString &path) const;
signals:
void processCrashed();
......@@ -86,9 +89,7 @@ private slots:
void readThirdDataStream();
private:
QString qmlPuppetApplicationName() const;
QString macOSBundlePath(const QString &path) const;
QFile m_captureFileForTest;
QWeakPointer<QLocalServer> m_localServer;
QWeakPointer<QLocalSocket> m_firstSocket;
QWeakPointer<QLocalSocket> m_secondSocket;
......
......@@ -41,6 +41,7 @@
#include <coreplugin/designmode.h>
#include <coreplugin/icore.h>
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginspec.h>
#include <projectexplorer/projectexplorerconstants.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment