ProjectExplorer: Reuse StringUtils::joinStrings()

Do some minor cleanup.

Change-Id: I375cec2cd4e0def201c09f5ad9eea4226a5d64e6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2023-02-03 11:21:39 +01:00
parent 383c2205d0
commit 5d96c3a4e9
3 changed files with 18 additions and 22 deletions

View File

@@ -11,6 +11,7 @@
#include <utils/portlist.h> #include <utils/portlist.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/stringutils.h>
#include <utils/url.h> #include <utils/url.h>
using namespace Utils; using namespace Utils;
@@ -30,10 +31,10 @@ public:
} // namespace Internal } // namespace Internal
DeviceUsedPortsGatherer::DeviceUsedPortsGatherer(QObject *parent) : DeviceUsedPortsGatherer::DeviceUsedPortsGatherer(QObject *parent)
QObject(parent), d(new Internal::DeviceUsedPortsGathererPrivate) : QObject(parent)
{ , d(new Internal::DeviceUsedPortsGathererPrivate)
} {}
DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer() DeviceUsedPortsGatherer::~DeviceUsedPortsGatherer()
{ {
@@ -56,8 +57,7 @@ void DeviceUsedPortsGatherer::start()
d->process.reset(new QtcProcess); d->process.reset(new QtcProcess);
d->process->setCommand(d->portsGatheringMethod.commandLine(protocol)); d->process->setCommand(d->portsGatheringMethod.commandLine(protocol));
connect(d->process.get(), &QtcProcess::done, connect(d->process.get(), &QtcProcess::done, this, &DeviceUsedPortsGatherer::handleProcessDone);
this, &DeviceUsedPortsGatherer::handleProcessDone);
d->process->start(); d->process->start();
} }
@@ -107,13 +107,11 @@ void DeviceUsedPortsGatherer::handleProcessDone()
if (d->process->result() == ProcessResult::FinishedWithSuccess) { if (d->process->result() == ProcessResult::FinishedWithSuccess) {
setupUsedPorts(); setupUsedPorts();
} else { } else {
QString errMsg = d->process->errorString(); const QString errorString = d->process->errorString();
const QByteArray stdErr = d->process->readAllRawStandardError(); const QString stdErr = d->process->readAllStandardError();
if (!stdErr.isEmpty()) { const QString outputString
errMsg += QLatin1Char('\n'); = stdErr.isEmpty() ? stdErr : Tr::tr("Remote error output was: %1").arg(stdErr);
errMsg += Tr::tr("Remote error output was: %1").arg(QString::fromUtf8(stdErr)); emitError(Utils::joinStrings({errorString, outputString}, '\n'));
}
emitError(errMsg);
} }
stop(); stop();
} }
@@ -139,8 +137,6 @@ PortsGatherer::PortsGatherer(RunControl *runControl)
}); });
} }
PortsGatherer::~PortsGatherer() = default;
void PortsGatherer::start() void PortsGatherer::start()
{ {
appendMessage(Tr::tr("Checking available ports..."), NormalMessageFormat); 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)) if (Internal::SubChannelProvider *provider = m_channelProviders.value(i))
return provider->channel(); return provider->channel();
return QUrl(); return {};
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -44,7 +44,7 @@ private:
}; };
class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererAdapter class PROJECTEXPLORER_EXPORT DeviceUsedPortsGathererAdapter
: public Utils::Tasking::TaskAdapter<DeviceUsedPortsGatherer> : public Utils::Tasking::TaskAdapter<DeviceUsedPortsGatherer>
{ {
public: public:
DeviceUsedPortsGathererAdapter(); DeviceUsedPortsGathererAdapter();
@@ -57,7 +57,6 @@ class PROJECTEXPLORER_EXPORT PortsGatherer : public RunWorker
public: public:
explicit PortsGatherer(RunControl *runControl); explicit PortsGatherer(RunControl *runControl);
~PortsGatherer() override;
QUrl findEndPoint(); QUrl findEndPoint();

View File

@@ -9,6 +9,7 @@
#include <utils/processinfo.h> #include <utils/processinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/stringutils.h>
using namespace Utils; using namespace Utils;
@@ -50,13 +51,13 @@ void SshDeviceProcessList::handleProcessDone()
if (d->m_process.result() == ProcessResult::FinishedWithSuccess) { if (d->m_process.result() == ProcessResult::FinishedWithSuccess) {
reportProcessListUpdated(buildProcessList(d->m_process.cleanedStdOut())); reportProcessListUpdated(buildProcessList(d->m_process.cleanedStdOut()));
} else { } 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()) ? Tr::tr("Process listing command failed with exit code %1.").arg(d->m_process.exitCode())
: d->m_process.errorString(); : d->m_process.errorString();
const QString stdErr = d->m_process.cleanedStdErr(); const QString stdErr = d->m_process.cleanedStdErr();
const QString fullMessage = stdErr.isEmpty() const QString outputString
? errorMessage : errorMessage + '\n' + Tr::tr("Remote stderr was: %1").arg(stdErr); = stdErr.isEmpty() ? stdErr : Tr::tr("Remote stderr was: %1").arg(stdErr);
reportError(fullMessage); reportError(Utils::joinStrings({errorString, outputString}, '\n'));
} }
setFinished(); setFinished();
} }