[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.
main
Adriaan de Groot 4 years ago
parent bce6f3f1b7
commit efec12d001

@ -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"

@ -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
{

@ -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

Loading…
Cancel
Save