|
|
|
@ -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 )
|
|
|
|
|
{
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
cLog() << "FATAL ERROR in"
|
|
|
|
|
<< m_descriptorPath
|
|
|
|
|
<< "\nThe branding component name should match the name of the "
|
|
|
|
|
"component directory.";
|
|
|
|
|
::exit( EXIT_FAILURE );
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|