From 5e8ab97de4a5967450bc3b8c223ea0909e7e52c6 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 16 Oct 2014 16:14:48 +0200 Subject: [PATCH] Actually load branding data from default component. --- src/branding/default/branding.desc | 16 ++- .../images => src/branding/default}/squid.png | Bin src/libcalamaresui/Branding.cpp | 117 +++++++++++++++++- src/libcalamaresui/Branding.h | 16 +++ 4 files changed, 142 insertions(+), 7 deletions(-) rename {data/images => src/branding/default}/squid.png (100%) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 6c6df5504..93ca927cf 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -1,2 +1,16 @@ --- -component-name: default +componentName: default + +strings: + productName: Generic GNU/Linux + version: 1.0 LTS + shortVersion: 1.0 + versionedName: Generic GNU/Linux 1.0 LTS "Rusty Trombone" + shortVersionedName: Generic 1.0 + +images: + productLogo: "squid.png" + productIcon: "squid.png" + +slideshow: + - "squid.png" diff --git a/data/images/squid.png b/src/branding/default/squid.png similarity index 100% rename from data/images/squid.png rename to src/branding/default/squid.png diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 246cb54a6..1be38fb09 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -39,6 +39,39 @@ Branding::instance() return s_instance; } +enum Branding::StringEntry : short +{ + ProductName, + Version, + ShortVersion, + VersionedName, + ShortVersionedName +}; + + +QStringList Branding::s_stringEntryStrings = +{ + "productName", + "version", + "shortVersion", + "versionedName", + "shortVersionedName" +}; + + +enum Branding::ImageEntry : short +{ + ProductLogo, + ProductIcon +}; + + +QStringList Branding::s_imageEntryStrings = +{ + "productLogo", + "productIcon" +}; + Branding::Branding( const QString& brandingFilePath, QObject* parent ) @@ -51,20 +84,61 @@ Branding::Branding( const QString& brandingFilePath, { QByteArray ba = file.readAll(); + QFileInfo fi ( m_descriptorPath ); + QDir componentDir = fi.absoluteDir(); + if ( !componentDir.exists() ) + bail( "Bad component directory path." ); + try { YAML::Node doc = YAML::Load( ba.constData() ); Q_ASSERT( doc.IsMap() ); - m_componentName = QString::fromStdString( doc[ "component-name" ] + m_componentName = QString::fromStdString( doc[ "componentName" ] .as< std::string >() ); if ( m_componentName != QFileInfo( m_descriptorPath ).absoluteDir().dirName() ) + bail( "The branding component name should match the name of the " + "component directory." ); + + if ( !doc[ "strings" ].IsMap() ) + bail( "Syntax error in strings map." ); + + QVariantMap strings = + CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap(); + m_strings.clear(); + for ( auto it = strings.constBegin(); it != strings.constEnd(); ++it ) + m_strings.insert( it.key(), it.value().toString() ); + + if ( !doc[ "images" ].IsMap() ) + bail( "Syntax error in images map." ); + + QVariantMap images = + CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap(); + m_images.clear(); + for ( auto it = images.constBegin(); it != images.constEnd(); ++it ) { - cLog() << "FATAL ERROR in" - << m_descriptorPath - << "\nThe branding component name should match the name of the " - "component directory."; - ::exit( EXIT_FAILURE ); + QString pathString = it.value().toString(); + QFileInfo imageFi( componentDir.absoluteFilePath( pathString ) ); + if ( !imageFi.exists() ) + bail( QString( "Image file %1 does not exist." ) + .arg( imageFi.absoluteFilePath() ) ); + + m_images.insert( it.key(), imageFi.absoluteFilePath() ); + } + + if ( !doc[ "slideshow" ].IsSequence() ) + bail( "Syntax error in slideshow sequence." ); + + doc[ "slideshow" ] >> m_slideshow; + for ( int i = 0; i < m_slideshow.count(); ++i ) + { + QString pathString = m_slideshow[ i ]; + QFileInfo imageFi( componentDir.absoluteFilePath( pathString ) ); + if ( !imageFi.exists() ) + bail( QString( "Slideshow file %1 does not exist." ) + .arg( imageFi.absoluteFilePath() ) ); + + m_slideshow[ i ] = imageFi.absoluteFilePath(); } } catch ( YAML::Exception& e ) @@ -103,4 +177,35 @@ Branding::componentDirectory() const return fi.absoluteDir().absolutePath(); } + +QString +Branding::string( Branding::StringEntry stringEntry ) const +{ + return m_strings.value( s_stringEntryStrings.value( stringEntry ) ); +} + + +QString +Branding::image( Branding::ImageEntry imageEntry ) const +{ + return m_images.value( s_imageEntryStrings.value( imageEntry ) ); +} + + +QStringList +Branding::slideshow() const +{ + return m_slideshow; +} + + +void +Branding::bail( const QString& message ) +{ + cLog() << "FATAL ERROR in" + << m_descriptorPath + << "\n" + message; + ::exit( EXIT_FAILURE ); +} + } diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index faad18511..b0b86f793 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -23,6 +23,8 @@ #include "Typedefs.h" #include +#include +#include namespace Calamares @@ -32,6 +34,9 @@ class UIDLLEXPORT Branding : public QObject { Q_OBJECT public: + enum StringEntry : short; + enum ImageEntry : short; + static Branding* instance(); explicit Branding( const QString& brandingFilePath, @@ -41,12 +46,23 @@ public: QString componentName() const; QString componentDirectory() const; + QString string( Branding::StringEntry stringEntry ) const; + QString image( Branding::ImageEntry imageEntry ) const; + QStringList slideshow() const; private: static Branding* s_instance; + static QStringList s_stringEntryStrings; + static QStringList s_imageEntryStrings; + + void bail( const QString& message ); + QString m_descriptorPath; QString m_componentName; + QMap< QString, QString > m_strings; + QMap< QString, QString > m_images; + QStringList m_slideshow; }; }