Actually load branding data from default component.
This commit is contained in:
parent
6513c6400e
commit
5e8ab97de4
@ -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"
|
||||||
|
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 149 KiB |
@ -39,6 +39,39 @@ Branding::instance()
|
|||||||
return s_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,
|
Branding::Branding( const QString& brandingFilePath,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
@ -51,20 +84,61 @@ Branding::Branding( const QString& brandingFilePath,
|
|||||||
{
|
{
|
||||||
QByteArray ba = file.readAll();
|
QByteArray ba = file.readAll();
|
||||||
|
|
||||||
|
QFileInfo fi ( m_descriptorPath );
|
||||||
|
QDir componentDir = fi.absoluteDir();
|
||||||
|
if ( !componentDir.exists() )
|
||||||
|
bail( "Bad component directory path." );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( ba.constData() );
|
YAML::Node doc = YAML::Load( ba.constData() );
|
||||||
Q_ASSERT( doc.IsMap() );
|
Q_ASSERT( doc.IsMap() );
|
||||||
|
|
||||||
m_componentName = QString::fromStdString( doc[ "component-name" ]
|
m_componentName = QString::fromStdString( doc[ "componentName" ]
|
||||||
.as< std::string >() );
|
.as< std::string >() );
|
||||||
if ( m_componentName != QFileInfo( m_descriptorPath ).absoluteDir().dirName() )
|
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"
|
QString pathString = it.value().toString();
|
||||||
<< m_descriptorPath
|
QFileInfo imageFi( componentDir.absoluteFilePath( pathString ) );
|
||||||
<< "\nThe branding component name should match the name of the "
|
if ( !imageFi.exists() )
|
||||||
"component directory.";
|
bail( QString( "Image file %1 does not exist." )
|
||||||
::exit( EXIT_FAILURE );
|
.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 )
|
catch ( YAML::Exception& e )
|
||||||
@ -103,4 +177,35 @@ Branding::componentDirectory() const
|
|||||||
return fi.absoluteDir().absolutePath();
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
@ -32,6 +34,9 @@ class UIDLLEXPORT Branding : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum StringEntry : short;
|
||||||
|
enum ImageEntry : short;
|
||||||
|
|
||||||
static Branding* instance();
|
static Branding* instance();
|
||||||
|
|
||||||
explicit Branding( const QString& brandingFilePath,
|
explicit Branding( const QString& brandingFilePath,
|
||||||
@ -41,12 +46,23 @@ public:
|
|||||||
QString componentName() const;
|
QString componentName() const;
|
||||||
QString componentDirectory() const;
|
QString componentDirectory() const;
|
||||||
|
|
||||||
|
QString string( Branding::StringEntry stringEntry ) const;
|
||||||
|
QString image( Branding::ImageEntry imageEntry ) const;
|
||||||
|
QStringList slideshow() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Branding* s_instance;
|
static Branding* s_instance;
|
||||||
|
|
||||||
|
static QStringList s_stringEntryStrings;
|
||||||
|
static QStringList s_imageEntryStrings;
|
||||||
|
|
||||||
|
void bail( const QString& message );
|
||||||
|
|
||||||
QString m_descriptorPath;
|
QString m_descriptorPath;
|
||||||
QString m_componentName;
|
QString m_componentName;
|
||||||
|
QMap< QString, QString > m_strings;
|
||||||
|
QMap< QString, QString > m_images;
|
||||||
|
QStringList m_slideshow;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user