2010-02-16 13:39:13 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
|
|
|
** Commercial Usage
|
|
|
|
**
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprojectruncontrol.h"
|
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2010-04-15 11:59:22 +02:00
|
|
|
#include "qmlprojectconstants.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
#include <projectexplorer/applicationlauncher.h>
|
2010-09-23 10:35:23 +02:00
|
|
|
#include <utils/environment.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
#include <debugger/debuggerrunner.h>
|
|
|
|
#include <debugger/debuggerplugin.h>
|
2010-02-24 11:30:32 +01:00
|
|
|
#include <debugger/debuggerconstants.h>
|
|
|
|
#include <debugger/debuggeruiswitcher.h>
|
2010-08-13 14:18:10 +02:00
|
|
|
#include <debugger/debuggerengine.h>
|
2010-06-28 17:46:42 +02:00
|
|
|
#include <qmljsinspector/qmljsinspectorconstants.h>
|
2010-10-05 10:54:05 +02:00
|
|
|
#include <qt4projectmanager/qtversionmanager.h>
|
|
|
|
#include <qt4projectmanager/qmlobservertool.h>
|
2010-10-04 15:13:31 +02:00
|
|
|
#include <qt4projectmanager/qt4projectmanagerconstants.h>
|
2010-02-24 11:30:32 +01:00
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
#include <QApplication>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QLabel>
|
2010-09-28 17:26:27 +02:00
|
|
|
#include <QMessageBox>
|
2010-10-04 15:13:31 +02:00
|
|
|
#include <QPushButton>
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
using ProjectExplorer::RunConfiguration;
|
|
|
|
using ProjectExplorer::RunControl;
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
|
|
|
namespace Internal {
|
|
|
|
|
2010-04-30 13:19:31 +02:00
|
|
|
QmlRunControl::QmlRunControl(QmlProjectRunConfiguration *runConfiguration, QString mode)
|
|
|
|
: RunControl(runConfiguration, mode)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment environment = Utils::Environment::systemEnvironment();
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
m_applicationLauncher.setEnvironment(environment.toStringList());
|
|
|
|
m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory());
|
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
if (mode == ProjectExplorer::Constants::RUNMODE) {
|
|
|
|
m_executable = runConfiguration->viewerPath();
|
|
|
|
} else {
|
|
|
|
m_executable = runConfiguration->observerPath();
|
|
|
|
}
|
2010-02-16 13:39:13 +01:00
|
|
|
m_commandLineArguments = runConfiguration->viewerArguments();
|
|
|
|
|
2010-04-19 14:21:33 +02:00
|
|
|
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,bool)),
|
|
|
|
this, SLOT(slotError(QString, bool)));
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(appendOutput(QString, bool)),
|
|
|
|
this, SLOT(slotAddToOutputWindow(QString, bool)));
|
2010-02-16 13:39:13 +01:00
|
|
|
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
|
|
|
|
this, SLOT(processExited(int)));
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
|
|
|
|
this, SLOT(slotBringApplicationToForeground(qint64)));
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControl::~QmlRunControl()
|
|
|
|
{
|
2010-10-04 09:44:18 +02:00
|
|
|
stop();
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::start()
|
|
|
|
{
|
|
|
|
m_applicationLauncher.start(ProjectExplorer::ApplicationLauncher::Gui, m_executable,
|
|
|
|
m_commandLineArguments);
|
2010-02-24 11:30:32 +01:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
emit started();
|
2010-04-19 15:55:02 +02:00
|
|
|
emit appendMessage(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
|
|
|
|
m_commandLineArguments.join(QLatin1String(" "))), false);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
2010-08-20 14:19:25 +02:00
|
|
|
RunControl::StopResult QmlRunControl::stop()
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
m_applicationLauncher.stop();
|
2010-08-20 14:19:25 +02:00
|
|
|
return StoppedSynchronously;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlRunControl::isRunning() const
|
|
|
|
{
|
|
|
|
return m_applicationLauncher.isRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
|
|
|
|
{
|
|
|
|
bringApplicationToForeground(pid);
|
|
|
|
}
|
|
|
|
|
2010-04-19 14:21:33 +02:00
|
|
|
void QmlRunControl::slotError(const QString &err, bool isError)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-04-19 14:21:33 +02:00
|
|
|
emit appendMessage(this, err, isError);
|
2010-02-16 13:39:13 +01:00
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
2010-04-19 14:21:33 +02:00
|
|
|
void QmlRunControl::slotAddToOutputWindow(const QString &line, bool onStdErr)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-04-19 14:21:33 +02:00
|
|
|
emit addToOutputWindowInline(this, line, onStdErr);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::processExited(int exitCode)
|
|
|
|
{
|
2010-04-19 14:21:33 +02:00
|
|
|
emit appendMessage(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode), exitCode != 0);
|
2010-02-16 13:39:13 +01:00
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControlFactory::QmlRunControlFactory(QObject *parent)
|
|
|
|
: IRunControlFactory(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControlFactory::~QmlRunControlFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlRunControlFactory::canRun(RunConfiguration *runConfiguration,
|
|
|
|
const QString &mode) const
|
|
|
|
{
|
2010-07-29 16:58:12 +02:00
|
|
|
QmlProjectRunConfiguration *config = qobject_cast<QmlProjectRunConfiguration*>(runConfiguration);
|
|
|
|
if (mode == ProjectExplorer::Constants::RUNMODE) {
|
2010-10-04 15:13:31 +02:00
|
|
|
return config != 0 && !config->viewerPath().isEmpty();
|
|
|
|
} else {
|
2010-08-18 13:54:12 +02:00
|
|
|
bool qmlDebugSupportInstalled = Debugger::DebuggerUISwitcher::instance()->supportedLanguages()
|
2010-08-24 17:17:54 +02:00
|
|
|
& Debugger::QmlLanguage;
|
2010-10-05 10:54:05 +02:00
|
|
|
|
|
|
|
if (config && qmlDebugSupportInstalled) {
|
|
|
|
if (!config->observerPath().isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->qtVersion() && Qt4ProjectManager::QmlObserverTool::canBuild(config->qtVersion())) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-07-29 16:58:12 +02:00
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
|
|
|
|
return false;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RunControl *QmlRunControlFactory::create(RunConfiguration *runConfiguration,
|
|
|
|
const QString &mode)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
|
2010-08-13 14:18:10 +02:00
|
|
|
|
|
|
|
QmlProjectRunConfiguration *config = qobject_cast<QmlProjectRunConfiguration *>(runConfiguration);
|
|
|
|
RunControl *runControl = 0;
|
|
|
|
if (mode == ProjectExplorer::Constants::RUNMODE) {
|
|
|
|
runControl = new QmlRunControl(config, mode);
|
2010-10-04 15:13:31 +02:00
|
|
|
} else if (mode == ProjectExplorer::Constants::DEBUGMODE) {
|
2010-08-13 14:18:10 +02:00
|
|
|
runControl = createDebugRunControl(config);
|
|
|
|
}
|
|
|
|
return runControl;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlRunControlFactory::displayName() const
|
|
|
|
{
|
|
|
|
return tr("Run");
|
|
|
|
}
|
|
|
|
|
2010-04-16 11:46:47 +02:00
|
|
|
QWidget *QmlRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(runConfiguration)
|
|
|
|
return new QLabel("TODO add Configuration widget");
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
ProjectExplorer::RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig)
|
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment environment = Utils::Environment::systemEnvironment();
|
2010-08-13 14:18:10 +02:00
|
|
|
Debugger::DebuggerStartParameters params;
|
|
|
|
params.startMode = Debugger::StartInternal;
|
2010-10-04 15:13:31 +02:00
|
|
|
params.executable = runConfig->observerPath();
|
2010-09-02 17:17:35 +02:00
|
|
|
params.qmlServerAddress = "127.0.0.1";
|
|
|
|
params.qmlServerPort = runConfig->qmlDebugServerPort();
|
2010-08-13 14:18:10 +02:00
|
|
|
params.processArgs = runConfig->viewerArguments();
|
2010-09-20 12:16:54 +02:00
|
|
|
params.processArgs.append(QLatin1String("-qmljsdebugger=port:") + QString::number(runConfig->qmlDebugServerPort()));
|
2010-08-13 14:18:10 +02:00
|
|
|
params.workingDirectory = runConfig->workingDirectory();
|
|
|
|
params.environment = environment.toStringList();
|
|
|
|
params.displayName = runConfig->displayName();
|
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
if (params.executable.isEmpty()) {
|
|
|
|
showQmlObserverToolWarning();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
Debugger::DebuggerRunControl *debuggerRunControl = Debugger::DebuggerPlugin::createDebugger(params, runConfig);
|
|
|
|
return debuggerRunControl;
|
|
|
|
}
|
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
void QmlRunControlFactory::showQmlObserverToolWarning() {
|
|
|
|
QMessageBox dialog(QApplication::activeWindow());
|
|
|
|
QPushButton *qtPref = dialog.addButton(tr("Open Qt4 Options"),
|
|
|
|
QMessageBox::ActionRole);
|
|
|
|
dialog.addButton(tr("Cancel"), QMessageBox::ActionRole);
|
|
|
|
dialog.setDefaultButton(qtPref);
|
|
|
|
dialog.setWindowTitle(tr("QML Observer Missing"));
|
|
|
|
dialog.setText(tr("QML Observer could not be found."));
|
|
|
|
dialog.setInformativeText(tr(
|
|
|
|
"QML Observer is used to offer debugging features for "
|
|
|
|
"QML applications, such as interactive debugging and inspection tools."
|
|
|
|
"It must be compiled for each used Qt version separately. "
|
|
|
|
"On the Qt4 options page, select the current Qt installation "
|
|
|
|
"and click Rebuild."));
|
|
|
|
dialog.exec();
|
|
|
|
if (dialog.clickedButton() == qtPref) {
|
|
|
|
Core::ICore::instance()->showOptionsDialog(
|
|
|
|
Qt4ProjectManager::Constants::QT_SETTINGS_CATEGORY,
|
|
|
|
Qt4ProjectManager::Constants::QTVERSION_SETTINGS_PAGE_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace Internal
|
|
|
|
} // namespace QmlProjectManager
|
|
|
|
|