From fdd85b7f337ef082fefa7f00a6025c1af6c0aded Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Tue, 16 Feb 2010 13:39:13 +0100
Subject: [PATCH] QmlProjectManager refactoring

Putting every class in it's own files + avoid "using namespace"
---
 src/plugins/qmlinspector/qmlinspectormode.cpp |   6 +-
 .../qmlprojectmanager/qmlnewprojectwizard.cpp |  10 +-
 src/plugins/qmlprojectmanager/qmlproject.cpp  | 510 +-----------------
 src/plugins/qmlprojectmanager/qmlproject.h    | 151 +-----
 .../qmlprojectmanager/qmlprojectfile.cpp      |  91 ++++
 .../qmlprojectmanager/qmlprojectfile.h        |  70 +++
 .../qmlprojectmanager/qmlprojectmanager.cpp   |   8 +-
 .../qmlprojectmanager/qmlprojectmanager.pro   |  13 +-
 .../qmlprojectmanagerconstants.h              |  47 ++
 .../qmlprojectmanager/qmlprojectnodes.cpp     |   8 +-
 .../qmlprojectmanager/qmlprojectnodes.h       |   6 +-
 .../qmlprojectmanager/qmlprojectplugin.cpp    |  15 +-
 .../qmlprojectrunconfiguration.cpp            | 238 ++++++++
 .../qmlprojectrunconfiguration.h              |  87 +++
 .../qmlprojectrunconfigurationfactory.cpp     | 113 ++++
 .../qmlprojectrunconfigurationfactory.h       |  61 +++
 .../qmlprojectruncontrol.cpp                  | 159 ++++++
 .../qmlprojectmanager/qmlprojectruncontrol.h  |  83 +++
 .../{qmltarget.cpp => qmlprojecttarget.cpp}   |  69 ++-
 .../{qmltarget.h => qmlprojecttarget.h}       |  31 +-
 .../qmlprojectmanager/qmlprojectwizard.cpp    |   7 +-
 .../qmlprojectmanager/qmltaskmanager.cpp      |   4 +-
 22 files changed, 1079 insertions(+), 708 deletions(-)
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectfile.cpp
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectfile.h
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.cpp
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.h
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
 create mode 100644 src/plugins/qmlprojectmanager/qmlprojectruncontrol.h
 rename src/plugins/qmlprojectmanager/{qmltarget.cpp => qmlprojecttarget.cpp} (57%)
 rename src/plugins/qmlprojectmanager/{qmltarget.h => qmlprojecttarget.h} (75%)

diff --git a/src/plugins/qmlinspector/qmlinspectormode.cpp b/src/plugins/qmlinspector/qmlinspectormode.cpp
index c4e568c6648..9cbdf393b73 100644
--- a/src/plugins/qmlinspector/qmlinspectormode.cpp
+++ b/src/plugins/qmlinspector/qmlinspectormode.cpp
@@ -62,7 +62,7 @@
 #include <projectexplorer/project.h>
 #include <projectexplorer/target.h>
 
-#include <qmlprojectmanager/qmlproject.h>
+#include <qmlprojectmanager/qmlprojectrunconfiguration.h>
 
 #include <QtCore/QStringList>
 #include <QtCore/QtPlugin>
@@ -186,8 +186,8 @@ void QmlInspectorMode::connectToViewer()
         return;
     }
 
-    QmlProjectManager::QmlRunConfiguration* config =
-            qobject_cast<QmlProjectManager::QmlRunConfiguration*>(project->activeTarget()->activeRunConfiguration());
+    QmlProjectManager::QmlProjectRunConfiguration* config =
+            qobject_cast<QmlProjectManager::QmlProjectRunConfiguration*>(project->activeTarget()->activeRunConfiguration());
     if (!config) {
         emit statusMessage(tr("Cannot find project run configuration, debugging canceled."));
         return;
diff --git a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
index 66fc7a905de..02064a4ff60 100644
--- a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
+++ b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp
@@ -37,11 +37,8 @@
 #include <QtCore/QTextStream>
 #include <QtCore/QCoreApplication>
 
-using namespace QmlProjectManager::Internal;
-
-//////////////////////////////////////////////////////////////////////////////
-// QmlNewProjectWizardDialog
-//////////////////////////////////////////////////////////////////////////////
+namespace QmlProjectManager {
+namespace Internal {
 
 QmlNewProjectWizardDialog::QmlNewProjectWizardDialog(QWidget *parent) :
     ProjectExplorer::BaseProjectWizardDialog(parent)
@@ -168,3 +165,6 @@ bool QmlNewProjectWizard::postGenerateFiles(const Core::GeneratedFiles &l, QStri
     return true;
 }
 
+} // namespace Internal
+} // namespace QmlProjectManager
+
diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp
index 6646e9caf06..7c7725dbd45 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.cpp
+++ b/src/plugins/qmlprojectmanager/qmlproject.cpp
@@ -28,73 +28,33 @@
 **************************************************************************/
 
 #include "qmlproject.h"
-#include "qmlprojectconstants.h"
-#include "qmltarget.h"
+#include "qmlprojectfile.h"
+#include "qmlprojectmanagerconstants.h"
+#include "fileformat/qmlprojectitem.h"
 
-#include <projectexplorer/toolchain.h>
-#include <projectexplorer/persistentsettings.h>
-#include <projectexplorer/projectexplorerconstants.h>
 #include <extensionsystem/pluginmanager.h>
-#include <utils/pathchooser.h>
-#include <utils/qtcassert.h>
-#include <coreplugin/icore.h>
-#include <coreplugin/editormanager/editormanager.h>
-#include <coreplugin/editormanager/ieditor.h>
-#include <coreplugin/modemanager.h>
-
+#include <projectexplorer/filewatcher.h>
 #include <qmljseditor/qmljsmodelmanagerinterface.h>
 
-#include <utils/synchronousprocess.h>
-
-#include <QtCore/QtDebug>
-#include <QtCore/QDir>
-#include <QtCore/QSettings>
-#include <QtCore/QProcess>
-#include <QtCore/QCoreApplication>
-
-#include <QtGui/QFormLayout>
-#include <QtGui/QMainWindow>
-#include <QtGui/QComboBox>
-#include <QtGui/QMessageBox>
-#include <QtGui/QLineEdit>
-#include <QtGui/QLabel>
-#include <QtGui/QSpinBox>
-
-#include <QtDeclarative/QmlComponent>
-
-using namespace QmlProjectManager;
-using namespace QmlProjectManager::Internal;
-using namespace ProjectExplorer;
-
-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");
+#include <QTextStream>
+#include <QmlComponent>
+#include <QtDebug>
 
-const int DEFAULT_DEBUG_SERVER_PORT(3768);
-} // namespace
+namespace QmlProjectManager {
 
-////////////////////////////////////////////////////////////////////////////////////
-// QmlProject
-////////////////////////////////////////////////////////////////////////////////////
-
-QmlProject::QmlProject(Manager *manager, const QString &fileName)
+QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName)
     : m_manager(manager),
       m_fileName(fileName),
       m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJSEditor::ModelManagerInterface>()),
       m_fileWatcher(new ProjectExplorer::FileWatcher(this)),
-      m_targetFactory(new QmlTargetFactory(this))
+      m_targetFactory(new Internal::QmlProjectTargetFactory(this))
 {
-    setSupportedTargetIds(QSet<QString>() << QLatin1String(VIEWER_TARGET_ID));
+    setSupportedTargetIds(QSet<QString>() << QLatin1String(Constants::QML_VIEWER_TARGET_ID));
     QFileInfo fileInfo(m_fileName);
     m_projectName = fileInfo.completeBaseName();
 
-    m_file = new QmlProjectFile(this, fileName);
-    m_rootNode = new QmlProjectNode(this, m_file);
+    m_file = new Internal::QmlProjectFile(this, fileName);
+    m_rootNode = new Internal::QmlProjectNode(this, m_file);
 
     m_fileWatcher->addFile(fileName),
     connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
@@ -247,7 +207,7 @@ Core::IFile *QmlProject::file() const
     return m_file;
 }
 
-Manager *QmlProject::projectManager() const
+Internal::Manager *QmlProject::projectManager() const
 {
     return m_manager;
 }
@@ -272,17 +232,17 @@ QList<ProjectExplorer::BuildConfigWidget*> QmlProject::subConfigWidgets()
     return QList<ProjectExplorer::BuildConfigWidget*>();
 }
 
-QmlTargetFactory *QmlProject::targetFactory() const
+Internal::QmlProjectTargetFactory *QmlProject::targetFactory() const
 {
     return m_targetFactory;
 }
 
-QmlTarget *QmlProject::activeTarget() const
+Internal::QmlProjectTarget *QmlProject::activeTarget() const
 {
-    return static_cast<QmlTarget *>(Project::activeTarget());
+    return static_cast<Internal::QmlProjectTarget *>(Project::activeTarget());
 }
 
-QmlProjectNode *QmlProject::rootProjectNode() const
+Internal::QmlProjectNode *QmlProject::rootProjectNode() const
 {
     return m_rootNode;
 }
@@ -298,7 +258,7 @@ bool QmlProject::fromMap(const QVariantMap &map)
         return false;
 
     if (targets().isEmpty()) {
-        Internal::QmlTarget *target(targetFactory()->create(this, QLatin1String(VIEWER_TARGET_ID)));
+        Internal::QmlProjectTarget *target(targetFactory()->create(this, QLatin1String(Constants::QML_VIEWER_TARGET_ID)));
         addTarget(target);
     }
 
@@ -306,434 +266,4 @@ bool QmlProject::fromMap(const QVariantMap &map)
     return true;
 }
 
-////////////////////////////////////////////////////////////////////////////////////
-// 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 *)
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////////
-// QmlRunConfiguration
-////////////////////////////////////////////////////////////////////////////////////
-
-QmlRunConfiguration::QmlRunConfiguration(QmlTarget *parent) :
-    ProjectExplorer::RunConfiguration(parent, QLatin1String(QML_RC_ID)),
-    m_debugServerPort(DEFAULT_DEBUG_SERVER_PORT)
-{
-    ctor();
-}
-
-QmlRunConfiguration::QmlRunConfiguration(QmlTarget *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)
-{
-    ctor();
-}
-
-void QmlRunConfiguration::ctor()
-{
-    setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
-
-    // prepend creator/bin dir to search path (only useful for special creator-qml package)
-    const QString searchPath = QCoreApplication::applicationDirPath()
-                               + Utils::SynchronousProcess::pathSeparator()
-                               + QString(qgetenv("PATH"));
-    m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, QLatin1String("qmlviewer"));
-}
-
-QmlRunConfiguration::~QmlRunConfiguration()
-{
-}
-
-QmlTarget *QmlRunConfiguration::qmlTarget() const
-{
-    return static_cast<Internal::QmlTarget *>(target());
-}
-
-QString QmlRunConfiguration::viewerPath() const
-{
-    if (!m_qmlViewerCustomPath.isEmpty())
-        return m_qmlViewerCustomPath;
-    return m_qmlViewerDefaultPath;
-}
-
-QStringList QmlRunConfiguration::viewerArguments() const
-{
-    QStringList args;
-
-    // arguments in .user file
-    if (!m_qmlViewerArgs.isEmpty())
-        args.append(m_qmlViewerArgs);
-
-    // arguments from .qmlproject file
-    foreach (const QString &libraryPath, qmlTarget()->qmlProject()->libraryPaths()) {
-        args.append(QLatin1String("-L"));
-        args.append(libraryPath);
-    }
-
-    const QString s = mainScript();
-    if (! s.isEmpty())
-        args.append(s);
-    return args;
-}
-
-QString QmlRunConfiguration::workingDirectory() const
-{
-    QFileInfo projectFile(qmlTarget()->qmlProject()->file()->fileName());
-    return projectFile.absolutePath();
-}
-
-uint QmlRunConfiguration::debugServerPort() const
-{
-    return m_debugServerPort;
-}
-
-QWidget *QmlRunConfiguration::configurationWidget()
-{
-    QWidget *config = new QWidget;
-    QFormLayout *form = new QFormLayout(config);
-
-    QComboBox *combo = new QComboBox;
-
-    QDir projectDir = qmlTarget()->qmlProject()->projectDir();
-    QStringList files;
-
-    files.append(tr("<Current File>"));
-
-    int currentIndex = -1;
-
-    foreach (const QString &fn, qmlTarget()->qmlProject()->files()) {
-        QFileInfo fileInfo(fn);
-        if (fileInfo.suffix() != QLatin1String("qml"))
-            continue;
-
-        QString fileName = projectDir.relativeFilePath(fn);
-        if (fileName == m_scriptFile)
-            currentIndex = files.size();
-
-        files.append(fileName);
-    }
-
-    combo->addItems(files);
-    if (currentIndex != -1)
-        combo->setCurrentIndex(currentIndex);
-
-    connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
-
-    Utils::PathChooser *qmlViewer = new Utils::PathChooser;
-    qmlViewer->setExpectedKind(Utils::PathChooser::Command);
-    qmlViewer->setPath(viewerPath());
-    connect(qmlViewer, SIGNAL(changed(QString)), this, SLOT(onQmlViewerChanged()));
-
-    QLineEdit *qmlViewerArgs = new QLineEdit;
-    qmlViewerArgs->setText(m_qmlViewerArgs);
-    connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onQmlViewerArgsChanged()));
-
-    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()));
-
-    form->addRow(tr("QML Viewer"), qmlViewer);
-    form->addRow(tr("QML Viewer arguments:"), qmlViewerArgs);
-    form->addRow(tr("Main QML File:"), combo);
-    form->addRow(tr("Debugging Port:"), debugPort);
-
-    return config;
-}
-
-QString QmlRunConfiguration::mainScript() const
-{
-    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();
-        }
-    }
-
-    return qmlTarget()->qmlProject()->projectDir().absoluteFilePath(m_scriptFile);
-}
-
-void QmlRunConfiguration::setMainScript(const QString &scriptFile)
-{
-    m_scriptFile = scriptFile;
-}
-
-void QmlRunConfiguration::onQmlViewerChanged()
-{
-    if (Utils::PathChooser *chooser = qobject_cast<Utils::PathChooser *>(sender())) {
-        m_qmlViewerCustomPath = chooser->path();
-    }
-}
-
-void QmlRunConfiguration::onQmlViewerArgsChanged()
-{
-    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
-        m_qmlViewerArgs = lineEdit->text();
-}
-
-void QmlRunConfiguration::onDebugServerPortChanged()
-{
-    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender())) {
-        m_debugServerPort = spinBox->value();
-    }
-}
-
-QVariantMap QmlRunConfiguration::toMap() const
-{
-    QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
-
-    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;
-}
-
-bool QmlRunConfiguration::fromMap(const QVariantMap &map)
-{
-    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();
-
-    return RunConfiguration::fromMap(map);
-}
-
-////////////////////////////////////////////////////////////////////////////////////
-// QmlRunConfigurationFactory
-////////////////////////////////////////////////////////////////////////////////////
-
-QmlRunConfigurationFactory::QmlRunConfigurationFactory(QObject *parent) :
-    ProjectExplorer::IRunConfigurationFactory(parent)
-{
-}
-
-QmlRunConfigurationFactory::~QmlRunConfigurationFactory()
-{
-}
-
-QStringList QmlRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
-{
-    if (!qobject_cast<QmlTarget *>(parent))
-        return QStringList();
-    return QStringList() << QLatin1String(QML_RC_ID);
-}
-
-QString QmlRunConfigurationFactory::displayNameForId(const QString &id) const
-{
-    if (id == QLatin1String(QML_RC_ID))
-        return tr("Run QML Script");
-    return QString();
-}
-
-bool QmlRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
-{
-    if (!qobject_cast<QmlTarget *>(parent))
-        return false;
-    return id == QLatin1String(QML_RC_ID);
-}
-
-ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
-{
-    if (!canCreate(parent, id))
-        return 0;
-    QmlTarget *qmlparent(static_cast<QmlTarget *>(parent));
-    return new QmlRunConfiguration(qmlparent);
-}
-
-bool QmlRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
-{
-    QString id(idFromMap(map));
-    return canCreate(parent, id);
-}
-
-ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
-{
-    if (!canRestore(parent, map))
-        return 0;
-    QmlTarget *qmlparent(static_cast<QmlTarget *>(parent));
-    QmlRunConfiguration *rc(new QmlRunConfiguration(qmlparent));
-    if (rc->fromMap(map))
-        return rc;
-    delete rc;
-    return 0;
-}
-
-bool QmlRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, RunConfiguration *source) const
-{
-    return canCreate(parent, source->id());
-}
-
-ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::clone(ProjectExplorer::Target *parent, RunConfiguration *source)
-{
-    if (!canClone(parent, source))
-        return 0;
-    QmlTarget *qmlparent(static_cast<QmlTarget *>(parent));
-    return new QmlRunConfiguration(qmlparent, qobject_cast<QmlRunConfiguration *>(source));
-}
-
-////////////////////////////////////////////////////////////////////////////////////
-// QmlRunControl
-////////////////////////////////////////////////////////////////////////////////////
-
-QmlRunControl::QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMode)
-    : RunControl(runConfiguration), m_debugMode(debugMode)
-{
-    Environment environment = ProjectExplorer::Environment::systemEnvironment();
-    if (debugMode)
-        environment.set("QML_DEBUG_SERVER_PORT", QString::number(runConfiguration->debugServerPort()));
-
-    m_applicationLauncher.setEnvironment(environment.toStringList());
-    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)),
-            this, SLOT(slotBringApplicationToForeground(qint64)));
-}
-
-QmlRunControl::~QmlRunControl()
-{
-}
-
-void QmlRunControl::start()
-{
-    m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable, m_commandLineArguments);
-    emit started();
-    emit addToOutputWindow(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
-                           m_commandLineArguments.join(QLatin1String(" "))));
-}
-
-void QmlRunControl::stop()
-{
-    m_applicationLauncher.stop();
-}
-
-bool QmlRunControl::isRunning() const
-{
-    return m_applicationLauncher.isRunning();
-}
-
-void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
-{
-    bringApplicationToForeground(pid);
-}
-
-void QmlRunControl::slotError(const QString &err)
-{
-    emit error(this, err);
-    emit finished();
-}
-
-void QmlRunControl::slotAddToOutputWindow(const QString &line)
-{
-    if (m_debugMode && line.startsWith("QmlDebugServer: Waiting for connection")) {
-        Core::ICore *core = Core::ICore::instance();
-        core->modeManager()->activateMode(QLatin1String("QML_INSPECT_MODE"));
-    }
-
-    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)
-    : IRunControlFactory(parent)
-{
-}
-
-QmlRunControlFactory::~QmlRunControlFactory()
-{
-
-}
-
-bool QmlRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
-{
-    Q_UNUSED(mode);
-    return (qobject_cast<QmlRunConfiguration*>(runConfiguration) != 0);
-}
-
-RunControl *QmlRunControlFactory::create(RunConfiguration *runConfiguration, const QString &mode)
-{
-    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
-    return new QmlRunControl(qobject_cast<QmlRunConfiguration *>(runConfiguration),
-                             mode == ProjectExplorer::Constants::DEBUGMODE);
-}
-
-QString QmlRunControlFactory::displayName() const
-{
-    return tr("Run");
-}
-
-QWidget *QmlRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
-{
-    Q_UNUSED(runConfiguration)
-    return new QLabel("TODO add Configuration widget");
-}
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h
index b5a9d3238be..c93bab4063b 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.h
+++ b/src/plugins/qmlprojectmanager/qmlproject.h
@@ -31,113 +31,30 @@
 #define QMLPROJECT_H
 
 #include "qmlprojectmanager.h"
-#include "qmlprojectnodes.h"
 #include "qmlprojectmanager_global.h"
-#include "qmltarget.h"
-#include "fileformat/qmlprojectitem.h"
+#include "qmlprojectnodes.h"
+#include "qmlprojecttarget.h"
 
 #include <projectexplorer/project.h>
-#include <projectexplorer/projectnodes.h>
-#include <projectexplorer/buildstep.h>
-#include <projectexplorer/applicationrunconfiguration.h>
-#include <projectexplorer/filewatcher.h>
-#include <coreplugin/ifile.h>
 
-#include <QtCore/QDir>
 #include <QtDeclarative/QmlEngine>
 
 namespace QmlJSEditor {
 class ModelManagerInterface;
 }
 
-namespace QmlProjectManager {
-class QmlProject;
-class QmlRunConfiguration;
-
-namespace Internal {
-
-class QmlProjectFile : public Core::IFile
-{
-    Q_OBJECT
-
-public:
-    QmlProjectFile(QmlProject *parent, QString fileName);
-    virtual ~QmlProjectFile();
-
-    virtual bool save(const QString &fileName = QString());
-    virtual QString fileName() const;
-
-    virtual QString defaultPath() const;
-    virtual QString suggestedFileName() const;
-    virtual QString mimeType() const;
-
-    virtual bool isModified() const;
-    virtual bool isReadOnly() const;
-    virtual bool isSaveAsAllowed() const;
-
-    virtual void modified(ReloadBehavior *behavior);
-
-private:
-    QmlProject *m_project;
-    QString m_fileName;
-};
-
-class QmlRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
-{
-    Q_OBJECT
-
-public:
-    explicit QmlRunConfigurationFactory(QObject *parent = 0);
-    ~QmlRunConfigurationFactory();
-
-    QStringList availableCreationIds(ProjectExplorer::Target *parent) const;
-    QString displayNameForId(const QString &id) const;
-
-    bool canCreate(ProjectExplorer::Target *parent, const QString &id) const;
-    ProjectExplorer::RunConfiguration *create(ProjectExplorer::Target *parent, const QString &id);
-    bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
-    ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Target *parent, const QVariantMap &map);
-    bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const;
-    ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source);
-};
-
-class QmlRunControl : public ProjectExplorer::RunControl {
-    Q_OBJECT
-public:
-    explicit QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMode);
-    virtual ~QmlRunControl ();
-
-    // RunControl
-    virtual void start();
-    virtual void stop();
-    virtual bool isRunning() const;
+namespace ProjectExplorer {
+class FileWatcher;
+}
 
-private slots:
-    void processExited(int exitCode);
-    void slotBringApplicationToForeground(qint64 pid);
-    void slotAddToOutputWindow(const QString &line);
-    void slotError(const QString & error);
+namespace QmlProjectManager {
 
-private:
-    ProjectExplorer::ApplicationLauncher m_applicationLauncher;
+class QmlProjectItem;
 
-    QString m_executable;
-    QStringList m_commandLineArguments;
-    bool m_debugMode;
-};
+namespace Internal {
 
-class QmlRunControlFactory : public ProjectExplorer::IRunControlFactory {
-    Q_OBJECT
-public:
-    explicit QmlRunControlFactory(QObject *parent = 0);
-    virtual ~QmlRunControlFactory();
-
-    // IRunControlFactory
-    virtual bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const;
-    virtual ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode);
-    virtual QString displayName() const;
-    virtual QWidget *configurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
-};
+class QmlProjectFile;
+class QmlProjectNode;
 
 } // namespace Internal
 
@@ -155,8 +72,8 @@ public:
     QString id() const;
     Core::IFile *file() const;
     Internal::Manager *projectManager() const;
-    Internal::QmlTargetFactory *targetFactory() const;
-    Internal::QmlTarget *activeTarget() const;
+    Internal::QmlProjectTargetFactory *targetFactory() const;
+    Internal::QmlProjectTarget *activeTarget() const;
 
     QList<ProjectExplorer::Project *> dependsOn();
 
@@ -209,49 +126,7 @@ private:
     ProjectExplorer::FileWatcher *m_fileWatcher;
 
     Internal::QmlProjectNode *m_rootNode;
-    Internal::QmlTargetFactory *m_targetFactory;
-};
-
-class QMLPROJECTMANAGER_EXPORT QmlRunConfiguration : public ProjectExplorer::RunConfiguration
-{
-    Q_OBJECT
-    friend class Internal::QmlRunConfigurationFactory;
-
-public:
-    QmlRunConfiguration(Internal::QmlTarget *parent);
-    virtual ~QmlRunConfiguration();
-
-    Internal::QmlTarget *qmlTarget() const;
-
-    QString viewerPath() const;
-    QStringList viewerArguments() const;
-    QString workingDirectory() const;
-    uint debugServerPort() const;
-
-    // RunConfiguration
-    virtual QWidget *configurationWidget();
-
-    QVariantMap toMap() const;
-
-private slots:
-    QString mainScript() const;
-    void setMainScript(const QString &scriptFile);
-    void onQmlViewerChanged();
-    void onQmlViewerArgsChanged();
-    void onDebugServerPortChanged();
-
-protected:
-    QmlRunConfiguration(Internal::QmlTarget *parent, QmlRunConfiguration *source);
-    virtual bool fromMap(const QVariantMap &map);
-
-private:
-    void ctor();
-
-    QString m_scriptFile;
-    QString m_qmlViewerCustomPath;
-    QString m_qmlViewerDefaultPath;
-    QString m_qmlViewerArgs;
-    uint m_debugServerPort;
+    Internal::QmlProjectTargetFactory *m_targetFactory;
 };
 
 } // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectfile.cpp b/src/plugins/qmlprojectmanager/qmlprojectfile.cpp
new file mode 100644
index 00000000000..5ec3b2010bb
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectfile.cpp
@@ -0,0 +1,91 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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 "qmlprojectfile.h"
+#include "qmlproject.h"
+#include "qmlprojectconstants.h"
+
+namespace QmlProjectManager {
+namespace Internal {
+
+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 *)
+{
+}
+
+} // namespace Internal
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectfile.h b/src/plugins/qmlprojectmanager/qmlprojectfile.h
new file mode 100644
index 00000000000..57195533ada
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectfile.h
@@ -0,0 +1,70 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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.
+**
+**************************************************************************/
+
+#ifndef QMLPROJECTFILE_H
+#define QMLPROJECTFILE_H
+
+#include <coreplugin/ifile.h>
+
+namespace QmlProjectManager {
+
+class QmlProject;
+
+namespace Internal {
+
+class QmlProjectFile : public Core::IFile
+{
+    Q_OBJECT
+
+public:
+    QmlProjectFile(QmlProject *parent, QString fileName);
+    virtual ~QmlProjectFile();
+
+    virtual bool save(const QString &fileName = QString());
+    virtual QString fileName() const;
+
+    virtual QString defaultPath() const;
+    virtual QString suggestedFileName() const;
+    virtual QString mimeType() const;
+
+    virtual bool isModified() const;
+    virtual bool isReadOnly() const;
+    virtual bool isSaveAsAllowed() const;
+
+    virtual void modified(ReloadBehavior *behavior);
+
+private:
+    QmlProject *m_project;
+    QString m_fileName;
+};
+
+} // namespace Internal
+} // namespace QmlProjectManager
+
+#endif // QMLPROJECTFILE_H
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.cpp b/src/plugins/qmlprojectmanager/qmlprojectmanager.cpp
index 09cfebe671b..3d352876b98 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.cpp
@@ -32,6 +32,7 @@
 #include "qmlproject.h"
 
 #include <coreplugin/icore.h>
+#include <coreplugin/ifile.h>
 #include <coreplugin/uniqueidmanager.h>
 #include <coreplugin/messagemanager.h>
 #include <projectexplorer/projectexplorerconstants.h>
@@ -40,8 +41,8 @@
 
 #include <QtDebug>
 
-using namespace QmlProjectManager;
-using namespace QmlProjectManager::Internal;
+namespace QmlProjectManager {
+namespace Internal {
 
 Manager::Manager()
 {
@@ -101,3 +102,6 @@ void Manager::notifyChanged(const QString &fileName)
         }
     }
 }
+
+} // namespace Internal
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
index ba56ece28d1..3361cc92e9e 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
@@ -14,18 +14,27 @@ HEADERS += qmlproject.h \
     qmlprojectconstants.h \
     qmlprojectnodes.h \
     qmlprojectwizard.h \
+    qmlprojectfile.h \
+    qmlprojectruncontrol.h \
+    qmlprojectrunconfiguration.h \
+    qmlprojectrunconfigurationfactory.h \
     qmlnewprojectwizard.h \
     qmltaskmanager.h \
     qmlprojectmanager_global.h \
-    qmltarget.h
+    qmlprojectmanagerconstants.h \
+    qmlprojecttarget.h
 SOURCES += qmlproject.cpp \
     qmlprojectplugin.cpp \
     qmlprojectmanager.cpp \
     qmlprojectnodes.cpp \
     qmlprojectwizard.cpp \
+    qmlprojectfile.cpp \
+    qmlprojectruncontrol.cpp \
+    qmlprojectrunconfiguration.cpp \
+    qmlprojectrunconfigurationfactory.cpp \
     qmlnewprojectwizard.cpp \
     qmltaskmanager.cpp \
-    qmltarget.cpp
+    qmlprojecttarget.cpp
 RESOURCES += qmlproject.qrc
 
 OTHER_FILES += QmlProjectManager.pluginspec
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h b/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h
new file mode 100644
index 00000000000..f02bf00e408
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h
@@ -0,0 +1,47 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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 <qglobal.h>
+
+namespace QmlProjectManager {
+namespace Constants {
+
+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_VIEWER_TARGET_ID("QmlProjectManager.QmlTarget");
+const char * const QML_VIEWER_TARGET_DISPLAY_NAME("QML Viewer");
+const char * const QML_MAINSCRIPT_KEY("QmlProjectManager.QmlRunConfiguration.MainScript");
+const char * const QML_DEBUG_SERVER_PORT_KEY("QmlProjectManager.QmlRunConfiguration.DebugServerPort");
+
+const int QML_DEFAULT_DEBUG_SERVER_PORT(3768);
+
+} // namespace Constants
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp b/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp
index b1ff8f8c5fb..163e2e7b543 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp
@@ -36,9 +36,10 @@
 
 #include <QFileInfo>
 #include <QDir>
+#include <QTextStream>
 
-using namespace QmlProjectManager;
-using namespace QmlProjectManager::Internal;
+namespace QmlProjectManager {
+namespace Internal {
 
 QmlProjectNode::QmlProjectNode(QmlProject *project, Core::IFile *projectFile)
     : ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absoluteFilePath()),
@@ -235,3 +236,6 @@ bool QmlProjectNode::renameFile(const ProjectExplorer::FileType fileType,
     Q_UNUSED(newFilePath)
     return false;
 }
+
+} // namespace Internal
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectnodes.h b/src/plugins/qmlprojectmanager/qmlprojectnodes.h
index 04e4be3fbd5..71fef556316 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectnodes.h
+++ b/src/plugins/qmlprojectmanager/qmlprojectnodes.h
@@ -27,8 +27,8 @@
 **
 **************************************************************************/
 
-#ifndef QMLPROJECTNODE_H
-#define QMLPROJECTNODE_H
+#ifndef QMLPROJECTNODES_H
+#define QMLPROJECTNODES_H
 
 #include <projectexplorer/projectnodes.h>
 
@@ -89,4 +89,4 @@ private:
 } // namespace Internal
 } // namespace QmlProjectManager
 
-#endif // QMLPROJECTNODE_H
+#endif // QMLPROJECTNODES_H
diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
index 7340bdc4f44..89335817dc2 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
@@ -33,6 +33,8 @@
 #include "qmlnewprojectwizard.h"
 #include "qmlprojectconstants.h"
 #include "qmlproject.h"
+#include "qmlprojectrunconfigurationfactory.h"
+#include "qmlprojectruncontrol.h"
 #include "qmltaskmanager.h"
 
 #include <extensionsystem/pluginmanager.h>
@@ -47,8 +49,8 @@
 
 #include <QtCore/QtPlugin>
 
-using namespace QmlProjectManager;
-using namespace QmlProjectManager::Internal;
+namespace QmlProjectManager {
+namespace Internal {
 
 QmlProjectPlugin::QmlProjectPlugin() :
         m_qmlTaskManager(0)
@@ -75,8 +77,8 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
     m_qmlTaskManager = new QmlTaskManager(this);
 
     addAutoReleasedObject(manager);
-    addAutoReleasedObject(new QmlRunConfigurationFactory);
-    addAutoReleasedObject(new QmlRunControlFactory);
+    addAutoReleasedObject(new Internal::QmlProjectRunConfigurationFactory);
+    addAutoReleasedObject(new Internal::QmlRunControlFactory);
     addAutoReleasedObject(new QmlNewProjectWizard);
     addAutoReleasedObject(new QmlProjectWizard);
     return true;
@@ -94,4 +96,7 @@ void QmlProjectPlugin::extensionsInitialized()
             m_qmlTaskManager, SLOT(documentUpdated(QmlJS::Document::Ptr)));
 }
 
-Q_EXPORT_PLUGIN(QmlProjectPlugin)
+} // namespace Internal
+} // namespace QmlProjectManager
+
+Q_EXPORT_PLUGIN(QmlProjectManager::Internal::QmlProjectPlugin)
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
new file mode 100644
index 00000000000..4a03f98a795
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
@@ -0,0 +1,238 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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 "qmlproject.h"
+#include "qmlprojectmanagerconstants.h"
+#include "qmlprojectrunconfiguration.h"
+#include "qmlprojecttarget.h"
+
+#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/editormanager/ieditor.h>
+#include <coreplugin/icore.h>
+#include <coreplugin/ifile.h>
+#include <utils/synchronousprocess.h>
+#include <utils/pathchooser.h>
+
+#include <QFormLayout>
+#include <QComboBox>
+#include <QCoreApplication>
+#include <QLineEdit>
+#include <QSpinBox>
+
+namespace QmlProjectManager {
+
+QmlProjectRunConfiguration::QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent) :
+    ProjectExplorer::RunConfiguration(parent, QLatin1String(Constants::QML_RC_ID)),
+    m_debugServerPort(Constants::QML_DEFAULT_DEBUG_SERVER_PORT)
+{
+    ctor();
+}
+
+QmlProjectRunConfiguration::QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent, QmlProjectRunConfiguration *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)
+{
+    ctor();
+}
+
+void QmlProjectRunConfiguration::ctor()
+{
+    setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name."));
+
+    // prepend creator/bin dir to search path (only useful for special creator-qml package)
+    const QString searchPath = QCoreApplication::applicationDirPath()
+                               + Utils::SynchronousProcess::pathSeparator()
+                               + QString(qgetenv("PATH"));
+    m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, QLatin1String("qmlviewer"));
+}
+
+QmlProjectRunConfiguration::~QmlProjectRunConfiguration()
+{
+}
+
+Internal::QmlProjectTarget *QmlProjectRunConfiguration::qmlTarget() const
+{
+    return static_cast<Internal::QmlProjectTarget *>(target());
+}
+
+QString QmlProjectRunConfiguration::viewerPath() const
+{
+    if (!m_qmlViewerCustomPath.isEmpty())
+        return m_qmlViewerCustomPath;
+    return m_qmlViewerDefaultPath;
+}
+
+QStringList QmlProjectRunConfiguration::viewerArguments() const
+{
+    QStringList args;
+
+    // arguments in .user file
+    if (!m_qmlViewerArgs.isEmpty())
+        args.append(m_qmlViewerArgs);
+
+    // arguments from .qmlproject file
+    foreach (const QString &libraryPath, qmlTarget()->qmlProject()->libraryPaths()) {
+        args.append(QLatin1String("-L"));
+        args.append(libraryPath);
+    }
+
+    const QString s = mainScript();
+    if (! s.isEmpty())
+        args.append(s);
+    return args;
+}
+
+QString QmlProjectRunConfiguration::workingDirectory() const
+{
+    QFileInfo projectFile(qmlTarget()->qmlProject()->file()->fileName());
+    return projectFile.absolutePath();
+}
+
+uint QmlProjectRunConfiguration::debugServerPort() const
+{
+    return m_debugServerPort;
+}
+
+QWidget *QmlProjectRunConfiguration::configurationWidget()
+{
+    QWidget *config = new QWidget;
+    QFormLayout *form = new QFormLayout(config);
+
+    QComboBox *combo = new QComboBox;
+
+    QDir projectDir = qmlTarget()->qmlProject()->projectDir();
+    QStringList files;
+
+    files.append(tr("<Current File>"));
+
+    int currentIndex = -1;
+
+    foreach (const QString &fn, qmlTarget()->qmlProject()->files()) {
+        QFileInfo fileInfo(fn);
+        if (fileInfo.suffix() != QLatin1String("qml"))
+            continue;
+
+        QString fileName = projectDir.relativeFilePath(fn);
+        if (fileName == m_scriptFile)
+            currentIndex = files.size();
+
+        files.append(fileName);
+    }
+
+    combo->addItems(files);
+    if (currentIndex != -1)
+        combo->setCurrentIndex(currentIndex);
+
+    connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
+
+    Utils::PathChooser *qmlViewer = new Utils::PathChooser;
+    qmlViewer->setExpectedKind(Utils::PathChooser::Command);
+    qmlViewer->setPath(viewerPath());
+    connect(qmlViewer, SIGNAL(changed(QString)), this, SLOT(onQmlViewerChanged()));
+
+    QLineEdit *qmlViewerArgs = new QLineEdit;
+    qmlViewerArgs->setText(m_qmlViewerArgs);
+    connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onQmlViewerArgsChanged()));
+
+    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()));
+
+    form->addRow(tr("QML Viewer"), qmlViewer);
+    form->addRow(tr("QML Viewer arguments:"), qmlViewerArgs);
+    form->addRow(tr("Main QML File:"), combo);
+    form->addRow(tr("Debugging Port:"), debugPort);
+
+    return config;
+}
+
+QString QmlProjectRunConfiguration::mainScript() const
+{
+    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();
+        }
+    }
+
+    return qmlTarget()->qmlProject()->projectDir().absoluteFilePath(m_scriptFile);
+}
+
+void QmlProjectRunConfiguration::setMainScript(const QString &scriptFile)
+{
+    m_scriptFile = scriptFile;
+}
+
+void QmlProjectRunConfiguration::onQmlViewerChanged()
+{
+    if (Utils::PathChooser *chooser = qobject_cast<Utils::PathChooser *>(sender())) {
+        m_qmlViewerCustomPath = chooser->path();
+    }
+}
+
+void QmlProjectRunConfiguration::onQmlViewerArgsChanged()
+{
+    if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
+        m_qmlViewerArgs = lineEdit->text();
+}
+
+void QmlProjectRunConfiguration::onDebugServerPortChanged()
+{
+    if (QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender())) {
+        m_debugServerPort = spinBox->value();
+    }
+}
+
+QVariantMap QmlProjectRunConfiguration::toMap() const
+{
+    QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
+
+    map.insert(QLatin1String(Constants::QML_VIEWER_KEY), m_qmlViewerCustomPath);
+    map.insert(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY), m_qmlViewerArgs);
+    map.insert(QLatin1String(Constants::QML_MAINSCRIPT_KEY),  m_scriptFile);
+    map.insert(QLatin1String(Constants::QML_DEBUG_SERVER_PORT_KEY), m_debugServerPort);
+    return map;
+}
+
+bool QmlProjectRunConfiguration::fromMap(const QVariantMap &map)
+{
+    m_qmlViewerCustomPath = map.value(QLatin1String(Constants::QML_VIEWER_KEY)).toString();
+    m_qmlViewerArgs = map.value(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY)).toString();
+    m_scriptFile = map.value(QLatin1String(Constants::QML_MAINSCRIPT_KEY), tr("<Current File>")).toString();
+    m_debugServerPort = map.value(QLatin1String(Constants::QML_DEBUG_SERVER_PORT_KEY), Constants::QML_DEFAULT_DEBUG_SERVER_PORT).toUInt();
+
+    return RunConfiguration::fromMap(map);
+}
+
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
new file mode 100644
index 00000000000..6e17c7dc3d2
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
@@ -0,0 +1,87 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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.
+**
+**************************************************************************/
+
+#ifndef QMLPROJECTRUNCONFIGURATION_H
+#define QMLPROJECTRUNCONFIGURATION_H
+
+#include "qmlprojectmanager_global.h"
+#include <projectexplorer/runconfiguration.h>
+
+namespace QmlProjectManager {
+
+namespace Internal {
+class QmlProjectTarget;
+class QmlProjectRunConfigurationFactory;
+}
+
+class QMLPROJECTMANAGER_EXPORT QmlProjectRunConfiguration : public ProjectExplorer::RunConfiguration
+{
+    Q_OBJECT
+    friend class Internal::QmlProjectRunConfigurationFactory;
+
+public:
+    QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent);
+    virtual ~QmlProjectRunConfiguration();
+
+    Internal::QmlProjectTarget *qmlTarget() const;
+
+    QString viewerPath() const;
+    QStringList viewerArguments() const;
+    QString workingDirectory() const;
+    uint debugServerPort() const;
+
+    // RunConfiguration
+    virtual QWidget *configurationWidget();
+
+    QVariantMap toMap() const;
+
+private slots:
+    QString mainScript() const;
+    void setMainScript(const QString &scriptFile);
+    void onQmlViewerChanged();
+    void onQmlViewerArgsChanged();
+    void onDebugServerPortChanged();
+
+protected:
+    QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent, QmlProjectRunConfiguration *source);
+    virtual bool fromMap(const QVariantMap &map);
+
+private:
+    void ctor();
+
+    QString m_scriptFile;
+    QString m_qmlViewerCustomPath;
+    QString m_qmlViewerDefaultPath;
+    QString m_qmlViewerArgs;
+    uint m_debugServerPort;
+};
+
+} // namespace QmlProjectManager
+
+#endif // QMLPROJECTRUNCONFIGURATION_H
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.cpp
new file mode 100644
index 00000000000..2f325601a12
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.cpp
@@ -0,0 +1,113 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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 "qmlprojectmanagerconstants.h"
+#include "qmlprojectrunconfiguration.h"
+#include "qmlprojectrunconfigurationfactory.h"
+#include "qmlprojecttarget.h"
+
+#include <projectexplorer/projectconfiguration.h>
+#include <projectexplorer/runconfiguration.h>
+
+namespace QmlProjectManager {
+namespace Internal {
+
+QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory(QObject *parent) :
+    ProjectExplorer::IRunConfigurationFactory(parent)
+{
+}
+
+QmlProjectRunConfigurationFactory::~QmlProjectRunConfigurationFactory()
+{
+}
+
+QStringList QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
+{
+    if (!qobject_cast<QmlProjectTarget *>(parent))
+        return QStringList();
+    return QStringList() << QLatin1String(Constants::QML_RC_ID);
+}
+
+QString QmlProjectRunConfigurationFactory::displayNameForId(const QString &id) const
+{
+    if (id == QLatin1String(Constants::QML_RC_ID))
+        return tr("Run QML Script");
+    return QString();
+}
+
+bool QmlProjectRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
+{
+    if (!qobject_cast<QmlProjectTarget *>(parent))
+        return false;
+    return id == QLatin1String(Constants::QML_RC_ID);
+}
+
+ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
+{
+    if (!canCreate(parent, id))
+        return 0;
+    QmlProjectTarget *qmlparent(static_cast<QmlProjectTarget *>(parent));
+    return new QmlProjectRunConfiguration(qmlparent);
+}
+
+bool QmlProjectRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
+{
+    QString id(ProjectExplorer::idFromMap(map));
+    return canCreate(parent, id);
+}
+
+ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
+{
+    if (!canRestore(parent, map))
+        return 0;
+    QmlProjectTarget *qmlparent(static_cast<QmlProjectTarget *>(parent));
+    QmlProjectRunConfiguration *rc(new QmlProjectRunConfiguration(qmlparent));
+    if (rc->fromMap(map))
+        return rc;
+    delete rc;
+    return 0;
+}
+
+bool QmlProjectRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
+{
+    return canCreate(parent, source->id());
+}
+
+ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::clone(ProjectExplorer::Target *parent,
+                                                                     ProjectExplorer::RunConfiguration *source)
+{
+    if (!canClone(parent, source))
+        return 0;
+    QmlProjectTarget *qmlparent(static_cast<QmlProjectTarget *>(parent));
+    return new QmlProjectRunConfiguration(qmlparent, qobject_cast<QmlProjectRunConfiguration *>(source));
+}
+
+} // namespace Internal
+} // namespace QmlProjectManager
+
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.h
new file mode 100644
index 00000000000..e305153de44
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationfactory.h
@@ -0,0 +1,61 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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.
+**
+**************************************************************************/
+
+#ifndef QMLPROJECTRUNCONFIGURATIONFACTORY_H
+#define QMLPROJECTRUNCONFIGURATIONFACTORY_H
+
+#include <projectexplorer/runconfiguration.h>
+
+namespace QmlProjectManager {
+namespace Internal {
+
+class QmlProjectRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
+{
+    Q_OBJECT
+
+public:
+    explicit QmlProjectRunConfigurationFactory(QObject *parent = 0);
+    ~QmlProjectRunConfigurationFactory();
+
+    QStringList availableCreationIds(ProjectExplorer::Target *parent) const;
+    QString displayNameForId(const QString &id) const;
+
+    bool canCreate(ProjectExplorer::Target *parent, const QString &id) const;
+    ProjectExplorer::RunConfiguration *create(ProjectExplorer::Target *parent, const QString &id);
+    bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
+    ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Target *parent, const QVariantMap &map);
+    bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const;
+    ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source);
+};
+
+} // namespace Internal
+} // namespace QmlProjectManager
+
+
+#endif // QMLPROJECTRUNCONFIGURATIONFACTORY_H
diff --git a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
new file mode 100644
index 00000000000..b4bc07c2eb9
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp
@@ -0,0 +1,159 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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"
+
+#include <coreplugin/icore.h>
+#include <coreplugin/modemanager.h>
+#include <projectexplorer/environment.h>
+#include <projectexplorer/projectexplorerconstants.h>
+#include <projectexplorer/applicationlauncher.h>
+#include <utils/qtcassert.h>
+
+#include <QDir>
+#include <QLabel>
+
+using ProjectExplorer::RunConfiguration;
+using ProjectExplorer::RunControl;
+
+namespace QmlProjectManager {
+namespace Internal {
+
+QmlRunControl::QmlRunControl(QmlProjectRunConfiguration *runConfiguration, bool debugMode)
+    : RunControl(runConfiguration), m_debugMode(debugMode)
+{
+    ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment();
+    if (debugMode)
+        environment.set("QML_DEBUG_SERVER_PORT", QString::number(runConfiguration->debugServerPort()));
+
+    m_applicationLauncher.setEnvironment(environment.toStringList());
+    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)),
+            this, SLOT(slotBringApplicationToForeground(qint64)));
+}
+
+QmlRunControl::~QmlRunControl()
+{
+}
+
+void QmlRunControl::start()
+{
+    m_applicationLauncher.start(ProjectExplorer::ApplicationLauncher::Gui, m_executable,
+                                m_commandLineArguments);
+    emit started();
+    emit addToOutputWindow(this, tr("Starting %1 %2").arg(QDir::toNativeSeparators(m_executable),
+                           m_commandLineArguments.join(QLatin1String(" "))));
+}
+
+void QmlRunControl::stop()
+{
+    m_applicationLauncher.stop();
+}
+
+bool QmlRunControl::isRunning() const
+{
+    return m_applicationLauncher.isRunning();
+}
+
+void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
+{
+    bringApplicationToForeground(pid);
+}
+
+void QmlRunControl::slotError(const QString &err)
+{
+    emit error(this, err);
+    emit finished();
+}
+
+void QmlRunControl::slotAddToOutputWindow(const QString &line)
+{
+    if (m_debugMode && line.startsWith("QmlDebugServer: Waiting for connection")) {
+        Core::ICore *core = Core::ICore::instance();
+        core->modeManager()->activateMode(QLatin1String("QML_INSPECT_MODE"));
+    }
+
+    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)
+    : IRunControlFactory(parent)
+{
+}
+
+QmlRunControlFactory::~QmlRunControlFactory()
+{
+}
+
+bool QmlRunControlFactory::canRun(RunConfiguration *runConfiguration,
+                                  const QString &mode) const
+{
+    Q_UNUSED(mode);
+    return (qobject_cast<QmlProjectRunConfiguration*>(runConfiguration) != 0);
+}
+
+RunControl *QmlRunControlFactory::create(RunConfiguration *runConfiguration,
+                                         const QString &mode)
+{
+    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
+    return new QmlRunControl(qobject_cast<QmlProjectRunConfiguration *>(runConfiguration),
+                             mode == ProjectExplorer::Constants::DEBUGMODE);
+}
+
+QString QmlRunControlFactory::displayName() const
+{
+    return tr("Run");
+}
+
+QWidget *QmlRunControlFactory::configurationWidget(RunConfiguration *runConfiguration)
+{
+    Q_UNUSED(runConfiguration)
+    return new QLabel("TODO add Configuration widget");
+}
+
+} // namespace Internal
+} // namespace QmlProjectManager
+
diff --git a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.h b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.h
new file mode 100644
index 00000000000..a8b27ddbeff
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.h
@@ -0,0 +1,83 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** 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.
+**
+**************************************************************************/
+
+#ifndef QMLPROJECTRUNCONTROL_H
+#define QMLPROJECTRUNCONTROL_H
+
+#include <projectexplorer/runconfiguration.h>
+#include <projectexplorer/applicationlauncher.h>
+
+namespace QmlProjectManager {
+
+class QmlProjectRunConfiguration;
+
+namespace Internal {
+
+class QmlRunControl : public ProjectExplorer::RunControl {
+    Q_OBJECT
+public:
+    explicit QmlRunControl(QmlProjectRunConfiguration *runConfiguration, bool debugMode);
+    virtual ~QmlRunControl ();
+
+    // RunControl
+    virtual void start();
+    virtual void stop();
+    virtual bool isRunning() const;
+
+private slots:
+    void processExited(int exitCode);
+    void slotBringApplicationToForeground(qint64 pid);
+    void slotAddToOutputWindow(const QString &line);
+    void slotError(const QString & error);
+
+private:
+    ProjectExplorer::ApplicationLauncher m_applicationLauncher;
+
+    QString m_executable;
+    QStringList m_commandLineArguments;
+    bool m_debugMode;
+};
+
+class QmlRunControlFactory : public ProjectExplorer::IRunControlFactory {
+    Q_OBJECT
+public:
+    explicit QmlRunControlFactory(QObject *parent = 0);
+    virtual ~QmlRunControlFactory();
+
+    // IRunControlFactory
+    virtual bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const;
+    virtual ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode);
+    virtual QString displayName() const;
+    virtual QWidget *configurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
+};
+
+} // namespace Internal
+} // namespace QmlProjectManager
+
+#endif // QMLPROJECTRUNCONTROL_H
diff --git a/src/plugins/qmlprojectmanager/qmltarget.cpp b/src/plugins/qmlprojectmanager/qmlprojecttarget.cpp
similarity index 57%
rename from src/plugins/qmlprojectmanager/qmltarget.cpp
rename to src/plugins/qmlprojectmanager/qmlprojecttarget.cpp
index 11ead390f60..605e0c87443 100644
--- a/src/plugins/qmlprojectmanager/qmltarget.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojecttarget.cpp
@@ -27,122 +27,115 @@
 **
 **************************************************************************/
 
-#include "qmltarget.h"
+#include "qmlprojecttarget.h"
 
 #include "qmlproject.h"
+#include "qmlprojectmanagerconstants.h"
+#include "qmlprojectrunconfiguration.h"
 
 #include <QtGui/QApplication>
 #include <QtGui/QStyle>
 
-namespace {
-const char * const VIEWER_TARGET_DISPLAY_NAME("QML Viewer");
-}
-
-using namespace QmlProjectManager;
-using namespace QmlProjectManager::Internal;
-
-////////////////////////////////////////////////////////////////////////////////////
-// QmlTarget
-////////////////////////////////////////////////////////////////////////////////////
+namespace QmlProjectManager {
+namespace Internal {
 
-QmlTarget::QmlTarget(QmlProject *parent) :
-    ProjectExplorer::Target(parent, QLatin1String(VIEWER_TARGET_ID))
+QmlProjectTarget::QmlProjectTarget(QmlProject *parent) :
+    ProjectExplorer::Target(parent, QLatin1String(Constants::QML_VIEWER_TARGET_ID))
 {
     setDisplayName(QApplication::translate("QmlProjectManager::QmlTarget",
-                                           VIEWER_TARGET_DISPLAY_NAME,
+                                           Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
                                            "Qml Viewer target display name"));
     setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
 }
 
-QmlTarget::~QmlTarget()
+QmlProjectTarget::~QmlProjectTarget()
 {
 }
 
-QmlProject *QmlTarget::qmlProject() const
+QmlProject *QmlProjectTarget::qmlProject() const
 {
     return static_cast<QmlProject *>(project());
 }
 
-ProjectExplorer::IBuildConfigurationFactory *QmlTarget::buildConfigurationFactory(void) const
+ProjectExplorer::IBuildConfigurationFactory *QmlProjectTarget::buildConfigurationFactory(void) const
 {
     return 0;
 }
 
-bool QmlTarget::fromMap(const QVariantMap &map)
+bool QmlProjectTarget::fromMap(const QVariantMap &map)
 {
     if (!Target::fromMap(map))
         return false;
 
     setDisplayName(QApplication::translate("QmlProjectManager::QmlTarget",
-                                           VIEWER_TARGET_DISPLAY_NAME,
+                                           Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
                                            "Qml Viewer target display name"));
 
     return true;
 }
 
-////////////////////////////////////////////////////////////////////////////////////
-// QmlTargetFactory
-////////////////////////////////////////////////////////////////////////////////////
-
-QmlTargetFactory::QmlTargetFactory(QObject *parent) :
+QmlProjectTargetFactory::QmlProjectTargetFactory(QObject *parent) :
     ITargetFactory(parent)
 {
 }
 
-QmlTargetFactory::~QmlTargetFactory()
+QmlProjectTargetFactory::~QmlProjectTargetFactory()
 {
 }
 
-QStringList QmlTargetFactory::availableCreationIds(ProjectExplorer::Project *parent) const
+QStringList QmlProjectTargetFactory::availableCreationIds(ProjectExplorer::Project *parent) const
 {
     if (!qobject_cast<QmlProject *>(parent))
         return QStringList();
-    return QStringList() << QLatin1String(VIEWER_TARGET_ID);
+    return QStringList() << QLatin1String(Constants::QML_VIEWER_TARGET_ID);
 }
 
-QString QmlTargetFactory::displayNameForId(const QString &id) const
+QString QmlProjectTargetFactory::displayNameForId(const QString &id) const
 {
-    if (id == QLatin1String(VIEWER_TARGET_ID))
+    if (id == QLatin1String(Constants::QML_VIEWER_TARGET_ID))
         return QCoreApplication::translate("QmlProjectManager::QmlTarget",
-                                           VIEWER_TARGET_DISPLAY_NAME,
+                                           Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
                                            "Qml Viewer target display name");
     return QString();
 }
 
-bool QmlTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
+bool QmlProjectTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
 {
     if (!qobject_cast<QmlProject *>(parent))
         return false;
-    return id == QLatin1String(VIEWER_TARGET_ID);
+    return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
 }
 
-QmlTarget *QmlTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
+QmlProjectTarget *QmlProjectTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
 {
     if (!canCreate(parent, id))
         return 0;
     QmlProject *qmlproject(static_cast<QmlProject *>(parent));
-    QmlTarget *t(new QmlTarget(qmlproject));
+    QmlProjectTarget *t(new QmlProjectTarget(qmlproject));
 
     // Add RunConfiguration (Qml does not have BuildConfigurations)
-    QmlRunConfiguration *runConf(new QmlRunConfiguration(t));
+    QmlProjectRunConfiguration *runConf(new QmlProjectRunConfiguration(t));
     t->addRunConfiguration(runConf);
 
     return t;
 }
 
-bool QmlTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
+bool QmlProjectTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
 {
     return canCreate(parent, ProjectExplorer::idFromMap(map));
 }
 
-QmlTarget *QmlTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
+QmlProjectTarget *QmlProjectTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
 {
     if (!canRestore(parent, map))
         return 0;
     QmlProject *qmlproject(static_cast<QmlProject *>(parent));
-    QmlTarget *target(new QmlTarget(qmlproject));
+    QmlProjectTarget *target(new QmlProjectTarget(qmlproject));
     if (target->fromMap(map))
         return target;
     delete target;
     return 0;
 }
+
+} // namespace Internal
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmltarget.h b/src/plugins/qmlprojectmanager/qmlprojecttarget.h
similarity index 75%
rename from src/plugins/qmlprojectmanager/qmltarget.h
rename to src/plugins/qmlprojectmanager/qmlprojecttarget.h
index 158f4d8ffc8..8ba253687ac 100644
--- a/src/plugins/qmlprojectmanager/qmltarget.h
+++ b/src/plugins/qmlprojectmanager/qmlprojecttarget.h
@@ -27,8 +27,8 @@
 **
 **************************************************************************/
 
-#ifndef QMLTARGET_H
-#define QMLTARGET_H
+#ifndef QMLPROJECTTARGET_H
+#define QMLPROJECTTARGET_H
 
 #include <projectexplorer/target.h>
 
@@ -37,22 +37,20 @@
 
 namespace QmlProjectManager {
 class QmlProject;
-class QmlRunConfiguration;
+class QmlProjectRunConfiguration;
 
 namespace Internal {
 
-const char * const VIEWER_TARGET_ID("QmlProjectManager.QmlTarget");
+class QmlProjectTargetFactory;
 
-class QmlTargetFactory;
-
-class QmlTarget : public ProjectExplorer::Target
+class QmlProjectTarget : public ProjectExplorer::Target
 {
     Q_OBJECT
-    friend class QmlTargetFactory;
+    friend class QmlProjectTargetFactory;
 
 public:
-    explicit QmlTarget(QmlProject *parent);
-    ~QmlTarget();
+    explicit QmlProjectTarget(QmlProject *parent);
+    ~QmlProjectTarget();
 
     QmlProject *qmlProject() const;
 
@@ -62,25 +60,24 @@ protected:
     bool fromMap(const QVariantMap &map);
 };
 
-class QmlTargetFactory : public ProjectExplorer::ITargetFactory
+class QmlProjectTargetFactory : public ProjectExplorer::ITargetFactory
 {
     Q_OBJECT
 
 public:
-    explicit QmlTargetFactory(QObject *parent = 0);
-    ~QmlTargetFactory();
+    explicit QmlProjectTargetFactory(QObject *parent = 0);
+    ~QmlProjectTargetFactory();
 
     QStringList availableCreationIds(ProjectExplorer::Project *parent) const;
     QString displayNameForId(const QString &id) const;
 
     bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
-    QmlTarget *create(ProjectExplorer::Project *parent, const QString &id);
+    QmlProjectTarget *create(ProjectExplorer::Project *parent, const QString &id);
     bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
-    QmlTarget *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
+    QmlProjectTarget *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
 };
 
 } // namespace Internal
-
 } // namespace QmlProjectManager
 
-#endif // QMLTARGET_H
+#endif // QMLPROJECTTARGET_H
diff --git a/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp b/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
index d70d421983b..2bce845fd49 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectwizard.cpp
@@ -43,9 +43,12 @@
 #include <QtCore/QtDebug>
 #include <QtCore/QCoreApplication>
 
-using namespace QmlProjectManager::Internal;
+
 using namespace Utils;
 
+namespace QmlProjectManager {
+namespace Internal {
+
 //////////////////////////////////////////////////////////////////////////////
 // QmlProjectWizardDialog
 //////////////////////////////////////////////////////////////////////////////
@@ -174,3 +177,5 @@ bool QmlProjectWizard::postGenerateFiles(const Core::GeneratedFiles &l, QString
     return true;
 }
 
+} // namespace Internal
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmltaskmanager.cpp b/src/plugins/qmlprojectmanager/qmltaskmanager.cpp
index b5f7daa5d5e..db23fa31be8 100644
--- a/src/plugins/qmlprojectmanager/qmltaskmanager.cpp
+++ b/src/plugins/qmlprojectmanager/qmltaskmanager.cpp
@@ -48,7 +48,7 @@ void QmlTaskManager::setTaskWindow(ProjectExplorer::TaskWindow *taskWindow)
     m_taskWindow->addCategory(Constants::TASK_CATEGORY_QML, "Qml");
 }
 
-void QmlTaskManager::documentUpdated(QmlJS::Document::Ptr doc)
+void QmlTaskManager::documentUpdated(QmlJS::Document::Ptr /*doc*/)
 {
 #if 0 // This will give way too many flickering errors in the build-results pane *when you're typing*
     m_taskWindow->clearTasks(Constants::TASK_CATEGORY_QML);
@@ -66,4 +66,4 @@ void QmlTaskManager::documentUpdated(QmlJS::Document::Ptr doc)
 }
 
 } // Internal
-} // QmlEditor
+} // QmlProjectManager
-- 
GitLab