diff options
author | hjk <hjk@theqtcompany.com> | 2016-01-25 13:14:23 +0100 |
---|---|---|
committer | hjk <hjk@theqtcompany.com> | 2016-01-26 10:09:46 +0000 |
commit | d35f4fb72ddafc2472a266cf281ad52948ecdf5e (patch) | |
tree | 58b87278d07032955e4bc3a2d615c08f0c11d63e | |
parent | 9ae2ce76297ef899e9c4444f736ede4706c7ece4 (diff) | |
download | qt-creator-d35f4fb72ddafc2472a266cf281ad52948ecdf5e.tar.gz |
ProjectExplorer: Use StandardRunnable in LocalApplicationRunControl
Also un-export LocalApplicationRunControl.
Change-Id: Ide5dbb61035d9f648f517a9d89763803ac0c4d26
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
-rw-r--r-- | src/plugins/projectexplorer/localapplicationruncontrol.cpp | 122 | ||||
-rw-r--r-- | src/plugins/projectexplorer/localapplicationruncontrol.h | 28 |
2 files changed, 58 insertions, 92 deletions
diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.cpp b/src/plugins/projectexplorer/localapplicationruncontrol.cpp index bf7ea838e8..b7e92e4e16 100644 --- a/src/plugins/projectexplorer/localapplicationruncontrol.cpp +++ b/src/plugins/projectexplorer/localapplicationruncontrol.cpp @@ -40,37 +40,30 @@ namespace ProjectExplorer { namespace Internal { -static bool isLocal(RunConfiguration *runConfiguration) +class LocalApplicationRunControl : public RunControl { - Target *target = runConfiguration ? runConfiguration->target() : 0; - Kit *kit = target ? target->kit() : 0; - return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; -} + Q_OBJECT -bool LocalApplicationRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const -{ - return mode == Constants::NORMAL_RUN_MODE && isLocal(runConfiguration); -} +public: + LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode); -RunControl *LocalApplicationRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) -{ - Q_UNUSED(errorMessage) - QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0); - auto runnable = runConfiguration->runnable().as<StandardRunnable>(); - auto runControl = new LocalApplicationRunControl(runConfiguration, mode); - runControl->setCommand(runnable.executable, runnable.commandLineArguments); - runControl->setApplicationLauncherMode(runnable.runMode); - runControl->setWorkingDirectory(runnable.workingDirectory); + void start() override; + StopResult stop() override; + bool isRunning() const override; - return runControl; -} + void setRunnable(const StandardRunnable &runnable) { m_runnable = runnable; } -} // namespace Internal +private: + void processStarted(); + void processExited(int exitCode, QProcess::ExitStatus status); -// ApplicationRunControl + ApplicationLauncher m_applicationLauncher; + StandardRunnable m_runnable; + bool m_running = false; +}; LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode) - : RunControl(rc, mode), m_runMode(ApplicationLauncher::Console), m_running(false) + : RunControl(rc, mode) { setIcon(Icons::RUN_SMALL); EnvironmentAspect *environment = rc->extraAspect<EnvironmentAspect>(); @@ -79,35 +72,32 @@ LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Cor env = environment->environment(); m_applicationLauncher.setEnvironment(env); - connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,Utils::OutputFormat)), - this, SLOT(slotAppendMessage(QString,Utils::OutputFormat))); - connect(&m_applicationLauncher, SIGNAL(processStarted()), - this, SLOT(processStarted())); - connect(&m_applicationLauncher, SIGNAL(processExited(int,QProcess::ExitStatus)), - this, SLOT(processExited(int,QProcess::ExitStatus))); - connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)), - this, SLOT(bringApplicationToForeground(qint64))); -} - -LocalApplicationRunControl::~LocalApplicationRunControl() -{ + 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); + connect(&m_applicationLauncher, &ApplicationLauncher::bringToForegroundRequested, + this, &RunControl::bringApplicationToForeground); } void LocalApplicationRunControl::start() { emit started(); - if (m_executable.isEmpty()) { + if (m_runnable.executable.isEmpty()) { appendMessage(tr("No executable specified.") + QLatin1Char('\n'), Utils::ErrorMessageFormat); emit finished(); - } else if (!QFileInfo::exists(m_executable)) { - appendMessage(tr("Executable %1 does not exist.").arg(QDir::toNativeSeparators(m_executable)) + QLatin1Char('\n'), + } else if (!QFileInfo::exists(m_runnable.executable)) { + appendMessage(tr("Executable %1 does not exist.") + .arg(QDir::toNativeSeparators(m_runnable.executable)) + QLatin1Char('\n'), Utils::ErrorMessageFormat); emit finished(); } else { m_running = true; - QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)) + QLatin1Char('\n'); + QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_runnable.executable)) + QLatin1Char('\n'); appendMessage(msg, Utils::NormalMessageFormat); - m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments); + m_applicationLauncher.start(m_runnable.runMode, m_runnable.executable, m_runnable.commandLineArguments); setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID())); } } @@ -123,28 +113,6 @@ bool LocalApplicationRunControl::isRunning() const return m_running; } -void LocalApplicationRunControl::setCommand(const QString &executable, const QString &commandLineArguments) -{ - m_executable = executable; - m_commandLineArguments = commandLineArguments; -} - -void LocalApplicationRunControl::setApplicationLauncherMode(const ApplicationLauncher::Mode mode) -{ - m_runMode = mode; -} - -void LocalApplicationRunControl::setWorkingDirectory(const QString &workingDirectory) -{ - m_applicationLauncher.setWorkingDirectory(workingDirectory); -} - -void LocalApplicationRunControl::slotAppendMessage(const QString &err, - Utils::OutputFormat format) -{ - appendMessage(err, format); -} - void LocalApplicationRunControl::processStarted() { // Console processes only know their pid after being started @@ -158,13 +126,39 @@ void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatu QString msg; if (status == QProcess::CrashExit) { msg = tr("%1 crashed") - .arg(QDir::toNativeSeparators(m_executable)); + .arg(QDir::toNativeSeparators(m_runnable.executable)); } else { msg = tr("%1 exited with code %2") - .arg(QDir::toNativeSeparators(m_executable)).arg(exitCode); + .arg(QDir::toNativeSeparators(m_runnable.executable)).arg(exitCode); } appendMessage(msg + QLatin1Char('\n'), Utils::NormalMessageFormat); emit finished(); } +// LocalApplicationRunControlFactory + +static bool isLocal(RunConfiguration *runConfiguration) +{ + Target *target = runConfiguration ? runConfiguration->target() : 0; + Kit *kit = target ? target->kit() : 0; + return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; +} + +bool LocalApplicationRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const +{ + return mode == Constants::NORMAL_RUN_MODE && isLocal(runConfiguration); +} + +RunControl *LocalApplicationRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) +{ + Q_UNUSED(errorMessage) + QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0); + auto runControl = new LocalApplicationRunControl(runConfiguration, mode); + runControl->setRunnable(runConfiguration->runnable().as<StandardRunnable>()); + return runControl; +} + +} // namespace Internal } // namespace ProjectExplorer + +#include "localapplicationruncontrol.moc" diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.h b/src/plugins/projectexplorer/localapplicationruncontrol.h index 9d6fd3e3c8..2ca0020cba 100644 --- a/src/plugins/projectexplorer/localapplicationruncontrol.h +++ b/src/plugins/projectexplorer/localapplicationruncontrol.h @@ -27,7 +27,6 @@ #define LOCALAPPLICATIONRUNCONTROL_H #include "runconfiguration.h" -#include "applicationlauncher.h" namespace ProjectExplorer { namespace Internal { @@ -41,33 +40,6 @@ public: }; } // namespace Internal - -class PROJECTEXPLORER_EXPORT LocalApplicationRunControl : public RunControl -{ - Q_OBJECT -public: - LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode); - ~LocalApplicationRunControl(); - void start(); - StopResult stop(); - bool isRunning() const; - - void setCommand(const QString &executable, const QString &commandLineArguments); - void setApplicationLauncherMode(const ApplicationLauncher::Mode mode); - void setWorkingDirectory(const QString &workingDirectory); - -private slots: - void processStarted(); - void processExited(int exitCode, QProcess::ExitStatus status); - void slotAppendMessage(const QString &err, Utils::OutputFormat isError); -private: - ApplicationLauncher m_applicationLauncher; - QString m_executable; - QString m_commandLineArguments; - ApplicationLauncher::Mode m_runMode; - bool m_running; -}; - } // namespace ProjectExplorer #endif // LOCALAPPLICATIONRUNCONTROL_H |