2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-22 12:08:19 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-22 12:08:19 +01:00
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
#include "nodeinstanceclientproxy.h"
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStringList>
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
#include "nodeinstanceserverinterface.h"
|
2010-11-24 14:52:06 +01:00
|
|
|
|
|
|
|
#include "propertyabstractcontainer.h"
|
|
|
|
#include "propertyvaluecontainer.h"
|
|
|
|
#include "propertybindingcontainer.h"
|
|
|
|
#include "instancecontainer.h"
|
|
|
|
#include "createinstancescommand.h"
|
|
|
|
#include "createscenecommand.h"
|
|
|
|
#include "changevaluescommand.h"
|
|
|
|
#include "changebindingscommand.h"
|
2011-06-08 17:02:03 +02:00
|
|
|
#include "changeauxiliarycommand.h"
|
2010-11-24 14:52:06 +01:00
|
|
|
#include "changefileurlcommand.h"
|
|
|
|
#include "removeinstancescommand.h"
|
|
|
|
#include "clearscenecommand.h"
|
|
|
|
#include "removepropertiescommand.h"
|
|
|
|
#include "reparentinstancescommand.h"
|
|
|
|
#include "changeidscommand.h"
|
|
|
|
#include "changestatecommand.h"
|
2010-12-09 16:09:37 +01:00
|
|
|
#include "completecomponentcommand.h"
|
2011-01-18 18:23:28 +01:00
|
|
|
#include "synchronizecommand.h"
|
2011-07-06 15:48:21 +02:00
|
|
|
#include "tokencommand.h"
|
2010-11-24 14:52:06 +01:00
|
|
|
|
|
|
|
#include "informationchangedcommand.h"
|
|
|
|
#include "pixmapchangedcommand.h"
|
|
|
|
#include "valueschangedcommand.h"
|
2010-11-30 17:46:57 +01:00
|
|
|
#include "childrenchangedcommand.h"
|
2010-11-30 21:32:52 +01:00
|
|
|
#include "imagecontainer.h"
|
|
|
|
#include "statepreviewimagechangedcommand.h"
|
2010-12-09 16:09:37 +01:00
|
|
|
#include "componentcompletedcommand.h"
|
2011-06-08 17:02:03 +02:00
|
|
|
#include "changenodesourcecommand.h"
|
2010-11-24 14:52:06 +01:00
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
|
|
|
|
: QObject(parent),
|
2011-01-12 17:05:48 +01:00
|
|
|
m_nodeInstanceServer(0),
|
2011-01-18 18:23:28 +01:00
|
|
|
m_blockSize(0),
|
2011-04-19 17:13:08 +02:00
|
|
|
m_writeCommandCounter(0),
|
|
|
|
m_lastReadCommandCounter(0),
|
2011-01-18 18:23:28 +01:00
|
|
|
m_synchronizeId(-1)
|
2010-11-24 14:52:06 +01:00
|
|
|
{
|
2011-06-09 15:50:48 +02:00
|
|
|
}
|
2011-01-12 17:05:48 +01:00
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
void NodeInstanceClientProxy::initializeSocket()
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
m_socket = new QLocalSocket(this);
|
|
|
|
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream()));
|
|
|
|
connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit()));
|
|
|
|
connect(m_socket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit()));
|
|
|
|
m_socket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered);
|
|
|
|
m_socket->waitForConnected(-1);
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:50:38 +01:00
|
|
|
void NodeInstanceClientProxy::writeCommand(const QVariant &command)
|
2010-11-24 14:52:06 +01:00
|
|
|
{
|
|
|
|
QByteArray block;
|
|
|
|
QDataStream out(&block, QIODevice::WriteOnly);
|
2012-09-26 16:23:12 +02:00
|
|
|
out.setVersion(QDataStream::Qt_4_8);
|
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
out << quint32(0);
|
2011-04-19 17:13:08 +02:00
|
|
|
out << quint32(m_writeCommandCounter);
|
|
|
|
m_writeCommandCounter++;
|
2010-11-24 14:52:06 +01:00
|
|
|
out << command;
|
|
|
|
out.device()->seek(0);
|
|
|
|
out << quint32(block.size() - sizeof(quint32));
|
|
|
|
|
2011-01-06 13:50:38 +01:00
|
|
|
m_socket->write(block);
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 17:46:57 +01:00
|
|
|
void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-11-30 17:46:57 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 21:32:52 +01:00
|
|
|
void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-11-30 21:32:52 +01:00
|
|
|
}
|
|
|
|
|
2010-12-09 16:09:37 +01:00
|
|
|
void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command)
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
writeCommand(QVariant::fromValue(command));
|
2010-12-09 16:09:37 +01:00
|
|
|
}
|
|
|
|
|
2011-07-06 15:48:21 +02:00
|
|
|
void NodeInstanceClientProxy::token(const TokenCommand &command)
|
|
|
|
{
|
|
|
|
writeCommand(QVariant::fromValue(command));
|
|
|
|
}
|
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
void NodeInstanceClientProxy::flush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-18 18:23:28 +01:00
|
|
|
void NodeInstanceClientProxy::synchronizeWithClientProcess()
|
|
|
|
{
|
|
|
|
if (m_synchronizeId >= 0) {
|
|
|
|
SynchronizeCommand synchronizeCommand(m_synchronizeId);
|
|
|
|
writeCommand(QVariant::fromValue(synchronizeCommand));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
qint64 NodeInstanceClientProxy::bytesToWrite() const
|
|
|
|
{
|
2011-01-06 13:50:38 +01:00
|
|
|
return m_socket->bytesToWrite();
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::readDataStream()
|
|
|
|
{
|
|
|
|
QList<QVariant> commandList;
|
|
|
|
|
2011-01-06 13:50:38 +01:00
|
|
|
while (!m_socket->atEnd()) {
|
|
|
|
if (m_socket->bytesAvailable() < int(sizeof(quint32)))
|
2010-11-24 14:52:06 +01:00
|
|
|
break;
|
|
|
|
|
2011-01-06 13:50:38 +01:00
|
|
|
QDataStream in(m_socket);
|
2012-09-26 16:23:12 +02:00
|
|
|
in.setVersion(QDataStream::Qt_4_8);
|
2010-11-24 14:52:06 +01:00
|
|
|
|
|
|
|
if (m_blockSize == 0) {
|
|
|
|
in >> m_blockSize;
|
|
|
|
}
|
|
|
|
|
2011-01-06 13:50:38 +01:00
|
|
|
if (m_socket->bytesAvailable() < m_blockSize)
|
2010-11-24 14:52:06 +01:00
|
|
|
break;
|
|
|
|
|
2011-04-19 17:13:08 +02:00
|
|
|
quint32 commandCounter;
|
|
|
|
in >> commandCounter;
|
|
|
|
bool commandLost = !((m_lastReadCommandCounter == 0 && commandCounter == 0) || (m_lastReadCommandCounter + 1 == commandCounter));
|
|
|
|
if (commandLost)
|
|
|
|
qDebug() << "client command lost: " << m_lastReadCommandCounter << commandCounter;
|
|
|
|
m_lastReadCommandCounter = commandCounter;
|
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
QVariant command;
|
|
|
|
in >> command;
|
|
|
|
m_blockSize = 0;
|
|
|
|
|
2011-09-20 15:24:58 +02:00
|
|
|
if (in.status() != QDataStream::Ok) {
|
|
|
|
qWarning() << "Stream is no ok!!!";
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-11-24 14:52:06 +01:00
|
|
|
|
|
|
|
commandList.append(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QVariant &command, commandList) {
|
|
|
|
dispatchCommand(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const
|
|
|
|
{
|
2011-01-05 13:23:33 +01:00
|
|
|
return m_nodeInstanceServer;
|
|
|
|
}
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
void NodeInstanceClientProxy::setNodeInstanceServer(NodeInstanceServerInterface *nodeInstanceServer)
|
|
|
|
{
|
|
|
|
m_nodeInstanceServer = nodeInstanceServer;
|
|
|
|
}
|
|
|
|
|
2011-01-05 13:23:33 +01:00
|
|
|
void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->createInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeFileUrl(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->createScene(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->clearScene(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->removeInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->removeProperties(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changePropertyBindings(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changePropertyValues(command);
|
|
|
|
}
|
|
|
|
|
2011-06-08 17:02:03 +02:00
|
|
|
void NodeInstanceClientProxy::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeAuxiliaryValues(command);
|
|
|
|
}
|
|
|
|
|
2011-01-05 13:23:33 +01:00
|
|
|
void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->reparentInstances(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeIds(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->changeState(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->completeComponent(command);
|
2010-11-24 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2011-06-08 17:02:03 +02:00
|
|
|
void NodeInstanceClientProxy::changeNodeSource(const ChangeNodeSourceCommand &command)
|
2011-05-06 13:08:46 +02:00
|
|
|
{
|
2011-06-08 17:02:03 +02:00
|
|
|
nodeInstanceServer()->changeNodeSource(command);
|
2011-05-06 13:08:46 +02:00
|
|
|
}
|
2011-07-06 15:48:21 +02:00
|
|
|
void NodeInstanceClientProxy::redirectToken(const TokenCommand &command)
|
|
|
|
{
|
|
|
|
nodeInstanceServer()->token(command);
|
|
|
|
}
|
2011-05-06 13:08:46 +02:00
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
|
|
|
|
{
|
|
|
|
static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand");
|
|
|
|
static const int changeFileUrlCommandType = QMetaType::type("ChangeFileUrlCommand");
|
|
|
|
static const int createSceneCommandType = QMetaType::type("CreateSceneCommand");
|
|
|
|
static const int clearSceneCommandType = QMetaType::type("ClearSceneCommand");
|
|
|
|
static const int removeInstancesCommandType = QMetaType::type("RemoveInstancesCommand");
|
|
|
|
static const int removePropertiesCommandType = QMetaType::type("RemovePropertiesCommand");
|
|
|
|
static const int changeBindingsCommandType = QMetaType::type("ChangeBindingsCommand");
|
|
|
|
static const int changeValuesCommandType = QMetaType::type("ChangeValuesCommand");
|
2011-06-08 17:02:03 +02:00
|
|
|
static const int changeAuxiliaryCommandType = QMetaType::type("ChangeAuxiliaryCommand");
|
2010-11-24 14:52:06 +01:00
|
|
|
static const int reparentInstancesCommandType = QMetaType::type("ReparentInstancesCommand");
|
|
|
|
static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand");
|
|
|
|
static const int changeStateCommandType = QMetaType::type("ChangeStateCommand");
|
2010-12-09 16:09:37 +01:00
|
|
|
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
|
2011-01-18 18:23:28 +01:00
|
|
|
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
|
2011-06-08 17:02:03 +02:00
|
|
|
static const int changeNodeSourceCommandType = QMetaType::type("ChangeNodeSourceCommand");
|
2011-07-06 15:48:21 +02:00
|
|
|
static const int tokenCommandType = QMetaType::type("TokenCommand");
|
2010-11-24 14:52:06 +01:00
|
|
|
|
2011-01-05 13:23:33 +01:00
|
|
|
if (command.userType() == createInstancesCommandType) {
|
|
|
|
createInstances(command.value<CreateInstancesCommand>());
|
|
|
|
} else if (command.userType() == changeFileUrlCommandType)
|
|
|
|
changeFileUrl(command.value<ChangeFileUrlCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == createSceneCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
createScene(command.value<CreateSceneCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == clearSceneCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
clearScene(command.value<ClearSceneCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == removeInstancesCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
removeInstances(command.value<RemoveInstancesCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == removePropertiesCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
removeProperties(command.value<RemovePropertiesCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == changeBindingsCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
changePropertyBindings(command.value<ChangeBindingsCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == changeValuesCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
changePropertyValues(command.value<ChangeValuesCommand>());
|
2011-06-08 17:02:03 +02:00
|
|
|
else if (command.userType() == changeAuxiliaryCommandType)
|
|
|
|
changeAuxiliaryValues(command.value<ChangeAuxiliaryCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == reparentInstancesCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
reparentInstances(command.value<ReparentInstancesCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == changeIdsCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
changeIds(command.value<ChangeIdsCommand>());
|
2010-11-24 14:52:06 +01:00
|
|
|
else if (command.userType() == changeStateCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
changeState(command.value<ChangeStateCommand>());
|
2010-12-09 16:09:37 +01:00
|
|
|
else if (command.userType() == completeComponentCommandType)
|
2011-01-05 13:23:33 +01:00
|
|
|
completeComponent(command.value<CompleteComponentCommand>());
|
2011-06-08 17:02:03 +02:00
|
|
|
else if (command.userType() == changeNodeSourceCommandType)
|
|
|
|
changeNodeSource(command.value<ChangeNodeSourceCommand>());
|
2011-07-06 15:48:21 +02:00
|
|
|
else if (command.userType() == tokenCommandType)
|
|
|
|
redirectToken(command.value<TokenCommand>());
|
2011-01-18 18:23:28 +01:00
|
|
|
else if (command.userType() == synchronizeCommandType) {
|
|
|
|
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
|
|
|
|
m_synchronizeId = synchronizeCommand.synchronizeId();
|
|
|
|
} else
|
2010-11-24 14:52:06 +01:00
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
|
|
|
} // namespace QmlDesigner
|