From efec12d001417980d0d4fe690a8069adc305a5f4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Mar 2021 15:24:02 +0100 Subject: [PATCH] [libcalamares] Read structured upload-server info - Use just type and url, since port can be specified in a URL. Note that we only use host and port, not the scheme (or the path, for that matter). - Factor out understanding the *uploadServer* key to a function. --- src/branding/default/branding.desc | 18 +++++++------- src/libcalamaresui/Branding.cpp | 38 +++++++++++++++++++++--------- src/libcalamaresui/Branding.h | 5 ++-- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index cd83b02f1..90f92b5f1 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -220,15 +220,13 @@ slideshowAPI: 2 # These options are to customize online uploading of logs to pastebins: -# - type : Defines the kind of pastebin service to be used.Currently -# it accepts two values: -# - none : disables the pastebin functionality -# - fiche : use fiche pastebin server -# - url : Defines the address of pastebin service to be used. -# Takes string as input -# - port : Defines the port number to be used to send logs. Takes -# integer as input +# - type : Defines the kind of pastebin service to be used. Currently +# it accepts two values: +# - none : disables the pastebin functionality +# - fiche : use fiche pastebin server +# - url : Defines the address of pastebin service to be used. +# Takes string as input. Important bits are the host and port, +# the scheme is not used. uploadServer : type : "fiche" - url : "termbin.com" - port : 9999 + url : "http://termbin.com:9999" diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a71675e38..3668c0b4b 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -138,6 +138,32 @@ loadStrings( QMap< QString, QString >& map, } } +static Branding::UploadServerInfo +uploadServerFromMap( const QVariantMap& map ) +{ + using Type = Branding::UploadServerType; + // *INDENT-OFF* + // clang-format off + static const NamedEnumTable< Type > names { + { "none", Type::None }, + { "fiche", Type::Fiche } + }; + // clang-format on + // *INDENT-ON* + + QString typestring = map[ "type" ].toString(); + QString urlstring = map[ "url" ].toString(); + + if ( typestring.isEmpty() || urlstring.isEmpty() ) + { + return Branding::UploadServerInfo( Branding::UploadServerType::None, QUrl() ); + } + + bool bogus = false; // we don't care about type-name lookup success here + return Branding::UploadServerInfo( names.find( typestring, bogus ), + QUrl( urlstring, QUrl::ParsingMode::StrictMode ) ); +} + /** @brief Load the @p map with strings from @p config * * If os-release is supported (with KF5 CoreAddons >= 5.58) then @@ -227,11 +253,7 @@ Branding::Branding( const QString& brandingFilePath, QObject* parent ) } ); loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } ); - const QVariantMap temp = CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] ); - for ( auto it = temp.constBegin(); it != temp.constEnd(); ++it ) - { - m_uploadServer.insert( it.key(), it.value().toString() ); - } + m_uploadServer = uploadServerFromMap( CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] ) ); } catch ( YAML::Exception& e ) { @@ -292,12 +314,6 @@ Branding::imagePath( Branding::ImageEntry imageEntry ) const return m_images.value( s_imageEntryStrings.value( imageEntry ) ); } -QString -Branding::uploadServer( Branding::UploadServerEntry uploadServerEntry ) const -{ - return m_uploadServer.value( s_uploadServerStrings.value( uploadServerEntry ) ); -} - QPixmap Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 52c27bfea..831b2adec 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -226,7 +226,8 @@ public: * This is both the type (which may be none, in which case the URL * is irrelevant and usually empty) and the URL for the upload. */ - QPair< UploadServerType, QUrl > uploadServer() const { return m_uploadServer; } + using UploadServerInfo = QPair< UploadServerType, QUrl >; + UploadServerInfo uploadServer() const { return m_uploadServer; } /** * Creates a map called "branding" in the global storage, and inserts an @@ -261,7 +262,7 @@ private: QMap< QString, QString > m_strings; QMap< QString, QString > m_images; QMap< QString, QString > m_style; - QPair< UploadServerType, QUrl > m_uploadServer; + UploadServerInfo m_uploadServer; /* The slideshow can be done in one of two ways: * - as a sequence of images