diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.cpp b/src/plugins/projectexplorer/localapplicationruncontrol.cpp index bf7ea838e83..b7e92e4e165 100644 --- a/src/plugins/projectexplorer/localapplicationruncontrol.cpp +++ b/src/plugins/projectexplorer/localapplicationruncontrol.cpp @@ -40,6 +40,103 @@ namespace ProjectExplorer { namespace Internal { +class LocalApplicationRunControl : public RunControl +{ + Q_OBJECT + +public: + LocalApplicationRunControl(RunConfiguration *runConfiguration, Core::Id mode); + + void start() override; + StopResult stop() override; + bool isRunning() const override; + + void setRunnable(const StandardRunnable &runnable) { m_runnable = runnable; } + +private: + void processStarted(); + void processExited(int exitCode, QProcess::ExitStatus status); + + ApplicationLauncher m_applicationLauncher; + StandardRunnable m_runnable; + bool m_running = false; +}; + +LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode) + : RunControl(rc, mode) +{ + setIcon(Icons::RUN_SMALL); + EnvironmentAspect *environment = rc->extraAspect(); + Utils::Environment env; + if (environment) + env = environment->environment(); + m_applicationLauncher.setEnvironment(env); + + connect(&m_applicationLauncher, &ApplicationLauncher::appendMessage, + this, static_cast(&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_runnable.executable.isEmpty()) { + appendMessage(tr("No executable specified.") + QLatin1Char('\n'), Utils::ErrorMessageFormat); + emit finished(); + } 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_runnable.executable)) + QLatin1Char('\n'); + appendMessage(msg, Utils::NormalMessageFormat); + m_applicationLauncher.start(m_runnable.runMode, m_runnable.executable, m_runnable.commandLineArguments); + setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID())); + } +} + +LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop() +{ + m_applicationLauncher.stop(); + return StoppedSynchronously; +} + +bool LocalApplicationRunControl::isRunning() const +{ + return m_running; +} + +void LocalApplicationRunControl::processStarted() +{ + // Console processes only know their pid after being started + setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID())); +} + +void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatus status) +{ + m_running = false; + setApplicationProcessHandle(ProcessHandle()); + QString msg; + if (status == QProcess::CrashExit) { + msg = tr("%1 crashed") + .arg(QDir::toNativeSeparators(m_runnable.executable)); + } else { + msg = tr("%1 exited with code %2") + .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; @@ -56,115 +153,12 @@ RunControl *LocalApplicationRunControlFactory::create(RunConfiguration *runConfi { Q_UNUSED(errorMessage) QTC_ASSERT(runConfiguration->runnable().is(), return 0); - auto runnable = runConfiguration->runnable().as(); auto runControl = new LocalApplicationRunControl(runConfiguration, mode); - runControl->setCommand(runnable.executable, runnable.commandLineArguments); - runControl->setApplicationLauncherMode(runnable.runMode); - runControl->setWorkingDirectory(runnable.workingDirectory); - + runControl->setRunnable(runConfiguration->runnable().as()); return runControl; } } // namespace Internal - -// ApplicationRunControl - -LocalApplicationRunControl::LocalApplicationRunControl(RunConfiguration *rc, Core::Id mode) - : RunControl(rc, mode), m_runMode(ApplicationLauncher::Console), m_running(false) -{ - setIcon(Icons::RUN_SMALL); - EnvironmentAspect *environment = rc->extraAspect(); - Utils::Environment env; - if (environment) - 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() -{ -} - -void LocalApplicationRunControl::start() -{ - emit started(); - if (m_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'), - Utils::ErrorMessageFormat); - emit finished(); - } else { - m_running = true; - QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)) + QLatin1Char('\n'); - appendMessage(msg, Utils::NormalMessageFormat); - m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments); - setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID())); - } -} - -LocalApplicationRunControl::StopResult LocalApplicationRunControl::stop() -{ - m_applicationLauncher.stop(); - return StoppedSynchronously; -} - -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 - setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID())); -} - -void LocalApplicationRunControl::processExited(int exitCode, QProcess::ExitStatus status) -{ - m_running = false; - setApplicationProcessHandle(ProcessHandle()); - QString msg; - if (status == QProcess::CrashExit) { - msg = tr("%1 crashed") - .arg(QDir::toNativeSeparators(m_executable)); - } else { - msg = tr("%1 exited with code %2") - .arg(QDir::toNativeSeparators(m_executable)).arg(exitCode); - } - appendMessage(msg + QLatin1Char('\n'), Utils::NormalMessageFormat); - emit finished(); -} - } // namespace ProjectExplorer + +#include "localapplicationruncontrol.moc" diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.h b/src/plugins/projectexplorer/localapplicationruncontrol.h index 9d6fd3e3c8b..2ca0020cba6 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