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 #pragma once
27
28 #include <projectexplorer/projectexplorerconstants.h>
29
30 #include <utils/id.h>
31
32 #include <QString>
33 #include <QUrl>
34
35 namespace QmlDebug {
36
37 enum QmlDebugServicesPreset {
38 NoQmlDebugServices,
39 QmlDebuggerServices,
40 QmlProfilerServices,
41 QmlNativeDebuggerServices,
42 QmlPreviewServices
43 };
44
qmlDebugServices(QmlDebugServicesPreset preset)45 inline QString qmlDebugServices(QmlDebugServicesPreset preset)
46 {
47 switch (preset) {
48 case NoQmlDebugServices:
49 return QString();
50 case QmlDebuggerServices:
51 return QStringLiteral("DebugMessages,QmlDebugger,V8Debugger,QmlInspector,DebugTranslation");
52 case QmlProfilerServices:
53 return QStringLiteral("CanvasFrameRate,EngineControl,DebugMessages,DebugTranslation");
54 case QmlNativeDebuggerServices:
55 return QStringLiteral("NativeQmlDebugger,DebugTranslation");
56 case QmlPreviewServices:
57 return QStringLiteral("QmlPreview,DebugTranslation");
58 default:
59 Q_ASSERT(false);
60 return QString();
61 }
62 }
63
qmlDebugCommandLineArguments(QmlDebugServicesPreset services,const QString & connectionMode,bool block)64 inline QString qmlDebugCommandLineArguments(QmlDebugServicesPreset services,
65 const QString &connectionMode, bool block)
66 {
67 if (services == NoQmlDebugServices)
68 return QString();
69
70 return QString::fromLatin1("-qmljsdebugger=%1%2,services:%3").arg(connectionMode)
71 .arg(QLatin1String(block ? ",block" : "")).arg(qmlDebugServices(services));
72 }
73
74 inline QString qmlDebugTcpArguments(QmlDebugServicesPreset services,
75 const QUrl &server, bool block = true)
76 {
77 // TODO: Also generate host:<host> if applicable.
78 return qmlDebugCommandLineArguments(services, QString("port:%1").arg(server.port()), block);
79 }
80
81 inline QString qmlDebugNativeArguments(QmlDebugServicesPreset services, bool block = true)
82 {
83 return qmlDebugCommandLineArguments(services, QLatin1String("native"), block);
84 }
85
86 inline QString qmlDebugLocalArguments(QmlDebugServicesPreset services, const QString &socket,
87 bool block = true)
88 {
89 return qmlDebugCommandLineArguments(services, QLatin1String("file:") + socket, block);
90 }
91
runnerIdForRunMode(Utils::Id runMode)92 inline Utils::Id runnerIdForRunMode(Utils::Id runMode)
93 {
94 if (runMode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE)
95 return ProjectExplorer::Constants::QML_PROFILER_RUNNER;
96 if (runMode == ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE)
97 return ProjectExplorer::Constants::QML_PREVIEW_RUNNER;
98 return {};
99 }
100
servicesForRunMode(Utils::Id runMode)101 inline QmlDebugServicesPreset servicesForRunMode(Utils::Id runMode)
102 {
103 if (runMode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE)
104 return QmlDebug::QmlProfilerServices;
105 if (runMode == ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE)
106 return QmlDebug::QmlPreviewServices;
107 if (runMode == ProjectExplorer::Constants::DEBUG_RUN_MODE)
108 return QmlDebug::QmlDebuggerServices;
109 return {};
110 }
111
112 } // namespace QmlDebug
113