From 5d96c3a4e9f2538b8269134e034f26557d348de7 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 3 Feb 2023 11:21:39 +0100 Subject: [PATCH] ProjectExplorer: Reuse StringUtils::joinStrings() Do some minor cleanup. Change-Id: I375cec2cd4e0def201c09f5ad9eea4226a5d64e6 Reviewed-by: Christian Kandeler --- .../devicesupport/deviceusedportsgatherer.cpp | 28 ++++++++----------- .../devicesupport/deviceusedportsgatherer.h | 3 +- .../devicesupport/sshdeviceprocesslist.cpp | 9 +++--- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp index d76be0a888e..8081c9745df 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include using namespace Utils; @@ -30,10 +31,10 @@ public: } // namespace Internal -DeviceUsedPortsGatherer::DeviceUsedPortsGatherer(QObject *parent) : - QObject(parent), d(new Internal::DeviceUsedPortsGathererPrivate) -{ -} +DeviceUsedPortsGatherer::DeviceUsedPortsGatherer(QObject *parent) + : QObject(parent) + , d(new Internal::DeviceUsedPortsGathererPrivate) +{} DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer() { @@ -56,8 +57,7 @@ void DeviceUsedPortsGatherer::start() d->process.reset(new QtcProcess); d->process->setCommand(d->portsGatheringMethod.commandLine(protocol)); - connect(d->process.get(), &QtcProcess::done, - this, &DeviceUsedPortsGatherer::handleProcessDone); + connect(d->process.get(), &QtcProcess::done, this, &DeviceUsedPortsGatherer::handleProcessDone); d->process->start(); } @@ -107,13 +107,11 @@ void DeviceUsedPortsGatherer::handleProcessDone() if (d->process->result() == ProcessResult::FinishedWithSuccess) { setupUsedPorts(); } else { - QString errMsg = d->process->errorString(); - const QByteArray stdErr = d->process->readAllRawStandardError(); - if (!stdErr.isEmpty()) { - errMsg += QLatin1Char('\n'); - errMsg += Tr::tr("Remote error output was: %1").arg(QString::fromUtf8(stdErr)); - } - emitError(errMsg); + const QString errorString = d->process->errorString(); + const QString stdErr = d->process->readAllStandardError(); + const QString outputString + = stdErr.isEmpty() ? stdErr : Tr::tr("Remote error output was: %1").arg(stdErr); + emitError(Utils::joinStrings({errorString, outputString}, '\n')); } stop(); } @@ -139,8 +137,6 @@ PortsGatherer::PortsGatherer(RunControl *runControl) }); } -PortsGatherer::~PortsGatherer() = default; - void PortsGatherer::start() { appendMessage(Tr::tr("Checking available ports..."), NormalMessageFormat); @@ -260,7 +256,7 @@ QUrl ChannelProvider::channel(int i) const { if (Internal::SubChannelProvider *provider = m_channelProviders.value(i)) return provider->channel(); - return QUrl(); + return {}; } } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h index 93b74ba1742..3519c7d22fe 100644 --- a/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h +++ b/src/plugins/projectexplorer/devicesupport/deviceusedportsgatherer.h @@ -44,7 +44,7 @@ private: }; class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererAdapter - : public Utils::Tasking::TaskAdapter + : public Utils::Tasking::TaskAdapter { public: DeviceUsedPortsGathererAdapter(); @@ -57,7 +57,6 @@ class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker public: explicit PortsGatherer(RunControl *runControl); - ~PortsGatherer() override; QUrl findEndPoint(); diff --git a/src/plugins/projectexplorer/devicesupport/sshdeviceprocesslist.cpp b/src/plugins/projectexplorer/devicesupport/sshdeviceprocesslist.cpp index 91e388bc09e..d64cde6e3ed 100644 --- a/src/plugins/projectexplorer/devicesupport/sshdeviceprocesslist.cpp +++ b/src/plugins/projectexplorer/devicesupport/sshdeviceprocesslist.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace Utils; @@ -50,13 +51,13 @@ void SshDeviceProcessList::handleProcessDone() if (d->m_process.result() == ProcessResult::FinishedWithSuccess) { reportProcessListUpdated(buildProcessList(d->m_process.cleanedStdOut())); } else { - const QString errorMessage = d->m_process.exitStatus() == QProcess::NormalExit + const QString errorString = d->m_process.exitStatus() == QProcess::NormalExit ? Tr::tr("Process listing command failed with exit code %1.").arg(d->m_process.exitCode()) : d->m_process.errorString(); const QString stdErr = d->m_process.cleanedStdErr(); - const QString fullMessage = stdErr.isEmpty() - ? errorMessage : errorMessage + '\n' + Tr::tr("Remote stderr was: %1").arg(stdErr); - reportError(fullMessage); + const QString outputString + = stdErr.isEmpty() ? stdErr : Tr::tr("Remote stderr was: %1").arg(stdErr); + reportError(Utils::joinStrings({errorString, outputString}, '\n')); } setFinished(); }