PublicKeyDeploymentDialog: Replace QString with Utils::Result

Change-Id: I7f9dc2720f115fa921aff74368e8d7eb80b2d34c
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2025-01-16 08:28:59 +01:00
parent 4c5b9b1c1f
commit ce4707d783
2 changed files with 14 additions and 11 deletions

View File

@@ -57,20 +57,20 @@ PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(
[this] { d->m_done ? accept() : reject(); }); [this] { d->m_done ? accept() : reject(); });
connect(&d->m_process, &Process::done, this, [this] { connect(&d->m_process, &Process::done, this, [this] {
const bool succeeded = d->m_process.result() == ProcessResult::FinishedWithSuccess; const bool succeeded = d->m_process.result() == ProcessResult::FinishedWithSuccess;
QString finalMessage; Result result = Result::Ok;
if (!succeeded) { if (!succeeded) {
const QString errorString = d->m_process.errorString(); const QString errorString = d->m_process.errorString();
const QString errorMessage = errorString.isEmpty() ? d->m_process.cleanedStdErr() const QString errorMessage = errorString.isEmpty() ? d->m_process.cleanedStdErr()
: errorString; : errorString;
finalMessage = Utils::joinStrings({Tr::tr("Key deployment failed."), result = Result::Error(Utils::joinStrings({Tr::tr("Key deployment failed."),
Utils::trimBack(errorMessage, '\n')}, '\n'); Utils::trimBack(errorMessage, '\n')}, '\n'));
} }
handleDeploymentDone(succeeded, finalMessage); handleDeploymentDone(result);
}); });
FileReader reader; FileReader reader;
if (!reader.fetch(publicKeyFileName)) { if (!reader.fetch(publicKeyFileName)) {
handleDeploymentDone(false, Tr::tr("Public key error: %1").arg(reader.errorString())); handleDeploymentDone(Result::Error(Tr::tr("Public key error: %1").arg(reader.errorString())));
return; return;
} }
@@ -111,16 +111,16 @@ PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
delete d; delete d;
} }
void PublicKeyDeploymentDialog::handleDeploymentDone(bool succeeded, const QString &errorMessage) void PublicKeyDeploymentDialog::handleDeploymentDone(const Result &result)
{ {
QString buttonText = succeeded ? Tr::tr("Deployment finished successfully.") : errorMessage; QString buttonText = result ? Tr::tr("Deployment finished successfully.") : result.error();
const QString textColor = creatorColor( const QString textColor = creatorColor(
succeeded ? Theme::TextColorNormal : Theme::TextColorError).name(); result ? Theme::TextColorNormal : Theme::TextColorError).name();
setLabelText(QString::fromLatin1("<font color=\"%1\">%2</font>") setLabelText(QString::fromLatin1("<font color=\"%1\">%2</font>")
.arg(textColor, buttonText.replace("\n", "<br/>"))); .arg(textColor, buttonText.replace("\n", "<br/>")));
setCancelButtonText(Tr::tr("Close")); setCancelButtonText(Tr::tr("Close"));
if (!succeeded) if (!result)
return; return;
setValue(1); setValue(1);

View File

@@ -7,7 +7,10 @@
#include <QProgressDialog> #include <QProgressDialog>
namespace Utils { class FilePath; } namespace Utils {
class FilePath;
class Result;
}
namespace RemoteLinux::Internal { namespace RemoteLinux::Internal {
@@ -28,7 +31,7 @@ public:
~PublicKeyDeploymentDialog() override; ~PublicKeyDeploymentDialog() override;
private: private:
void handleDeploymentDone(bool succeeded, const QString &errorMessage); void handleDeploymentDone(const Utils::Result &result);
Internal::PublicKeyDeploymentDialogPrivate * const d; Internal::PublicKeyDeploymentDialogPrivate * const d;
}; };