Actually load branding data from default component.

This commit is contained in:
Teo Mrnjavac 2014-10-16 16:14:48 +02:00
parent 6513c6400e
commit 5e8ab97de4
4 changed files with 142 additions and 7 deletions

View File

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

View File

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 149 KiB

View File

@ -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 );
}
}

View File

@ -23,6 +23,8 @@
#include "Typedefs.h"
#include <QObject>
#include <QStringList>
#include <QMap>
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;
};
}