2010-02-16 13:39:13 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
** this package.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#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-10-26 15:39:37 +02:00
|
|
|
#include <qt4projectmanager/qtversionmanager.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-10-19 11:14:03 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
|
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>
|
2010-08-13 14:18:10 +02:00
|
|
|
#include <debugger/debuggerengine.h>
|
2011-01-10 10:14:23 +01:00
|
|
|
#include <debugger/debuggerstartparameters.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
|
|
|
|
2011-01-24 12:29:48 +01:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
2010-02-16 13:39:13 +01:00
|
|
|
|
2011-01-07 14:52:18 +01:00
|
|
|
using namespace ProjectExplorer;
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
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-11-29 12:50:44 +01:00
|
|
|
m_applicationLauncher.setEnvironment(runConfiguration->environment());
|
2010-02-16 13:39:13 +01:00
|
|
|
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();
|
|
|
|
|
2011-01-07 14:52:18 +01:00
|
|
|
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,ProjectExplorer::OutputFormat)),
|
|
|
|
this, SLOT(slotAppendMessage(QString, ProjectExplorer::OutputFormat)));
|
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()
|
|
|
|
{
|
2011-01-07 14:52:18 +01:00
|
|
|
m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable,
|
2010-02-16 13:39:13 +01:00
|
|
|
m_commandLineArguments);
|
2010-02-24 11:30:32 +01:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
emit started();
|
2011-01-07 14:52:18 +01:00
|
|
|
QString msg = tr("Starting %1 %2")
|
|
|
|
.arg(QDir::toNativeSeparators(m_executable), m_commandLineArguments);
|
2011-01-07 18:57:54 +01:00
|
|
|
appendMessage(msg, NormalMessageFormat);
|
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);
|
|
|
|
}
|
|
|
|
|
2011-01-07 14:52:18 +01:00
|
|
|
void QmlRunControl::slotAppendMessage(const QString &line, OutputFormat format)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2011-01-07 18:57:54 +01:00
|
|
|
appendMessage(line, format);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::processExited(int exitCode)
|
|
|
|
{
|
2011-01-07 14:52:18 +01:00
|
|
|
QString msg = tr("%1 exited with code %2")
|
|
|
|
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
|
2011-01-07 18:57:54 +01:00
|
|
|
appendMessage(msg, exitCode ? ErrorMessageFormat : NormalMessageFormat);
|
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-11-10 11:39:01 +01: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();
|
2010-11-10 11:39:01 +01:00
|
|
|
|
|
|
|
bool qmlDebugSupportInstalled =
|
|
|
|
Debugger::DebuggerPlugin::isActiveDebugLanguage(Debugger::QmlLanguage);
|
|
|
|
|
|
|
|
if (config && qmlDebugSupportInstalled) {
|
|
|
|
if (!config->observerPath().isEmpty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (config->qtVersion() && Qt4ProjectManager::QmlObserverTool::canBuild(config->qtVersion())) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2010-10-05 10:54:05 +02:00
|
|
|
}
|
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-11-12 20:18:29 +01:00
|
|
|
} else if (mode == Debugger::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");
|
|
|
|
}
|
|
|
|
|
2011-01-07 14:52:18 +01:00
|
|
|
RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig)
|
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-10-19 11:14:03 +02:00
|
|
|
Utils::QtcProcess::addArg(¶ms.processArgs,
|
|
|
|
QLatin1String("-qmljsdebugger=port:") + QString::number(runConfig->qmlDebugServerPort()));
|
2010-08-13 14:18:10 +02:00
|
|
|
params.workingDirectory = runConfig->workingDirectory();
|
2010-11-29 12:50:44 +01:00
|
|
|
params.environment = runConfig->environment();
|
2010-08-13 14:18:10 +02:00
|
|
|
params.displayName = runConfig->displayName();
|
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
if (params.executable.isEmpty()) {
|
|
|
|
showQmlObserverToolWarning();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-10 11:39:01 +01:00
|
|
|
return Debugger::DebuggerPlugin::createDebugger(params, runConfig);
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
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 "
|
2010-10-11 14:05:10 +02:00
|
|
|
"QML applications, such as interactive debugging and inspection tools. "
|
2010-10-04 15:13:31 +02:00
|
|
|
"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
|
|
|
|
|