2009-05-04 12:19:22 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
** 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
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlproject.h"
|
|
|
|
#include "qmlprojectconstants.h"
|
|
|
|
|
|
|
|
#include <projectexplorer/toolchain.h>
|
2009-09-29 11:39:55 +02:00
|
|
|
#include <projectexplorer/persistentsettings.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
#include <coreplugin/icore.h>
|
2009-05-04 13:38:03 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2009-12-18 15:32:36 +10:00
|
|
|
#include <coreplugin/modemanager.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
#include <qmljseditor/qmlmodelmanagerinterface.h>
|
2009-09-04 17:54:38 +02:00
|
|
|
|
2009-05-05 12:21:57 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
#include <QtCore/QtDebug>
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
|
|
|
#include <QtGui/QFormLayout>
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
#include <QtGui/QComboBox>
|
2009-05-11 17:43:40 +02:00
|
|
|
#include <QtGui/QMessageBox>
|
2009-09-30 11:36:34 +02:00
|
|
|
#include <QtGui/QLineEdit>
|
2009-12-16 16:39:39 +01:00
|
|
|
#include <QtGui/QLabel>
|
2009-12-17 09:54:16 +01:00
|
|
|
#include <QtGui/QSpinBox>
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-18 16:32:14 +01:00
|
|
|
#include <QtDeclarative/QmlComponent>
|
2009-12-18 15:32:36 +10:00
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
using namespace QmlProjectManager;
|
|
|
|
using namespace QmlProjectManager::Internal;
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
namespace {
|
|
|
|
const char * const QML_RC_ID("QmlProjectManager.QmlRunConfiguration");
|
|
|
|
const char * const QML_RC_DISPLAY_NAME(QT_TRANSLATE_NOOP("QmlProjectManager::Internal::QmlRunConfiguration", "QML Viewer"));
|
|
|
|
|
|
|
|
const char * const QML_VIEWER_KEY("QmlProjectManager.QmlRunConfiguration.QmlViewer");
|
|
|
|
const char * const QML_VIEWER_ARGUMENTS_KEY("QmlProjectManager.QmlRunConfiguration.QmlViewerArguments");
|
|
|
|
const char * const QML_MAINSCRIPT_KEY("QmlProjectManager.QmlRunConfiguration.MainScript");
|
|
|
|
const char * const QML_DEBUG_SERVER_PORT_KEY("QmlProjectManager.QmlRunConfiguration.DebugServerPort");
|
|
|
|
|
|
|
|
const int DEFAULT_DEBUG_SERVER_PORT(3768);
|
|
|
|
} // namespace
|
2010-01-18 16:32:14 +01:00
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QmlProject
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QmlProject::QmlProject(Manager *manager, const QString &fileName)
|
|
|
|
: m_manager(manager),
|
2009-09-04 17:54:38 +02:00
|
|
|
m_fileName(fileName),
|
2010-01-19 13:53:48 +01:00
|
|
|
m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJSEditor::QmlModelManagerInterface>()),
|
|
|
|
m_fileWatcher(new ProjectExplorer::FileWatcher(this))
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
QFileInfo fileInfo(m_fileName);
|
2009-05-06 15:56:54 +02:00
|
|
|
m_projectName = fileInfo.completeBaseName();
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
m_file = new QmlProjectFile(this, fileName);
|
|
|
|
m_rootNode = new QmlProjectNode(this, m_file);
|
|
|
|
|
2010-01-19 13:53:48 +01:00
|
|
|
m_fileWatcher->addFile(fileName),
|
|
|
|
connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
|
|
|
this, SLOT(refreshProjectFile()));
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
m_manager->registerProject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProject::~QmlProject()
|
|
|
|
{
|
|
|
|
m_manager->unregisterProject(this);
|
|
|
|
|
|
|
|
delete m_rootNode;
|
|
|
|
}
|
|
|
|
|
2009-05-06 16:13:44 +02:00
|
|
|
QDir QmlProject::projectDir() const
|
|
|
|
{
|
|
|
|
return QFileInfo(file()->fileName()).dir();
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
QString QmlProject::filesFileName() const
|
2009-05-06 15:56:54 +02:00
|
|
|
{ return m_fileName; }
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
static QStringList readLines(const QString &absoluteFileName)
|
|
|
|
{
|
|
|
|
QStringList lines;
|
|
|
|
|
|
|
|
QFile file(absoluteFileName);
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
|
|
|
forever {
|
|
|
|
QString line = stream.readLine();
|
|
|
|
if (line.isNull())
|
|
|
|
break;
|
|
|
|
|
|
|
|
line = line.trimmed();
|
|
|
|
if (line.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lines.append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::parseProject(RefreshOptions options)
|
|
|
|
{
|
|
|
|
if (options & Files) {
|
2010-01-19 13:53:48 +01:00
|
|
|
if (options & ProjectFile)
|
|
|
|
delete m_projectItem.data();
|
2010-01-18 16:32:14 +01:00
|
|
|
if (!m_projectItem) {
|
2010-01-19 13:53:48 +01:00
|
|
|
QFile file(m_fileName);
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
QmlComponent *component = new QmlComponent(&m_engine, this);
|
|
|
|
component->setData(file.readAll(), QUrl::fromLocalFile(m_fileName));
|
|
|
|
if (component->isReady()
|
|
|
|
&& qobject_cast<QmlProjectItem*>(component->create())) {
|
|
|
|
m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
|
|
|
|
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged()), this, SLOT(refreshFiles()));
|
|
|
|
} else {
|
|
|
|
qWarning() << m_fileName << "is not valid qml file, falling back to old format ...";
|
|
|
|
m_files = convertToAbsoluteFiles(readLines(filesFileName()));
|
|
|
|
m_files.removeDuplicates();
|
|
|
|
m_modelManager->updateSourceFiles(m_files);
|
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_projectItem) {
|
|
|
|
m_projectItem.data()->setSourceDirectory(projectDir().path());
|
2010-01-28 17:12:07 +01:00
|
|
|
m_modelManager->updateSourceFiles(m_projectItem.data()->files());
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
m_rootNode->refresh();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Configuration) {
|
|
|
|
// update configuration
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Files)
|
|
|
|
emit fileListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::refresh(RefreshOptions options)
|
|
|
|
{
|
|
|
|
QSet<QString> oldFileList;
|
|
|
|
if (!(options & Configuration))
|
|
|
|
oldFileList = m_files.toSet();
|
|
|
|
|
|
|
|
parseProject(options);
|
|
|
|
|
|
|
|
if (options & Files)
|
|
|
|
m_rootNode->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
|
|
|
|
{
|
|
|
|
const QDir projectDir(QFileInfo(m_fileName).dir());
|
|
|
|
QStringList absolutePaths;
|
|
|
|
foreach (const QString &file, paths) {
|
|
|
|
QFileInfo fileInfo(projectDir, file);
|
|
|
|
absolutePaths.append(fileInfo.absoluteFilePath());
|
|
|
|
}
|
|
|
|
absolutePaths.removeDuplicates();
|
|
|
|
return absolutePaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::files() const
|
2010-01-18 16:32:14 +01:00
|
|
|
{
|
|
|
|
QStringList files;
|
|
|
|
if (m_projectItem) {
|
2010-01-28 17:12:07 +01:00
|
|
|
files = m_projectItem.data()->files();
|
2010-01-18 16:32:14 +01:00
|
|
|
} else {
|
|
|
|
files = m_files;
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-19 13:53:48 +01:00
|
|
|
void QmlProject::refreshProjectFile()
|
|
|
|
{
|
|
|
|
refresh(QmlProject::ProjectFile | Files);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::refreshFiles()
|
|
|
|
{
|
|
|
|
refresh(Files);
|
|
|
|
}
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString QmlProject::displayName() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return m_projectName;
|
|
|
|
}
|
|
|
|
|
2010-01-22 15:59:44 +01:00
|
|
|
QString QmlProject::id() const
|
|
|
|
{
|
|
|
|
return QLatin1String("QmlProjectManager.QmlProject");
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
Core::IFile *QmlProject::file() const
|
|
|
|
{
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
|
2009-05-07 15:43:59 +02:00
|
|
|
Manager *QmlProject::projectManager() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return m_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ProjectExplorer::Project *> QmlProject::dependsOn()
|
|
|
|
{
|
|
|
|
return QList<Project *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProject::isApplication() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-06 16:33:43 +02:00
|
|
|
bool QmlProject::hasBuildSettings() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
ProjectExplorer::BuildConfigWidget *QmlProject::createConfigWidget()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2009-05-07 12:27:52 +02:00
|
|
|
return 0;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
QList<ProjectExplorer::BuildConfigWidget*> QmlProject::subConfigWidgets()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2009-08-06 15:31:32 +02:00
|
|
|
return QList<ProjectExplorer::BuildConfigWidget*>();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
ProjectExplorer::IBuildConfigurationFactory *QmlProject::buildConfigurationFactory() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2009-09-24 16:02:02 +02:00
|
|
|
return 0;
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
QmlProjectNode *QmlProject::rootProjectNode() const
|
|
|
|
{
|
|
|
|
return m_rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::files(FilesMode) const
|
|
|
|
{
|
2010-01-18 16:32:14 +01:00
|
|
|
return files();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2009-07-03 16:46:01 +02:00
|
|
|
bool QmlProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
Project::restoreSettingsImpl(reader);
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
if (runConfigurations().isEmpty()) {
|
2009-10-08 18:37:18 +02:00
|
|
|
QmlRunConfiguration *runConf = new QmlRunConfiguration(this);
|
2009-05-07 12:27:52 +02:00
|
|
|
addRunConfiguration(runConf);
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
refresh(Everything);
|
2009-07-03 16:46:01 +02:00
|
|
|
return true;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer)
|
|
|
|
{
|
|
|
|
Project::saveSettingsImpl(writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QmlProjectFile
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QmlProjectFile::QmlProjectFile(QmlProject *parent, QString fileName)
|
|
|
|
: Core::IFile(parent),
|
|
|
|
m_project(parent),
|
|
|
|
m_fileName(fileName)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
QmlProjectFile::~QmlProjectFile()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool QmlProjectFile::save(const QString &)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProjectFile::fileName() const
|
|
|
|
{
|
|
|
|
return m_fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProjectFile::defaultPath() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProjectFile::suggestedFileName() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProjectFile::mimeType() const
|
|
|
|
{
|
|
|
|
return Constants::QMLMIMETYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectFile::isModified() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectFile::isReadOnly() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectFile::isSaveAsAllowed() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectFile::modified(ReloadBehavior *)
|
|
|
|
{
|
|
|
|
}
|
2009-05-04 13:38:03 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QmlRunConfiguration
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QmlRunConfiguration::QmlRunConfiguration(QmlProject *parent) :
|
|
|
|
ProjectExplorer::RunConfiguration(parent, QLatin1String(QML_RC_ID)),
|
|
|
|
m_debugServerPort(DEFAULT_DEBUG_SERVER_PORT)
|
|
|
|
{
|
|
|
|
ctor();
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunConfiguration::QmlRunConfiguration(QmlProject *parent, QmlRunConfiguration *source) :
|
|
|
|
ProjectExplorer::RunConfiguration(parent, source),
|
|
|
|
m_scriptFile(source->m_scriptFile),
|
|
|
|
m_qmlViewerCustomPath(source->m_qmlViewerCustomPath),
|
|
|
|
m_qmlViewerArgs(source->m_qmlViewerArgs),
|
|
|
|
m_debugServerPort(source->m_debugServerPort)
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
ctor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunConfiguration::ctor()
|
|
|
|
{
|
|
|
|
setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2010-01-12 10:38:23 +01:00
|
|
|
// prepend creator/bin dir to search path (only useful for special creator-qml package)
|
|
|
|
const QString searchPath = QCoreApplication::applicationDirPath()
|
2009-10-23 09:49:59 +02:00
|
|
|
+ Utils::SynchronousProcess::pathSeparator()
|
2010-01-12 10:38:23 +01:00
|
|
|
+ QString(qgetenv("PATH"));
|
2009-11-03 12:07:41 +01:00
|
|
|
m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, QLatin1String("qmlviewer"));
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
QmlRunConfiguration::~QmlRunConfiguration()
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QmlProject *QmlRunConfiguration::qmlProject() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
return static_cast<QmlProject *>(project());
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
QString QmlRunConfiguration::viewerPath() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2009-11-03 12:07:41 +01:00
|
|
|
if (!m_qmlViewerCustomPath.isEmpty())
|
|
|
|
return m_qmlViewerCustomPath;
|
|
|
|
return m_qmlViewerDefaultPath;
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
QStringList QmlRunConfiguration::viewerArguments() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
|
2009-09-30 11:36:34 +02:00
|
|
|
if (!m_qmlViewerArgs.isEmpty())
|
|
|
|
args.append(m_qmlViewerArgs);
|
|
|
|
|
2009-05-04 13:38:03 +02:00
|
|
|
const QString s = mainScript();
|
|
|
|
if (! s.isEmpty())
|
|
|
|
args.append(s);
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
QString QmlRunConfiguration::workingDirectory() const
|
2009-07-15 17:41:45 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
QFileInfo projectFile(qmlProject()->file()->fileName());
|
2009-12-16 16:39:39 +01:00
|
|
|
return projectFile.absolutePath();
|
2009-07-15 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2009-12-17 09:54:16 +01:00
|
|
|
uint QmlRunConfiguration::debugServerPort() const
|
|
|
|
{
|
|
|
|
return m_debugServerPort;
|
|
|
|
}
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
QWidget *QmlRunConfiguration::configurationWidget()
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2009-05-06 16:13:44 +02:00
|
|
|
QWidget *config = new QWidget;
|
|
|
|
QFormLayout *form = new QFormLayout(config);
|
|
|
|
|
2009-05-04 13:38:03 +02:00
|
|
|
QComboBox *combo = new QComboBox;
|
2009-05-06 16:13:44 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QDir projectDir = qmlProject()->projectDir();
|
2009-05-06 16:13:44 +02:00
|
|
|
QStringList files;
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
files.append(tr("<Current File>"));
|
|
|
|
|
|
|
|
int currentIndex = -1;
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
foreach (const QString &fn, qmlProject()->files()) {
|
2009-05-06 16:13:44 +02:00
|
|
|
QFileInfo fileInfo(fn);
|
|
|
|
if (fileInfo.suffix() != QLatin1String("qml"))
|
|
|
|
continue;
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
QString fileName = projectDir.relativeFilePath(fn);
|
|
|
|
if (fileName == m_scriptFile)
|
|
|
|
currentIndex = files.size();
|
|
|
|
|
|
|
|
files.append(fileName);
|
2009-05-06 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
combo->addItems(files);
|
2009-05-07 12:27:52 +02:00
|
|
|
if (currentIndex != -1)
|
|
|
|
combo->setCurrentIndex(currentIndex);
|
|
|
|
|
|
|
|
connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
|
2009-05-06 16:13:44 +02:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::PathChooser *qmlViewer = new Utils::PathChooser;
|
|
|
|
qmlViewer->setExpectedKind(Utils::PathChooser::Command);
|
2009-12-16 16:39:39 +01:00
|
|
|
qmlViewer->setPath(viewerPath());
|
2009-07-04 14:07:22 +02:00
|
|
|
connect(qmlViewer, SIGNAL(changed(QString)), this, SLOT(onQmlViewerChanged()));
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2009-09-30 11:36:34 +02:00
|
|
|
QLineEdit *qmlViewerArgs = new QLineEdit;
|
|
|
|
qmlViewerArgs->setText(m_qmlViewerArgs);
|
|
|
|
connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onQmlViewerArgsChanged()));
|
|
|
|
|
2009-12-17 09:54:16 +01:00
|
|
|
QSpinBox *debugPort = new QSpinBox;
|
|
|
|
debugPort->setMinimum(1024); // valid registered/dynamic/free ports according to http://www.iana.org/assignments/port-numbers
|
|
|
|
debugPort->setMaximum(65535);
|
|
|
|
debugPort->setValue(m_debugServerPort);
|
|
|
|
connect(debugPort, SIGNAL(valueChanged(int)), this, SLOT(onDebugServerPortChanged()));
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
form->addRow(tr("QML Viewer"), qmlViewer);
|
2009-09-30 11:36:34 +02:00
|
|
|
form->addRow(tr("QML Viewer arguments:"), qmlViewerArgs);
|
2009-05-07 14:47:01 +10:00
|
|
|
form->addRow(tr("Main QML File:"), combo);
|
2009-12-17 09:54:16 +01:00
|
|
|
form->addRow(tr("Debugging Port:"), debugPort);
|
2009-05-06 16:13:44 +02:00
|
|
|
|
|
|
|
return config;
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
QString QmlRunConfiguration::mainScript() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
|
|
|
if (m_scriptFile.isEmpty() || m_scriptFile == tr("<Current File>")) {
|
|
|
|
Core::EditorManager *editorManager = Core::ICore::instance()->editorManager();
|
|
|
|
if (Core::IEditor *editor = editorManager->currentEditor()) {
|
|
|
|
return editor->file()->fileName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
return qmlProject()->projectDir().absoluteFilePath(m_scriptFile);
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
void QmlRunConfiguration::setMainScript(const QString &scriptFile)
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
|
|
|
m_scriptFile = scriptFile;
|
|
|
|
}
|
|
|
|
|
2009-05-07 12:27:52 +02:00
|
|
|
void QmlRunConfiguration::onQmlViewerChanged()
|
|
|
|
{
|
2009-10-05 11:06:05 +02:00
|
|
|
if (Utils::PathChooser *chooser = qobject_cast<Utils::PathChooser *>(sender())) {
|
2009-11-03 12:07:41 +01:00
|
|
|
m_qmlViewerCustomPath = chooser->path();
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-30 11:36:34 +02:00
|
|
|
void QmlRunConfiguration::onQmlViewerArgsChanged()
|
|
|
|
{
|
|
|
|
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
|
|
|
|
m_qmlViewerArgs = lineEdit->text();
|
|
|
|
}
|
|
|
|
|
2009-12-17 09:54:16 +01:00
|
|
|
void QmlRunConfiguration::onDebugServerPortChanged()
|
|
|
|
{
|
|
|
|
if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender())) {
|
|
|
|
m_debugServerPort = spinBox->value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QVariantMap QmlRunConfiguration::toMap() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
map.insert(QLatin1String(QML_VIEWER_KEY), m_qmlViewerCustomPath);
|
|
|
|
map.insert(QLatin1String(QML_VIEWER_ARGUMENTS_KEY), m_qmlViewerArgs);
|
|
|
|
map.insert(QLatin1String(QML_MAINSCRIPT_KEY), m_scriptFile);
|
|
|
|
map.insert(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), m_debugServerPort);
|
|
|
|
return map;
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
bool QmlRunConfiguration::fromMap(const QVariantMap &map)
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
m_qmlViewerCustomPath = map.value(QLatin1String(QML_VIEWER_KEY)).toString();
|
|
|
|
m_qmlViewerArgs = map.value(QLatin1String(QML_VIEWER_ARGUMENTS_KEY)).toString();
|
|
|
|
m_scriptFile = map.value(QLatin1String(QML_MAINSCRIPT_KEY), tr("<Current File>")).toString();
|
|
|
|
m_debugServerPort = map.value(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), DEFAULT_DEBUG_SERVER_PORT).toUInt();
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
return RunConfiguration::fromMap(map);
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QmlRunConfigurationFactory
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QmlRunConfigurationFactory::QmlRunConfigurationFactory(QObject *parent) :
|
|
|
|
ProjectExplorer::IRunConfigurationFactory(parent)
|
2009-05-07 12:27:52 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunConfigurationFactory::~QmlRunConfigurationFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QStringList QmlRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *) const
|
2009-05-07 12:27:52 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
return QStringList() << QLatin1String(QML_RC_ID);
|
|
|
|
}
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QString QmlRunConfigurationFactory::displayNameForId(const QString &id) const
|
|
|
|
{
|
|
|
|
if (id == QLatin1String(QML_RC_ID))
|
|
|
|
return tr("Run QML Script");
|
|
|
|
return QString();
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
bool QmlRunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
|
2009-05-07 12:27:52 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
if (!qobject_cast<QmlProject *>(parent))
|
|
|
|
return false;
|
|
|
|
return id == QLatin1String(QML_RC_ID);
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
|
|
|
|
{
|
|
|
|
if (!canCreate(parent, id))
|
|
|
|
return 0;
|
|
|
|
QmlProject *project(static_cast<QmlProject *>(parent));
|
|
|
|
return new QmlRunConfiguration(project);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
|
|
|
|
{
|
|
|
|
QString id(idFromMap(map));
|
|
|
|
return canCreate(parent, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
|
2009-05-07 12:27:52 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
if (!canRestore(parent, map))
|
|
|
|
return 0;
|
|
|
|
QmlProject *project(static_cast<QmlProject *>(parent));
|
|
|
|
QmlRunConfiguration *rc(new QmlRunConfiguration(project));
|
|
|
|
if (rc->fromMap(map))
|
|
|
|
return rc;
|
|
|
|
delete rc;
|
|
|
|
return 0;
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
bool QmlRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, RunConfiguration *source) const
|
2009-05-07 12:27:52 +02:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
return canCreate(parent, source->id());
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::clone(ProjectExplorer::Project *parent, RunConfiguration *source)
|
|
|
|
{
|
|
|
|
if (!canClone(parent, source))
|
|
|
|
return 0;
|
|
|
|
QmlProject *project(static_cast<QmlProject *>(parent));
|
|
|
|
return new QmlRunConfiguration(project, qobject_cast<QmlRunConfiguration *>(source));
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QmlRunControl
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-12-17 09:54:16 +01:00
|
|
|
QmlRunControl::QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMode)
|
2009-12-18 15:32:36 +10:00
|
|
|
: RunControl(runConfiguration), m_debugMode(debugMode)
|
2009-12-16 16:39:39 +01:00
|
|
|
{
|
2009-12-17 09:54:16 +01:00
|
|
|
Environment environment = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
if (debugMode)
|
|
|
|
environment.set("QML_DEBUG_SERVER_PORT", QString::number(runConfiguration->debugServerPort()));
|
|
|
|
|
|
|
|
m_applicationLauncher.setEnvironment(environment.toStringList());
|
2009-12-16 16:39:39 +01:00
|
|
|
m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory());
|
|
|
|
|
|
|
|
m_executable = runConfiguration->viewerPath();
|
|
|
|
m_commandLineArguments = runConfiguration->viewerArguments();
|
|
|
|
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(applicationError(QString)),
|
|
|
|
this, SLOT(slotError(QString)));
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(appendOutput(QString)),
|
|
|
|
this, SLOT(slotAddToOutputWindow(QString)));
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
|
|
|
|
this, SLOT(processExited(int)));
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
|
2009-12-18 15:32:36 +10:00
|
|
|
this, SLOT(slotBringApplicationToForeground(qint64)));
|
2009-12-16 16:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControl::~QmlRunControl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::start()
|
|
|
|
{
|
|
|
|
m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable, m_commandLineArguments);
|
|
|
|
emit started();
|
|
|
|
emit addToOutputWindow(this, tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::stop()
|
|
|
|
{
|
|
|
|
m_applicationLauncher.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlRunControl::isRunning() const
|
|
|
|
{
|
|
|
|
return m_applicationLauncher.isRunning();
|
|
|
|
}
|
|
|
|
|
2009-12-18 15:32:36 +10:00
|
|
|
void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
|
|
|
|
{
|
|
|
|
bringApplicationToForeground(pid);
|
|
|
|
}
|
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
void QmlRunControl::slotError(const QString &err)
|
|
|
|
{
|
|
|
|
emit error(this, err);
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::slotAddToOutputWindow(const QString &line)
|
|
|
|
{
|
2010-01-12 10:50:37 +10:00
|
|
|
if (m_debugMode && line.startsWith("QmlDebugServer: Waiting for connection")) {
|
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
core->modeManager()->activateMode(QLatin1String("QML_INSPECT_MODE"));
|
|
|
|
}
|
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
emit addToOutputWindowInline(this, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlRunControl::processExited(int exitCode)
|
|
|
|
{
|
|
|
|
emit addToOutputWindow(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode));
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControlFactory::QmlRunControlFactory(QObject *parent)
|
2009-12-17 08:46:22 +01:00
|
|
|
: IRunControlFactory(parent)
|
2009-12-16 16:39:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRunControlFactory::~QmlRunControlFactory()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
|
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
Q_UNUSED(mode);
|
2009-12-17 09:54:16 +01:00
|
|
|
return (qobject_cast<QmlRunConfiguration*>(runConfiguration) != 0);
|
2009-12-16 16:39:39 +01:00
|
|
|
}
|
2009-05-07 12:27:52 +02:00
|
|
|
|
2009-12-16 16:39:39 +01:00
|
|
|
RunControl *QmlRunControlFactory::create(RunConfiguration *runConfiguration, const QString &mode)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
|
2009-12-17 09:54:16 +01:00
|
|
|
return new QmlRunControl(qobject_cast<QmlRunConfiguration *>(runConfiguration),
|
|
|
|
mode == ProjectExplorer::Constants::DEBUGMODE);
|
2009-12-16 16:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlRunControlFactory::displayName() const
|
|
|
|
{
|
|
|
|
return tr("Run");
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *QmlRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
|
|
|
|
{
|
|
|
|
Q_UNUSED(runConfiguration)
|
|
|
|
return new QLabel("TODO add Configuration widget");
|
|
|
|
}
|