diff options
author | hjk <hjk@qt.io> | 2017-03-10 09:05:52 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-03-14 10:35:37 +0000 |
commit | 30b4955ed7aa1ac3b78e9eb9385c033311b3a620 (patch) | |
tree | 79e62feb5b3f9c5d30ce5cc8a8b8a7ae165ab24b /src/plugins/projectexplorer/localapplicationruncontrol.cpp | |
parent | a1165291774411a5f2dd864540d638f810267ad5 (diff) |
ProjectExplorer: Add a SimpleRunControl implementation
Essentially a RunControl with and ApplicationLauncher member like it is
used directly or in disguise in the LocalApplicationRunControl, Nim and
Python. Extenting that to RemoteLinux/Qnx is possible, but left to the
next patch.
Change-Id: I91b3199d3d6a418fe4e5be7a5d61689c581a5121
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer/localapplicationruncontrol.cpp')
-rw-r--r-- | src/plugins/projectexplorer/localapplicationruncontrol.cpp | 85 |
1 files changed, 1 insertions, 84 deletions
diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.cpp b/src/plugins/projectexplorer/localapplicationruncontrol.cpp index 9cd27dc166..bb13231ae9 100644 --- a/src/plugins/projectexplorer/localapplicationruncontrol.cpp +++ b/src/plugins/projectexplorer/localapplicationruncontrol.cpp @@ -25,7 +25,6 @@ #include "localapplicationruncontrol.h" #include "runnables.h" -#include "environmentaspect.h" #include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/kitinformation.h> @@ -34,91 +33,11 @@ #include <utils/utilsicons.h> #include <utils/qtcassert.h> -#include <QDir> - using namespace Utils; namespace ProjectExplorer { namespace Internal { -class LocalApplicationRunControl : public RunControl -{ - Q_OBJECT - -public: - LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode); - - void start() override; - StopResult stop() override; - -private: - void processStarted(); - void processExited(int exitCode, QProcess::ExitStatus status); - - ApplicationLauncher m_applicationLauncher; -}; - -LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode) - : RunControl(rc, mode) -{ - setRunnable(rc->runnable()); - setIcon(Utils::Icons::RUN_SMALL_TOOLBAR); - connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage, - this, static_cast<void(RunControl::*)(const QString &, Utils::OutputFormat)>(&RunControl::appendMessage)); - connect(&m_applicationLauncher, &ApplicationLauncher::processStarted, - this, &LocalApplicationRunControl::processStarted); - connect(&m_applicationLauncher, &ApplicationLauncher::processExited, - this, &LocalApplicationRunControl::processExited); -} - -void LocalApplicationRunControl::start() -{ - QTC_ASSERT(runnable().is<StandardRunnable>(), return); - auto r = runnable().as<StandardRunnable>(); - reportApplicationStart(); - if (r.executable.isEmpty()) { - appendMessage(tr("No executable specified.") + QLatin1Char('\n'), Utils::ErrorMessageFormat); - reportApplicationStop(); - } else if (!QFileInfo::exists(r.executable)) { - appendMessage(tr("Executable %1 does not exist.") - .arg(QDir::toNativeSeparators(r.executable)) + QLatin1Char('\n'), - Utils::ErrorMessageFormat); - reportApplicationStop(); - } else { - QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(r.executable)) + QLatin1Char('\n'); - appendMessage(msg, Utils::NormalMessageFormat); - m_applicationLauncher.start(r); - setApplicationProcessHandle(m_applicationLauncher.applicationPID()); - } -} - -LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop() -{ - m_applicationLauncher.stop(); - return StoppedSynchronously; -} - -void LocalApplicationRunControl::processStarted() -{ - // Console processes only know their pid after being started - setApplicationProcessHandle(m_applicationLauncher.applicationPID()); - bringApplicationToForeground(); -} - -void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatus status) -{ - QString msg; - QString exe = runnable().as<StandardRunnable>().executable; - if (status == QProcess::CrashExit) - msg = tr("%1 crashed.").arg(QDir::toNativeSeparators(exe)); - else - msg = tr("%1 exited with code %2").arg(QDir::toNativeSeparators(exe)).arg(exitCode); - appendMessage(msg + QLatin1Char('\n'), Utils::NormalMessageFormat); - reportApplicationStop(); -} - -// LocalApplicationRunControlFactory - static bool isLocal(RunConfiguration *runConfiguration) { Target *target = runConfiguration ? runConfiguration->target() : nullptr; @@ -142,10 +61,8 @@ bool LocalApplicationRunControlFactory::canRun(RunConfiguration *runConfiguratio RunControl *LocalApplicationRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) { Q_UNUSED(errorMessage) - return new LocalApplicationRunControl(runConfiguration, mode); + return new SimpleRunControl(runConfiguration, mode); } } // namespace Internal } // namespace ProjectExplorer - -#include "localapplicationruncontrol.moc" |