From f9800e5a26dd6f9ae21cd492633ed6f1249cbbbf Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 9 May 2022 08:00:16 +0200 Subject: [PATCH] ProjectExplorer: React to QtcProcess::done in ApplicationLauncher The 'modern' way. Change-Id: I80c0bb0b9c7c08e6aef724d430a8dbbd4b0c2777 Reviewed-by: Jarek Kobus Reviewed-by: --- .../projectexplorer/applicationlauncher.cpp | 26 +++++++++---------- .../projectexplorer/applicationlauncher.h | 4 +-- src/plugins/projectexplorer/runcontrol.cpp | 24 ++++++----------- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index 6fc7bd01d23..9226274c657 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -72,7 +72,7 @@ public: ~ApplicationLauncherPrivate() override { if (m_state == Run) - emit q->finished(); + emit q->done(); } void start(); @@ -178,7 +178,7 @@ void ApplicationLauncherPrivate::stop() if (!isRunning()) return; m_process.stopProcess(); - QTimer::singleShot(100, this, [this] { emit q->finished(); }); + QTimer::singleShot(100, this, [this] { emit q->done(); }); } else { if (m_stopRequested) return; @@ -224,7 +224,7 @@ void ApplicationLauncherPrivate::handleDone() if (m_isLocal) { if (m_resultData.m_error == QProcess::UnknownError) { - emit q->finished(); + emit q->done(); return; } // TODO: why below handlings are different? @@ -233,7 +233,6 @@ void ApplicationLauncherPrivate::handleDone() if (m_processRunning && m_process.processId() == 0) { m_processRunning = false; m_resultData.m_exitCode = -1; // FIXME: Why? - emit q->finished(); } } else { QString errorString; @@ -252,23 +251,19 @@ void ApplicationLauncherPrivate::handleDone() if (m_processRunning && !isRunning()) { m_processRunning = false; m_resultData.m_exitCode = -1; - emit q->finished(); } } - emit q->errorOccurred(m_resultData.m_error); } else { - QTC_ASSERT(m_state == Run, return); + QTC_ASSERT(m_state == Run, emit q->done(); return); if (m_resultData.m_error == QProcess::FailedToStart) { m_resultData.m_exitStatus = QProcess::CrashExit; - emit q->errorOccurred(m_resultData.m_error); } else if (m_resultData.m_exitStatus == QProcess::CrashExit) { m_resultData.m_error = QProcess::Crashed; - emit q->errorOccurred(m_resultData.m_error); } m_state = Inactive; - emit q->finished(); } + emit q->done(); } void ApplicationLauncherPrivate::handleStandardOutput() @@ -312,6 +307,11 @@ QProcess::ExitStatus ApplicationLauncher::exitStatus() const return d->m_resultData.m_exitStatus; } +QProcess::ProcessError ApplicationLauncher::error() const +{ + return d->m_resultData.m_error; +} + void ApplicationLauncher::start() { d->start(); @@ -357,8 +357,7 @@ void ApplicationLauncherPrivate::start() m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No device."); m_resultData.m_error = QProcess::FailedToStart; m_resultData.m_exitStatus = QProcess::CrashExit; - emit q->errorOccurred(QProcess::FailedToStart); - emit q->finished(); + emit q->done(); return; } @@ -366,8 +365,7 @@ void ApplicationLauncherPrivate::start() m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No command given."); m_resultData.m_error = QProcess::FailedToStart; m_resultData.m_exitStatus = QProcess::CrashExit; - emit q->errorOccurred(QProcess::FailedToStart); - emit q->finished(); + emit q->done(); return; } diff --git a/src/plugins/projectexplorer/applicationlauncher.h b/src/plugins/projectexplorer/applicationlauncher.h index ca621795f81..edb8e2b0e4d 100644 --- a/src/plugins/projectexplorer/applicationlauncher.h +++ b/src/plugins/projectexplorer/applicationlauncher.h @@ -63,12 +63,12 @@ public: int exitCode() const; QProcess::ExitStatus exitStatus() const; + QProcess::ProcessError error() const; signals: void appendMessage(const QString &message, Utils::OutputFormat format, bool appendNewLine = true); void started(); - void finished(); - void errorOccurred(QProcess::ProcessError error); + void done(); private: std::unique_ptr d; diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 21ba70bbb31..cbceea2e0d7 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1220,30 +1220,22 @@ void SimpleTargetRunner::doStart(const Runnable &runnable) const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput()); appendMessage(msg, Utils::NormalMessageFormat); - connect(&m_launcher, &ApplicationLauncher::finished, this, [this, runnable]() { + connect(&m_launcher, &ApplicationLauncher::done, this, [this, runnable] { if (m_stopReported) return; - const QString msg = (m_launcher.exitStatus() == QProcess::CrashExit) - ? tr("%1 crashed.") : tr("%2 exited with code %1").arg(m_launcher.exitCode()); + QString msg = tr("%2 exited with code %1").arg(m_launcher.exitCode()); + if (m_launcher.exitStatus() == QProcess::CrashExit) + msg = tr("%1 crashed."); + else if (m_stopForced) + msg = tr("The process was ended forcefully."); + else if (m_launcher.error() != QProcess::UnknownError) + msg = userMessageForProcessError(m_launcher.error(), runnable.command.executable()); const QString displayName = runnable.command.executable().toUserOutput(); appendMessage(msg.arg(displayName), Utils::NormalMessageFormat); m_stopReported = true; reportStopped(); }); - connect(&m_launcher, &ApplicationLauncher::errorOccurred, - this, [this, runnable](QProcess::ProcessError error) { - if (m_stopReported) - return; - if (error == QProcess::Timedout) - return; // No actual change on the process side. - const QString msg = m_stopForced ? tr("The process was ended forcefully.") - : userMessageForProcessError(error, runnable.command.executable()); - appendMessage(msg, Utils::NormalMessageFormat); - m_stopReported = true; - reportStopped(); - }); - connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); const bool isDesktop = runnable.device.isNull()