2019-01-17 10:47:47 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmlpreviewruncontrol.h"
|
|
|
|
|
|
2019-12-10 16:25:41 +01:00
|
|
|
#include <qmlprojectmanager/qmlproject.h>
|
|
|
|
|
#include <qmlprojectmanager/qmlmainfileaspect.h>
|
|
|
|
|
|
2019-01-17 10:47:47 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
|
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/port.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
#include <utils/url.h>
|
2019-12-10 16:25:41 +01:00
|
|
|
#include <utils/fileutils.h>
|
2019-01-17 10:47:47 +01:00
|
|
|
|
|
|
|
|
namespace QmlPreview {
|
|
|
|
|
|
|
|
|
|
static const QString QmlServerUrl = "QmlServerUrl";
|
|
|
|
|
|
|
|
|
|
QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
|
|
|
|
|
QmlPreviewFileLoader fileLoader,
|
|
|
|
|
QmlPreviewFileClassifier fileClassifier,
|
|
|
|
|
QmlPreviewFpsHandler fpsHandler,
|
|
|
|
|
float initialZoom,
|
|
|
|
|
const QString &initialLocale)
|
|
|
|
|
: RunWorker(runControl)
|
|
|
|
|
{
|
|
|
|
|
setId("QmlPreviewRunner");
|
2019-03-13 18:14:34 +01:00
|
|
|
m_connectionManager.setFileLoader(fileLoader);
|
|
|
|
|
m_connectionManager.setFileClassifier(fileClassifier);
|
|
|
|
|
m_connectionManager.setFpsHandler(fpsHandler);
|
2019-01-17 10:47:47 +01:00
|
|
|
|
|
|
|
|
connect(this, &QmlPreviewRunner::loadFile,
|
2019-03-13 18:14:34 +01:00
|
|
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::loadFile);
|
2019-01-17 10:47:47 +01:00
|
|
|
connect(this, &QmlPreviewRunner::rerun,
|
2019-03-13 18:14:34 +01:00
|
|
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::rerun);
|
2019-01-17 10:47:47 +01:00
|
|
|
|
|
|
|
|
connect(this, &QmlPreviewRunner::zoom,
|
2019-03-13 18:14:34 +01:00
|
|
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::zoom);
|
2019-01-17 10:47:47 +01:00
|
|
|
connect(this, &QmlPreviewRunner::language,
|
2019-03-13 18:14:34 +01:00
|
|
|
&m_connectionManager, &Internal::QmlPreviewConnectionManager::language);
|
|
|
|
|
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
|
2019-01-17 10:47:47 +01:00
|
|
|
this, [this, initialZoom, initialLocale]() {
|
|
|
|
|
if (initialZoom > 0)
|
|
|
|
|
emit zoom(initialZoom);
|
|
|
|
|
if (!initialLocale.isEmpty())
|
|
|
|
|
emit language(initialLocale);
|
|
|
|
|
emit ready();
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-13 18:14:34 +01:00
|
|
|
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::restart,
|
2019-09-11 08:22:53 +03:00
|
|
|
runControl, [this, runControl]() {
|
2019-01-17 10:47:47 +01:00
|
|
|
if (!runControl->isRunning())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-12-10 16:25:41 +01:00
|
|
|
this->connect(runControl, &ProjectExplorer::RunControl::stopped, runControl, [runControl]() {
|
2019-01-17 10:47:47 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin::runRunConfiguration(
|
2019-03-13 18:09:27 +01:00
|
|
|
runControl->runConfiguration(),
|
|
|
|
|
ProjectExplorer::Constants::QML_PREVIEW_RUN_MODE, true);
|
2019-01-17 10:47:47 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
runControl->initiateStop();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlPreviewRunner::start()
|
|
|
|
|
{
|
2019-03-13 18:14:34 +01:00
|
|
|
m_connectionManager.setTarget(runControl()->target());
|
|
|
|
|
m_connectionManager.connectToServer(serverUrl());
|
2019-01-17 10:47:47 +01:00
|
|
|
reportStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlPreviewRunner::stop()
|
|
|
|
|
{
|
2019-03-13 18:14:34 +01:00
|
|
|
m_connectionManager.disconnectFromServer();
|
2019-01-17 10:47:47 +01:00
|
|
|
reportStopped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlPreviewRunner::setServerUrl(const QUrl &serverUrl)
|
|
|
|
|
{
|
|
|
|
|
recordData(QmlServerUrl, serverUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QUrl QmlPreviewRunner::serverUrl() const
|
|
|
|
|
{
|
|
|
|
|
return recordedData(QmlServerUrl).toUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runControl)
|
|
|
|
|
: SimpleTargetRunner(runControl)
|
|
|
|
|
{
|
|
|
|
|
setId("LocalQmlPreviewSupport");
|
|
|
|
|
const QUrl serverUrl = Utils::urlFromLocalSocket();
|
|
|
|
|
|
|
|
|
|
QmlPreviewRunner *preview = qobject_cast<QmlPreviewRunner *>(
|
2019-09-03 12:11:56 +02:00
|
|
|
runControl->createWorker(ProjectExplorer::Constants::QML_PREVIEW_RUNNER));
|
2019-01-17 10:47:47 +01:00
|
|
|
preview->setServerUrl(serverUrl);
|
|
|
|
|
|
|
|
|
|
addStopDependency(preview);
|
|
|
|
|
addStartDependency(preview);
|
|
|
|
|
|
2019-09-02 18:22:35 +02:00
|
|
|
setStarter([this, runControl, serverUrl] {
|
2019-12-10 16:25:41 +01:00
|
|
|
ProjectExplorer::Runnable runnable = runControl->runnable();
|
|
|
|
|
QStringList qmlProjectRunConfigurationArguments = runnable.commandLine().splitArguments();
|
|
|
|
|
|
|
|
|
|
const auto currentTarget = runControl->target();
|
|
|
|
|
const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem());
|
|
|
|
|
|
|
|
|
|
const auto aspect = runControl->aspect<QmlProjectManager::QmlMainFileAspect>();
|
|
|
|
|
const QString mainScript = aspect->mainScript();
|
|
|
|
|
const QString currentFile = aspect->currentFile();
|
|
|
|
|
|
|
|
|
|
const QString mainScriptFromProject = qmlBuildSystem->targetFile(
|
|
|
|
|
Utils::FilePath::fromString(mainScript)).toString();
|
|
|
|
|
|
|
|
|
|
const QString currentFileFromProject = qmlBuildSystem->targetFile(
|
|
|
|
|
Utils::FilePath::fromString(currentFile)).toString();
|
|
|
|
|
|
|
|
|
|
if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) {
|
|
|
|
|
qmlProjectRunConfigurationArguments.removeLast();
|
|
|
|
|
auto commandLine = Utils::CommandLine(runnable.commandLine().executable(), qmlProjectRunConfigurationArguments);
|
|
|
|
|
commandLine.addArg(currentFile);
|
|
|
|
|
runnable.setCommandLine(commandLine);
|
|
|
|
|
}
|
2019-01-17 10:47:47 +01:00
|
|
|
|
2019-12-10 16:25:41 +01:00
|
|
|
Utils::QtcProcess::addArg(&runnable.commandLineArguments,
|
2019-09-02 18:22:35 +02:00
|
|
|
QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices,
|
|
|
|
|
serverUrl.path()));
|
2019-12-10 16:25:41 +01:00
|
|
|
doStart(runnable, {});
|
2019-09-02 18:22:35 +02:00
|
|
|
});
|
2019-01-17 10:47:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlPreview
|