From 1cf3ac810abed23fdd915f8cf0dc1bd6c5d142c8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 12:25:23 +0200 Subject: [PATCH 01/13] [calamares] avoid extra defines for KCrash - Don't need an extra indirection from WITH_KF5Crash to WITH_KCRASH, just use the cmakedefine directly. - Since the setting is only used in main.cpp, move the define down there and remove cmakedefine entirely. --- src/calamares/CMakeLists.txt | 16 ++++++++-------- src/calamares/main.cpp | 4 ++-- src/libcalamares/CalamaresConfig.h.in | 6 ------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 1857b2b79..659865792 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -39,21 +39,21 @@ set_target_properties(calamares_bin ) calamares_automoc( calamares_bin ) -if( WITH_KF5Crash ) - set( LINK_LIBRARIES - KF5::CoreAddons - KF5::Crash - ) -endif() - target_link_libraries( calamares_bin PRIVATE ${CALAMARES_LIBRARIES} calamaresui Qt5::Core Qt5::Widgets - ${LINK_LIBRARIES} ) +if( WITH_KF5Crash ) + target_link_libraries( calamares_bin + PRIVATE + KF5::CoreAddons + KF5::Crash + ) + target_compile_definitions( calamares_bin PRIVATE WITH_KF5Crash ) +endif() install( TARGETS calamares_bin BUNDLE DESTINATION . diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 5ddda33c6..f218b8ab9 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -26,7 +26,7 @@ #include "utils/Logger.h" #include "CalamaresConfig.h" -#ifdef WITH_KCRASH +#ifdef WITH_KF5Crash #include #include #endif @@ -84,7 +84,7 @@ main( int argc, char* argv[] ) { CalamaresApplication a( argc, argv ); -#ifdef WITH_KCRASH +#ifdef WITH_KF5Crash KAboutData aboutData( "calamares", "Calamares", a.applicationVersion(), diff --git a/src/libcalamares/CalamaresConfig.h.in b/src/libcalamares/CalamaresConfig.h.in index cafbe9276..6fbab422c 100644 --- a/src/libcalamares/CalamaresConfig.h.in +++ b/src/libcalamares/CalamaresConfig.h.in @@ -10,12 +10,6 @@ //cmakedefines for CMake variables (e.g. for optdepends) go here #cmakedefine WITH_PYTHON - -#cmakedefine WITH_KF5Crash -#ifdef WITH_KF5Crash -#define WITH_KCRASH -#endif - #cmakedefine WITH_PYTHONQT #endif // CALAMARESCONFIG_H From 0c4d77541f827b188c3994e7760ee465d6f71202 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 12:59:28 +0200 Subject: [PATCH 02/13] [plasmalnf] simplify KF5-finding - No need to double-up package finding. --- src/modules/plasmalnf/CMakeLists.txt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index e39b1af9f..93c88b291 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -21,14 +21,6 @@ set_package_properties( ) if ( KF5Plasma_FOUND AND KF5Package_FOUND ) - if ( KF5Config_FOUND ) - set( option_kf5 Config ) - set( option_defs WITH_KCONFIG ) - # set( option_libs KF5::Config ) # Not needed anyway - endif() - - find_package( KF5 ${lnf_ver} REQUIRED CoreAddons Plasma Package ${option_kf5} ) - calamares_add_plugin( plasmalnf TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO @@ -45,11 +37,13 @@ if ( KF5Plasma_FOUND AND KF5Package_FOUND ) page_plasmalnf.ui LINK_PRIVATE_LIBRARIES calamaresui - ${option_libs} KF5::Package KF5::Plasma SHARED_LIB ) + if ( KF5Config_FOUND ) + target_compile_definitions(calamares_viewmodule_plasmalnf PRIVATE WITH_KCONFIG) + endif() else() calamares_skip_module( "plasmalnf (missing requirements)" ) endif() From a9f3b4050c2ae2890c726a0e04d712003f3d37e3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 13:21:39 +0200 Subject: [PATCH 03/13] [libcalamaresui] don't over-complicate PythonQt library linking --- src/libcalamaresui/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index aaa383fde..9b37c89d7 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -64,8 +64,7 @@ if( WITH_PYTHONQT ) viewpages/PythonQtGlobalStorageWrapper.cpp viewpages/PythonQtUtilsWrapper.cpp ) - set( OPTIONAL_PRIVATE_LIBRARIES - ${OPTIONAL_PRIVATE_LIBRARIES} + set( OPTIONAL_PYTHON_LIBRARIES ${PYTHON_LIBRARIES} ${PYTHONQT_LIBRARIES} ) @@ -76,7 +75,7 @@ calamares_add_library( calamaresui UI ${calamaresui_UI} EXPORT_MACRO UIDLLEXPORT_PRO LINK_PRIVATE_LIBRARIES - ${OPTIONAL_PRIVATE_LIBRARIES} + ${OPTIONAL_PYTHON_LIBRARIES} LINK_LIBRARIES Qt5::Svg Qt5::QuickWidgets From 5bae7b7b52c680c4f695d89cdb5425d168b509b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 13:25:07 +0200 Subject: [PATCH 04/13] [libcalamaresui] check for sufficiently-new KF5CoreAddons - From 5.58, KOSRelease is available (not used yet, though) --- src/libcalamaresui/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 9b37c89d7..7776cd496 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -83,3 +83,8 @@ calamares_add_library( calamaresui EXPORT CalamaresLibraryDepends VERSION ${CALAMARES_VERSION_SHORT} ) + +find_package( KF5CoreAddons 5.58 QUIET ) # If it's really new +if ( KF5CoreAddons_FOUND ) + target_compile_definitions( calamaresui PRIVATE WITH_KOSRelease ) +endif() From 5a126816f4ccfd671f997a67574e1dcbf266f534 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 15:49:13 +0200 Subject: [PATCH 05/13] [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. --- src/libcalamaresui/Branding.cpp | 80 +++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index b7bf4c7aa..f9e5751f3 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -87,6 +87,52 @@ Branding::WindowDimension::suffixes() 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& 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& 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& 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, QObject* parent ) : QObject( parent ) @@ -120,29 +166,15 @@ Branding::Branding( const QString& brandingFilePath, 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() ); + loadStrings( m_strings, CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap() ); if ( !doc[ "images" ].IsMap() ) bail( "Syntax error in images map." ); + loadImages( m_images, CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap() ); - 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[ "style" ].IsMap() ) + bail( "Syntax error in style map." ); + loadStyles( m_style, CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap() ); if ( doc[ "slideshow" ].IsSequence() ) { @@ -174,16 +206,6 @@ Branding::Branding( const QString& brandingFilePath, } else 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 ) { From 544d905b2f31f6b556d500bf96651437bb6c504b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 16:20:31 +0200 Subject: [PATCH 06/13] [libcalamaresui] WIP: refactor again - the string-manipulation can be done through a lambda. That makes handling *strings* and *styles* simple. - still doesn't compile. --- src/libcalamaresui/Branding.cpp | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index f9e5751f3..a618a901d 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -32,6 +32,8 @@ #include #include +#include + namespace Calamares { @@ -89,18 +91,25 @@ Branding::WindowDimension::suffixes() /** @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. + * Each key-value pair from @p config is inserted into the @p map, + * but the value is first transformed by the @p transform function, + * which may change strings. */ static void -loadStrings(QMap& map, const QVariantMap& config) +loadStrings( QMap& map, const QVariantMap& config, const std::function< QString(const QString&) >& transform ) { map.clear(); for ( auto it = config.constBegin(); it != config.constEnd(); ++it ) - map.insert( it.key(), it.value().toString() ); + map.insert( it.key(), transform( it.value().toString() ) ); } +/** @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. + */ + /** @brief Load the @p map of image-filepaths from @p config * * Paths are translated relative to componentDir, and must exist. @@ -123,16 +132,6 @@ loadImages(QMap& map, const QVariantMap& config) } } -/** @brief Load the @p map with stylesheet-strings from @p config. - */ -static void -loadStyles(QMap& 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, QObject* parent ) : QObject( parent ) @@ -166,7 +165,8 @@ Branding::Branding( const QString& brandingFilePath, if ( !doc[ "strings" ].IsMap() ) bail( "Syntax error in strings map." ); - loadStrings( m_strings, CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap() ); + loadStrings( m_strings, CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap(), + []( const QString& s ) -> QString { return s; } ); if ( !doc[ "images" ].IsMap() ) bail( "Syntax error in images map." ); @@ -174,7 +174,8 @@ Branding::Branding( const QString& brandingFilePath, if ( !doc[ "style" ].IsMap() ) bail( "Syntax error in style map." ); - loadStyles( m_style, CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap() ); + loadStrings( m_style, CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap(), + []( const QString& s ) -> QString { return s; } ); if ( doc[ "slideshow" ].IsSequence() ) { From 62328c99402bd730a33ea0a4f45afd3797882bbb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 16:26:30 +0200 Subject: [PATCH 07/13] [libcalamaresui] images-strings loading fixed - move the string-munge into a lambda and use the generic loadStrings() --- src/libcalamaresui/Branding.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a618a901d..4fb2721d8 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -110,28 +110,6 @@ loadStrings( QMap& map, const QVariantMap& config, const std:: * documentation for details. */ -/** @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& 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() ); - } -} - Branding::Branding( const QString& brandingFilePath, QObject* parent ) : QObject( parent ) @@ -170,7 +148,15 @@ Branding::Branding( const QString& brandingFilePath, if ( !doc[ "images" ].IsMap() ) bail( "Syntax error in images map." ); - loadImages( m_images, CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap() ); + loadStrings( m_images, CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap(), + [&]( const QString& s ) -> QString + { + QFileInfo imageFi( componentDir.absoluteFilePath( s ) ); + if ( !imageFi.exists() ) + bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) ); + return imageFi.absoluteFilePath(); + } + ); if ( !doc[ "style" ].IsMap() ) bail( "Syntax error in style map." ); From 667f78c0162ffd727590e7b7cc9e2682469de95c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 16:37:20 +0200 Subject: [PATCH 08/13] [libcalamaresui] if there's a YAML exception in branding, bail - all kinds of type errors result in bailing out, but a totally broken branding file does not? --- src/libcalamaresui/Branding.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 4fb2721d8..6b2266c3b 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -197,6 +197,7 @@ Branding::Branding( const QString& brandingFilePath, catch ( YAML::Exception& e ) { CalamaresUtils::explainYamlException( e, ba, file.fileName() ); + bail( e.what() ); } QDir translationsDir( componentDir.filePath( "lang" ) ); From 92d0e71029b4ecbed501e6595773c94b6a952a7f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 17:00:43 +0200 Subject: [PATCH 09/13] [libcalamaresui] one more refactor for string-loading - Do the checking for IsMap inside loadStrings() and use YAML::Exception to get to bail() (since we're already dealing with exceptions here, no extra costs). This tidies up the code somewhat. --- src/libcalamaresui/Branding.cpp | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 6b2266c3b..3043a74e5 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -89,15 +89,20 @@ Branding::WindowDimension::suffixes() return names; } -/** @brief Load the @p map with strings from @p config +/** @brief Load the @p map with strings from @p doc * - * Each key-value pair from @p config is inserted into the @p map, - * but the value is first transformed by the @p transform function, - * which may change strings. + * Each key-value pair from the sub-map in @p doc identified by @p key + * is inserted into the @p map, but the value is first transformed by + * the @p transform function, which may change strings. */ static void -loadStrings( QMap& map, const QVariantMap& config, const std::function< QString(const QString&) >& transform ) +loadStrings( QMap& map, const YAML::Node& doc, const std::string& key, const std::function< QString(const QString&) >& transform ) { + if ( !doc[ key ].IsMap() ) + throw YAML::Exception( YAML::Mark(), std::string("Branding configuration is not a map: ") + key ); + + const auto& config = CalamaresUtils::yamlMapToVariant( doc[ key ] ).toMap(); + map.clear(); for ( auto it = config.constBegin(); it != config.constEnd(); ++it ) map.insert( it.key(), transform( it.value().toString() ) ); @@ -141,14 +146,10 @@ Branding::Branding( const QString& brandingFilePath, initSimpleSettings( doc ); - if ( !doc[ "strings" ].IsMap() ) - bail( "Syntax error in strings map." ); - loadStrings( m_strings, CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap(), - []( const QString& s ) -> QString { return s; } ); - - if ( !doc[ "images" ].IsMap() ) - bail( "Syntax error in images map." ); - loadStrings( m_images, CalamaresUtils::yamlMapToVariant( doc[ "images" ] ).toMap(), + loadStrings( m_strings, doc, "strings", + []( const QString& s ) -> QString { return s; } + ); + loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString { QFileInfo imageFi( componentDir.absoluteFilePath( s ) ); @@ -156,12 +157,10 @@ Branding::Branding( const QString& brandingFilePath, bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) ); return imageFi.absoluteFilePath(); } - ); - - if ( !doc[ "style" ].IsMap() ) - bail( "Syntax error in style map." ); - loadStrings( m_style, CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap(), - []( const QString& s ) -> QString { return s; } ); + ); + loadStrings( m_style, doc, "style", + []( const QString& s ) -> QString { return s; } + ); if ( doc[ "slideshow" ].IsSequence() ) { From fbbbe63642fdfc7c9e1e46ea47cc590c8cd3d97c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 22:11:11 +0200 Subject: [PATCH 10/13] [libcalamaresui] WIP: Use KOSRelease and KMacroExpander in branding - allows you to use -- at runtime -- values from os-release in the branding file. - WIP because the only machine I have with sufficiently new KF5 is the FreeBSD box. --- src/libcalamaresui/Branding.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 3043a74e5..5a5ce4016 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -34,6 +34,11 @@ #include +#ifdef WITH_KOSRelease +#include +#include +#endif + namespace Calamares { @@ -146,9 +151,36 @@ Branding::Branding( const QString& brandingFilePath, initSimpleSettings( doc ); +#ifdef WITH_KOSRelease + KOSRelease relInfo; + QHash relMap; + relMap << "NAME" << relInfo.name() + << "VERSION" << relInfo.version() + << "ID" << relInfo.id() + << "ID_LIKE" << relInfo.idLike() + << "VERSION_CODENAME" << relInfo.versionCodename() + << "VERSION_ID" << relInfo.versionId() + << "PRETTY_NAME" << relInfo.prettyName() + << "HOME_URL" << relInfo.homeUrl() + << "DOCUMENTATION_URL" << relInfo.documentationUrl() + << "SUPPORT_URL" << relInfo.supportUrl() + << "BUG_REPORT_URL" << relInfo.bugReportUrl() + << "PRIVACY_POLICY_URL" << relInfo.privacyPolicyUrl() + << "BUILD_ID" << relInfo.buildId() + << "VARIANT" << relInfo.variant() + << "VARIANT_ID" << relInfo.variantId() + << "LOGO" << relInfo.logo(); + + + loadStrings( m_strings, doc, "strings", + [&]( const QString& s ) -> QString { return KMacroExpander::expandMacros{ s, relMap, '@' ); } + ); +#else + // No support for substituting in os-release values. loadStrings( m_strings, doc, "strings", []( const QString& s ) -> QString { return s; } ); +#endif loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString { From af73d90b7b72552ac245db1b6fe8054b06b17b69 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 22:54:54 +0200 Subject: [PATCH 11/13] [libcalamaresui] Fix build with KOSRelease - initialization of the hash was all wrong - special-case ID_LIKE - typo's - link to CoreAddons --- src/libcalamaresui/Branding.cpp | 41 ++++++++++++++++--------------- src/libcalamaresui/CMakeLists.txt | 1 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 5a5ce4016..2f9407bb7 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -153,27 +153,28 @@ Branding::Branding( const QString& brandingFilePath, #ifdef WITH_KOSRelease KOSRelease relInfo; - QHash relMap; - relMap << "NAME" << relInfo.name() - << "VERSION" << relInfo.version() - << "ID" << relInfo.id() - << "ID_LIKE" << relInfo.idLike() - << "VERSION_CODENAME" << relInfo.versionCodename() - << "VERSION_ID" << relInfo.versionId() - << "PRETTY_NAME" << relInfo.prettyName() - << "HOME_URL" << relInfo.homeUrl() - << "DOCUMENTATION_URL" << relInfo.documentationUrl() - << "SUPPORT_URL" << relInfo.supportUrl() - << "BUG_REPORT_URL" << relInfo.bugReportUrl() - << "PRIVACY_POLICY_URL" << relInfo.privacyPolicyUrl() - << "BUILD_ID" << relInfo.buildId() - << "VARIANT" << relInfo.variant() - << "VARIANT_ID" << relInfo.variantId() - << "LOGO" << relInfo.logo(); - - + + QHash< QString, QString > relMap{ + std::initializer_list< std::pair< QString, QString > > { + { QStringLiteral( "NAME" ), relInfo.name() }, + { QStringLiteral( "VERSION" ), relInfo.version() }, + { QStringLiteral( "ID" ), relInfo.id() }, + { QStringLiteral( "ID_LIKE" ), relInfo.idLike().join( ' ' ) }, + { QStringLiteral( "VERSION_CODENAME" ), relInfo.versionCodename() }, + { QStringLiteral( "VERSION_ID" ), relInfo.versionId() }, + { QStringLiteral( "PRETTY_NAME" ), relInfo.prettyName() }, + { QStringLiteral( "HOME_URL" ), relInfo.homeUrl() }, + { QStringLiteral( "DOCUMENTATION_URL" ), relInfo.documentationUrl() }, + { QStringLiteral( "SUPPORT_URL" ), relInfo.supportUrl() }, + { QStringLiteral( "BUG_REPORT_URL" ), relInfo.bugReportUrl() }, + { QStringLiteral( "PRIVACY_POLICY_URL" ), relInfo.privacyPolicyUrl() }, + { QStringLiteral( "BUILD_ID" ), relInfo.buildId() }, + { QStringLiteral( "VARIANT" ), relInfo.variant() }, + { QStringLiteral( "VARIANT_ID" ), relInfo.variantId() }, + { QStringLiteral( "LOGO" ), relInfo.logo() } + } }; loadStrings( m_strings, doc, "strings", - [&]( const QString& s ) -> QString { return KMacroExpander::expandMacros{ s, relMap, '@' ); } + [&]( const QString& s ) -> QString { return KMacroExpander::expandMacros( s, relMap, QLatin1Char( '@' ) ); } ); #else // No support for substituting in os-release values. diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 7776cd496..f6c8c9ac7 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -87,4 +87,5 @@ calamares_add_library( calamaresui find_package( KF5CoreAddons 5.58 QUIET ) # If it's really new if ( KF5CoreAddons_FOUND ) target_compile_definitions( calamaresui PRIVATE WITH_KOSRelease ) + target_link_libraries( calamaresui PRIVATE KF5::CoreAddons ) endif() From a30edb194a352ff0424d6154102a0df4f366be7e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 23:07:10 +0200 Subject: [PATCH 12/13] [branding] Update branding.desc with new os-release feature - Point to supported keys on the fd.o site - Point out need for quoting - Update example with "@{NAME}" for the window-title --- src/branding/default/branding.desc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 5fefc422a..3f6268cc5 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -40,8 +40,18 @@ windowSize: 800px,520px # # bootloaderEntryName is how this installation / distro is named # in the boot loader (e.g. in the GRUB menu). +# +# These strings support substitution from /etc/os-release +# if KDE Frameworks 5.58 are available at build-time. When +# enabled, @{var-name} is replaced by the equivalent value +# from os-release. All the supported var-names are in all-caps, +# and are listed on the FreeDesktop.org site, +# https://www.freedesktop.org/software/systemd/man/os-release.html +# Note that ANSI_COLOR and CPE_NAME don't make sense here, and +# are not supported (the rest are). Remember to quote the string +# if it contains substitutions, or you'll get YAML exceptions. strings: - productName: Generic GNU/Linux + productName: "@{NAME}" shortProductName: Generic version: 2017.8 LTS shortVersion: 2017.8 From 6c1b7f185dfea254279c71b3823eeca0c9d443ca Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 20 May 2019 23:10:18 +0200 Subject: [PATCH 13/13] CHANGES: mention os-release feature --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 17a14f317..731465158 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,9 @@ This release contains contributions from (alphabetically by first name): ## Modules ## + - *branding* now supports os-release variables in the *strings* section, + which allows re-using (at runtime) information set in /etc/os-release . + This requires KDE Frameworks 5.58. #1150 # 3.2.8 (2019-05-10) #