1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "nodeinstanceserverproxy.h"
27
28 #include "connectionmanagerinterface.h"
29 #include "puppetcreator.h"
30
31 #include <changeauxiliarycommand.h>
32 #include <changebindingscommand.h>
33 #include <changefileurlcommand.h>
34 #include <changeidscommand.h>
35 #include <changelanguagecommand.h>
36 #include <changenodesourcecommand.h>
37 #include <changepreviewimagesizecommand.h>
38 #include <changeselectioncommand.h>
39 #include <changestatecommand.h>
40 #include <changevaluescommand.h>
41 #include <childrenchangedcommand.h>
42 #include <clearscenecommand.h>
43 #include <completecomponentcommand.h>
44 #include <componentcompletedcommand.h>
45 #include <createinstancescommand.h>
46 #include <createscenecommand.h>
47 #include <debugoutputcommand.h>
48 #include <endpuppetcommand.h>
49 #include <informationchangedcommand.h>
50 #include <inputeventcommand.h>
51 #include <pixmapchangedcommand.h>
52 #include <puppettocreatorcommand.h>
53 #include <removeinstancescommand.h>
54 #include <removepropertiescommand.h>
55 #include <removesharedmemorycommand.h>
56 #include <reparentinstancescommand.h>
57 #include <statepreviewimagechangedcommand.h>
58 #include <synchronizecommand.h>
59 #include <tokencommand.h>
60 #include <update3dviewstatecommand.h>
61 #include <valueschangedcommand.h>
62 #include <view3dactioncommand.h>
63 #include <requestmodelnodepreviewimagecommand.h>
64
65 #include <import.h>
66 #include <nodeinstanceview.h>
67 #include <rewriterview.h>
68
69 #include <coreplugin/editormanager/editormanager.h>
70 #include <coreplugin/icore.h>
71 #include <projectexplorer/kit.h>
72 #include <utils/hostosinfo.h>
73 #include <qtsupport/baseqtversion.h>
74 #include <qtsupport/qtkitinformation.h>
75 #include <qtsupport/qtsupportconstants.h>
76
77 #include <QCoreApplication>
78 #include <QDir>
79 #include <QFileInfo>
80 #include <QLocalServer>
81 #include <QLocalSocket>
82 #include <QLoggingCategory>
83 #include <QMessageBox>
84 #include <QProcess>
85 #include <QTextStream>
86 #include <QTimer>
87 #include <QUuid>
88
89 namespace QmlDesigner {
90
91 static Q_LOGGING_CATEGORY(instanceViewBenchmark, "qtc.nodeinstances.init", QtWarningMsg);
92
NodeInstanceServerProxy(NodeInstanceView * nodeInstanceView,ProjectExplorer::Target * target,ConnectionManagerInterface & connectionManager)93 NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceView,
94 ProjectExplorer::Target *target,
95 ConnectionManagerInterface &connectionManager)
96 : m_nodeInstanceView(nodeInstanceView)
97 , m_connectionManager{connectionManager}
98
99 {
100 if (instanceViewBenchmark().isInfoEnabled())
101 m_benchmarkTimer.start();
102
103 m_connectionManager.setUp(this, qrcMappingString(), target, nodeInstanceView);
104
105 qCInfo(instanceViewBenchmark) << "puppets setup:" << m_benchmarkTimer.elapsed();
106 }
107
~NodeInstanceServerProxy()108 NodeInstanceServerProxy::~NodeInstanceServerProxy()
109 {
110 m_connectionManager.shutDown();
111 }
112
dispatchCommand(const QVariant & command)113 void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
114 {
115 static const int informationChangedCommandType = QMetaType::type("InformationChangedCommand");
116 static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand");
117 static const int valuesModifiedCommandType = QMetaType::type("ValuesModifiedCommand");
118 static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
119 static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
120 static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
121 static const int componentCompletedCommandType = QMetaType::type("ComponentCompletedCommand");
122 static const int tokenCommandType = QMetaType::type("TokenCommand");
123 static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
124 static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
125 static const int puppetToCreatorCommandType = QMetaType::type("PuppetToCreatorCommand");
126
127 qCInfo(instanceViewBenchmark) << "dispatching command" << command.userType() << command.typeName();
128 if (command.userType() == informationChangedCommandType) {
129 nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>());
130 } else if (command.userType() == valuesChangedCommandType) {
131 nodeInstanceClient()->valuesChanged(command.value<ValuesChangedCommand>());
132 } else if (command.userType() == valuesModifiedCommandType) {
133 nodeInstanceClient()->valuesModified(command.value<ValuesModifiedCommand>());
134 } else if (command.userType() == pixmapChangedCommandType) {
135 nodeInstanceClient()->pixmapChanged(command.value<PixmapChangedCommand>());
136 } else if (command.userType() == childrenChangedCommandType) {
137 nodeInstanceClient()->childrenChanged(command.value<ChildrenChangedCommand>());
138 } else if (command.userType() == statePreviewImageChangedCommandType) {
139 nodeInstanceClient()->statePreviewImagesChanged(command.value<StatePreviewImageChangedCommand>());
140 } else if (command.userType() == componentCompletedCommandType) {
141 nodeInstanceClient()->componentCompleted(command.value<ComponentCompletedCommand>());
142 } else if (command.userType() == tokenCommandType) {
143 nodeInstanceClient()->token(command.value<TokenCommand>());
144 } else if (command.userType() == debugOutputCommandType) {
145 nodeInstanceClient()->debugOutput(command.value<DebugOutputCommand>());
146 } else if (command.userType() == changeSelectionCommandType) {
147 nodeInstanceClient()->selectionChanged(command.value<ChangeSelectionCommand>());
148 } else if (command.userType() == puppetToCreatorCommandType) {
149 nodeInstanceClient()->handlePuppetToCreatorCommand(command.value<PuppetToCreatorCommand>());
150 } else {
151 Q_ASSERT(false);
152 }
153
154 qCInfo(instanceViewBenchmark) << "dispatching command" << "done" << command.userType();
155 }
156
nodeInstanceClient() const157 NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const
158 {
159 return m_nodeInstanceView;
160 }
161
qrcMappingString() const162 QString NodeInstanceServerProxy::qrcMappingString() const
163 {
164 if (m_nodeInstanceView && m_nodeInstanceView->model()) {
165 RewriterView *rewriterView = m_nodeInstanceView->model()->rewriterView();
166 if (rewriterView) {
167 QString mappingString;
168
169 using StringPair = QPair<QString, QString>;
170
171 foreach (const StringPair &pair, rewriterView->qrcMapping()) {
172 if (!mappingString.isEmpty())
173 mappingString.append(QLatin1String(";"));
174 mappingString.append(pair.first);
175 mappingString.append(QLatin1String("="));
176 mappingString.append(pair.second);
177 }
178
179 return mappingString;
180 }
181 }
182
183 return QString();
184 }
185
writeCommand(const QVariant & command)186 void NodeInstanceServerProxy::writeCommand(const QVariant &command)
187 {
188 m_connectionManager.writeCommand(command);
189 }
190
createInstances(const CreateInstancesCommand & command)191 void NodeInstanceServerProxy::createInstances(const CreateInstancesCommand &command)
192 {
193 writeCommand(QVariant::fromValue(command));
194 }
195
changeFileUrl(const ChangeFileUrlCommand & command)196 void NodeInstanceServerProxy::changeFileUrl(const ChangeFileUrlCommand &command)
197 {
198 writeCommand(QVariant::fromValue(command));
199 }
200
createScene(const CreateSceneCommand & command)201 void NodeInstanceServerProxy::createScene(const CreateSceneCommand &command)
202 {
203 qCInfo(instanceViewBenchmark) << Q_FUNC_INFO << m_benchmarkTimer.elapsed();
204 writeCommand(QVariant::fromValue(command));
205 }
206
clearScene(const ClearSceneCommand & command)207 void NodeInstanceServerProxy::clearScene(const ClearSceneCommand &command)
208 {
209 writeCommand(QVariant::fromValue(command));
210 }
211
update3DViewState(const Update3dViewStateCommand & command)212 void NodeInstanceServerProxy::update3DViewState(const Update3dViewStateCommand &command)
213 {
214 writeCommand(QVariant::fromValue(command));
215 }
216
removeInstances(const RemoveInstancesCommand & command)217 void NodeInstanceServerProxy::removeInstances(const RemoveInstancesCommand &command)
218 {
219 writeCommand(QVariant::fromValue(command));
220 }
221
changeSelection(const ChangeSelectionCommand & command)222 void NodeInstanceServerProxy::changeSelection(const ChangeSelectionCommand &command)
223 {
224 writeCommand(QVariant::fromValue(command));
225 }
226
removeProperties(const RemovePropertiesCommand & command)227 void NodeInstanceServerProxy::removeProperties(const RemovePropertiesCommand &command)
228 {
229 writeCommand(QVariant::fromValue(command));
230 }
231
changePropertyBindings(const ChangeBindingsCommand & command)232 void NodeInstanceServerProxy::changePropertyBindings(const ChangeBindingsCommand &command)
233 {
234 writeCommand(QVariant::fromValue(command));
235 }
236
changePropertyValues(const ChangeValuesCommand & command)237 void NodeInstanceServerProxy::changePropertyValues(const ChangeValuesCommand &command)
238 {
239 writeCommand(QVariant::fromValue(command));
240 }
241
changeAuxiliaryValues(const ChangeAuxiliaryCommand & command)242 void NodeInstanceServerProxy::changeAuxiliaryValues(const ChangeAuxiliaryCommand &command)
243 {
244 writeCommand(QVariant::fromValue(command));
245 }
246
reparentInstances(const ReparentInstancesCommand & command)247 void NodeInstanceServerProxy::reparentInstances(const ReparentInstancesCommand &command)
248 {
249 writeCommand(QVariant::fromValue(command));
250 }
251
changeIds(const ChangeIdsCommand & command)252 void NodeInstanceServerProxy::changeIds(const ChangeIdsCommand &command)
253 {
254 writeCommand(QVariant::fromValue(command));
255 }
256
changeState(const ChangeStateCommand & command)257 void NodeInstanceServerProxy::changeState(const ChangeStateCommand &command)
258 {
259 writeCommand(QVariant::fromValue(command));
260 }
261
completeComponent(const CompleteComponentCommand & command)262 void NodeInstanceServerProxy::completeComponent(const CompleteComponentCommand &command)
263 {
264 writeCommand(QVariant::fromValue(command));
265 }
266
changeNodeSource(const ChangeNodeSourceCommand & command)267 void NodeInstanceServerProxy::changeNodeSource(const ChangeNodeSourceCommand &command)
268 {
269 writeCommand(QVariant::fromValue(command));
270 }
271
token(const TokenCommand & command)272 void NodeInstanceServerProxy::token(const TokenCommand &command)
273 {
274 writeCommand(QVariant::fromValue(command));
275 }
276
removeSharedMemory(const RemoveSharedMemoryCommand & command)277 void NodeInstanceServerProxy::removeSharedMemory(const RemoveSharedMemoryCommand &command)
278 {
279 writeCommand(QVariant::fromValue(command));
280 }
281
benchmark(const QString & message)282 void NodeInstanceServerProxy::benchmark(const QString &message)
283 {
284 qCInfo(instanceViewBenchmark) << message << m_benchmarkTimer.elapsed();
285 }
286
inputEvent(const InputEventCommand & command)287 void NodeInstanceServerProxy::inputEvent(const InputEventCommand &command)
288 {
289 writeCommand(QVariant::fromValue(command));
290 }
291
view3DAction(const View3DActionCommand & command)292 void NodeInstanceServerProxy::view3DAction(const View3DActionCommand &command)
293 {
294 writeCommand(QVariant::fromValue(command));
295 }
296
requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand & command)297 void NodeInstanceServerProxy::requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command)
298 {
299 writeCommand(QVariant::fromValue(command));
300 }
301
changeLanguage(const ChangeLanguageCommand & command)302 void NodeInstanceServerProxy::changeLanguage(const ChangeLanguageCommand &command)
303 {
304 writeCommand(QVariant::fromValue(command));
305 }
306
changePreviewImageSize(const ChangePreviewImageSizeCommand & command)307 void NodeInstanceServerProxy::changePreviewImageSize(const ChangePreviewImageSizeCommand &command)
308 {
309 writeCommand(QVariant::fromValue(command));
310 }
311
312 } // namespace QmlDesigner
313