From 3cfee2802274bd97f6a84f8c340d90d7edfb1460 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 27 Apr 2022 17:06:02 +0200 Subject: [PATCH] ProjectExplorer: Use one function for done() in application launcher This only shifts the 'if' down one level. Change-Id: I2c049d9a38d786698c728e88d15b0129eba35aed Reviewed-by: Jarek Kobus --- .../projectexplorer/applicationlauncher.cpp | 96 +++++++++---------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index 8d04c3738c5..a0298bdac88 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -75,16 +75,15 @@ public: void handleStandardOutput(); void handleStandardError(); + void handleDone(); // Local - void handleLocalDone(); void cannotRetrieveLocalDebugOutput(); void checkLocalDebugOutput(qint64 pid, const QString &message); qint64 applicationPID() const; bool isRunning() const; // Remote - void handleRemoteDone(); void doReportError(const QString &message, QProcess::ProcessError error = QProcess::FailedToStart); void setFinished(); @@ -240,44 +239,57 @@ QProcess::ProcessError ApplicationLauncher::error() const return d->m_remoteError; } -void ApplicationLauncherPrivate::handleLocalDone() +void ApplicationLauncherPrivate::handleDone() { const QProcess::ProcessError error = m_process->error(); - if (error == QProcess::UnknownError) { - m_exitCode = m_process->exitCode(); - m_exitStatus = m_process->exitStatus(); - emit q->finished(); - return; - } - // TODO: why below handlings are different? - if (m_useTerminal) { - emit q->appendMessage(m_process->errorString(), ErrorMessageFormat); - if (m_processRunning && m_process->processId() == 0) { - m_processRunning = false; - m_exitCode = -1; + + if (m_isLocal) { + if (error == QProcess::UnknownError) { + m_exitCode = m_process->exitCode(); + m_exitStatus = m_process->exitStatus(); emit q->finished(); + return; } + // TODO: why below handlings are different? + if (m_useTerminal) { + emit q->appendMessage(m_process->errorString(), ErrorMessageFormat); + if (m_processRunning && m_process->processId() == 0) { + m_processRunning = false; + m_exitCode = -1; + emit q->finished(); + } + } else { + QString errorString; + switch (error) { + case QProcess::FailedToStart: + errorString = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?"); + break; + case QProcess::Crashed: + m_exitStatus = QProcess::CrashExit; + break; + default: + errorString = ApplicationLauncher::tr("Some error has occurred while running the program."); + } + if (!errorString.isEmpty()) + emit q->appendMessage(errorString, ErrorMessageFormat); + if (m_processRunning && !isRunning()) { + m_processRunning = false; + m_exitCode = -1; + emit q->finished(); + } + } + emit q->errorOccurred(error); + } else { - QString errorString; - switch (m_process->error()) { - case QProcess::FailedToStart: - errorString = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?"); - break; - case QProcess::Crashed: - m_exitStatus = QProcess::CrashExit; - break; - default: - errorString = ApplicationLauncher::tr("Some error has occurred while running the program."); - } - if (!errorString.isEmpty()) - emit q->appendMessage(errorString, ErrorMessageFormat); - if (m_processRunning && !isRunning()) { - m_processRunning = false; - m_exitCode = -1; - emit q->finished(); + QTC_ASSERT(m_state == Run, return); + if (error == QProcess::FailedToStart) { + doReportError(ApplicationLauncher::tr("Application failed to start: %1") + .arg(m_process->errorString())); + } else if (m_process->exitStatus() == QProcess::CrashExit) { + doReportError(m_process->errorString(), QProcess::Crashed); } + setFinished(); } - emit q->errorOccurred(error); } void ApplicationLauncherPrivate::handleStandardOutput() @@ -336,9 +348,6 @@ void ApplicationLauncherPrivate::start() if (m_isLocal) { m_process.reset(new QtcProcess(this)); - connect(m_process.get(), &QtcProcess::done, - this, &ApplicationLauncherPrivate::handleLocalDone); - // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) const FilePath fixedPath = m_runnable.workingDirectory.normalizedPathName(); m_process->setWorkingDirectory(fixedPath); @@ -390,8 +399,6 @@ void ApplicationLauncherPrivate::start() m_stopRequested = false; m_process.reset(m_runnable.device->createProcess(this)); - connect(m_process.get(), &QtcProcess::done, - this, &ApplicationLauncherPrivate::handleRemoteDone); m_process->setCommand(m_runnable.command); m_process->setWorkingDirectory(m_runnable.workingDirectory); m_process->setRemoteEnvironment(m_runnable.environment); @@ -404,6 +411,7 @@ void ApplicationLauncherPrivate::start() m_outputCodec = QTextCodec::codecForName("utf8"); connect(m_process.get(), &QtcProcess::started, q, &ApplicationLauncher::started); + connect(m_process.get(), &QtcProcess::done, this, &ApplicationLauncherPrivate::handleDone); m_process->setProcessChannelMode(m_processChannelMode); if (m_processChannelMode == QProcess::SeparateChannels) { @@ -430,18 +438,6 @@ void ApplicationLauncherPrivate::setFinished() emit q->finished(); } -void ApplicationLauncherPrivate::handleRemoteDone() -{ - QTC_ASSERT(m_state == Run, return); - if (m_process->error() == QProcess::FailedToStart) { - doReportError(ApplicationLauncher::tr("Application failed to start: %1") - .arg(m_process->errorString())); - } else if (m_process->exitStatus() == QProcess::CrashExit) { - doReportError(m_process->errorString(), QProcess::Crashed); - } - setFinished(); -} - void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess::ProcessError error) { m_remoteErrorString = message;