From b07c9bb4af8f202a741286d2068e7e116a332c48 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Dec 2021 12:53:43 +0100 Subject: [PATCH] [libcalamaresui] Use meaningful type for Upload info - use a struct with named fields instead of a tuple - offer an operator bool() for the logic of does-it-make-sense-to-upload --- src/libcalamaresui/Branding.cpp | 7 ++++--- src/libcalamaresui/Branding.h | 9 ++++++++- src/libcalamaresui/ViewManager.cpp | 4 +--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 5894c723d..b723f5dc7 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -162,14 +162,15 @@ uploadServerFromMap( const QVariantMap& map ) if ( typestring.isEmpty() || urlstring.isEmpty() ) { - return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl(), 0 ); + return Branding::UploadServerInfo { Branding::UploadServerType::None, QUrl(), 0 }; } bool bogus = false; // we don't care about type-name lookup success here - return Branding::UploadServerInfo( + return Branding::UploadServerInfo { names.find( typestring, bogus ), QUrl( urlstring, QUrl::ParsingMode::StrictMode ), - sizeLimitKiB >= 0 ? CalamaresUtils::KiBtoBytes( static_cast< unsigned long long >( sizeLimitKiB ) ) : -1 ); + sizeLimitKiB >= 0 ? CalamaresUtils::KiBtoBytes( static_cast< unsigned long long >( sizeLimitKiB ) ) : -1 + }; } /** @brief Load the @p map with strings from @p config diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index ba49f87c3..899b14c78 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -227,7 +227,14 @@ public: * is irrelevant and usually empty), the URL for the upload and the size limit of upload * in bytes (for configuration value < 0, it serves -1, which stands for having no limit). */ - using UploadServerInfo = std::tuple< UploadServerType, QUrl, qint64 >; + struct UploadServerInfo + { + UploadServerType type; + QUrl url; + qint64 size; + + operator bool() const { return type != Calamares::Branding::UploadServerType::None && size != 0; } + }; UploadServerInfo uploadServer() const { return m_uploadServer; } /** diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 5d4109ca2..0c0e324a1 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -152,9 +152,7 @@ ViewManager::insertViewStep( int before, ViewStep* step ) void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { - const auto webPaste = Calamares::Branding::instance()->uploadServer(); - bool shouldOfferWebPaste - = std::get< 0 >( webPaste ) != Calamares::Branding::UploadServerType::None and std::get< 2 >( webPaste ) != 0; + bool shouldOfferWebPaste = bool( Calamares::Branding::instance()->uploadServer() ); cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message;