[libcalamaresui] Support os-release substitutions in images

- Branding images might want to use os-release data as well.
 - Refactor a little to keep the number of #ifdefs the same;
   an intermediate expand() lambda handles expansion (or not,
   if it's not enabled).

FIXES #1153
main
Adriaan de Groot 5 years ago
parent 368e7aac16
commit cd38ded8d5

@ -83,6 +83,8 @@ strings:
# any size and proportion, and will be scaled to fit inside
# the window. Use `welcomeExpandingLogo` to make it non-scaled.
# Recommended size is 320x150.
#
# These strings can also use substitutions from os-release (see above).
images:
productLogo: "squid.png"
productIcon: "squid.png"

@ -152,6 +152,7 @@ Branding::Branding( const QString& brandingFilePath,
initSimpleSettings( doc );
#ifdef WITH_KOSRelease
// Copy the os-release information into a QHash for use by KMacroExpander.
KOSRelease relInfo;
QHash< QString, QString > relMap{
@ -173,19 +174,18 @@ Branding::Branding( const QString& brandingFilePath,
{ QStringLiteral( "VARIANT_ID" ), relInfo.variantId() },
{ QStringLiteral( "LOGO" ), relInfo.logo() }
} };
loadStrings( m_strings, doc, "strings",
[&]( const QString& s ) -> QString { return KMacroExpander::expandMacros( s, relMap, QLatin1Char( '@' ) ); }
);
auto expand = [&]( const QString& s ) -> QString { return KMacroExpander::expandMacros( s, relMap, QLatin1Char( '@' ) ); };
#else
// No support for substituting in os-release values.
loadStrings( m_strings, doc, "strings",
[]( const QString& s ) -> QString { return s; }
);
auto expand = []( const QString& s ) -> QString { return s; };
#endif
// Massage the strings, images and style sections.
loadStrings( m_strings, doc, "strings", expand );
loadStrings( m_images, doc, "images",
[&]( const QString& s ) -> QString
{
QFileInfo imageFi( componentDir.absoluteFilePath( s ) );
QFileInfo imageFi( componentDir.absoluteFilePath( expand( s ) ) );
if ( !imageFi.exists() )
bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) );
return imageFi.absoluteFilePath();

Loading…
Cancel
Save