[libcalamaresui] WIP: refactor copying strings from config to Branding
- this is mostly to make the constructor easier to read by moving parts of the story to easily-understood methods. - doesn't actually compile.
This commit is contained in:
parent
5bae7b7b52
commit
5a126816f4
@ -87,6 +87,52 @@ Branding::WindowDimension::suffixes()
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Load the @p map with strings from @p config
|
||||||
|
*
|
||||||
|
* If os-release is supported (with KF5 CoreAddons >= 5.58) then
|
||||||
|
* special substitutions can be done as well. See the branding
|
||||||
|
* documentation for details.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
loadStrings(QMap<QString, QString>& map, const QVariantMap& config)
|
||||||
|
{
|
||||||
|
map.clear();
|
||||||
|
for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
|
||||||
|
map.insert( it.key(), it.value().toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Load the @p map of image-filepaths from @p config
|
||||||
|
*
|
||||||
|
* Paths are translated relative to componentDir, and must exist.
|
||||||
|
* All paths are transformed to absolute paths before putting
|
||||||
|
* them in the map.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
loadImages(QMap<QString, QString>& map, const QVariantMap& config)
|
||||||
|
{
|
||||||
|
map.clear();
|
||||||
|
for ( auto it = config.constBegin(); it != config.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() ) );
|
||||||
|
|
||||||
|
map.insert( it.key(), imageFi.absoluteFilePath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Load the @p map with stylesheet-strings from @p config.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
loadStyles(QMap<QString, QString>& map, const QVariantMap& config)
|
||||||
|
{
|
||||||
|
map.clear();
|
||||||
|
for ( auto it = config.constBegin(); it != config.constEnd(); ++it )
|
||||||
|
map.insert( it.key(), it.value().toString() );
|
||||||
|
}
|
||||||
|
|
||||||
Branding::Branding( const QString& brandingFilePath,
|
Branding::Branding( const QString& brandingFilePath,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
@ -120,29 +166,15 @@ Branding::Branding( const QString& brandingFilePath,
|
|||||||
|
|
||||||
if ( !doc[ "strings" ].IsMap() )
|
if ( !doc[ "strings" ].IsMap() )
|
||||||
bail( "Syntax error in strings map." );
|
bail( "Syntax error in strings map." );
|
||||||
|
loadStrings( m_strings, CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap() );
|
||||||
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() )
|
if ( !doc[ "images" ].IsMap() )
|
||||||
bail( "Syntax error in images map." );
|
bail( "Syntax error in images map." );
|
||||||
|
loadImages( m_images, CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap() );
|
||||||
|
|
||||||
QVariantMap images =
|
if ( !doc[ "style" ].IsMap() )
|
||||||
CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap();
|
bail( "Syntax error in style map." );
|
||||||
m_images.clear();
|
loadStyles( m_style, CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap() );
|
||||||
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() )
|
if ( doc[ "slideshow" ].IsSequence() )
|
||||||
{
|
{
|
||||||
@ -174,16 +206,6 @@ Branding::Branding( const QString& brandingFilePath,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
bail( "Syntax error in slideshow sequence." );
|
bail( "Syntax error in slideshow sequence." );
|
||||||
|
|
||||||
if ( !doc[ "style" ].IsMap() )
|
|
||||||
bail( "Syntax error in style map." );
|
|
||||||
|
|
||||||
QVariantMap style =
|
|
||||||
CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap();
|
|
||||||
m_style.clear();
|
|
||||||
for ( auto it = style.constBegin(); it != style.constEnd(); ++it )
|
|
||||||
m_style.insert( it.key(), it.value().toString() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( YAML::Exception& e )
|
catch ( YAML::Exception& e )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user