Merge branch 'issue-1150'

FIXES #1150
main
Adriaan de Groot 6 years ago
commit fbb65d06eb

@ -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) #

@ -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

@ -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 .

@ -26,7 +26,7 @@
#include "utils/Logger.h"
#include "CalamaresConfig.h"
#ifdef WITH_KCRASH
#ifdef WITH_KF5Crash
#include <KF5/KCrash/KCrash>
#include <KF5/KCoreAddons/KAboutData>
#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(),

@ -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

@ -32,6 +32,13 @@
#include <QPixmap>
#include <QVariantMap>
#include <functional>
#ifdef WITH_KOSRelease
#include <KMacroExpander>
#include <KOSRelease>
#endif
namespace Calamares
{
@ -87,6 +94,32 @@ Branding::WindowDimension::suffixes()
return names;
}
/** @brief Load the @p map with strings from @p doc
*
* 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<QString, QString>& 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() ) );
}
/** @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.
*/
Branding::Branding( const QString& brandingFilePath,
QObject* parent )
: QObject( parent )
@ -118,31 +151,49 @@ Branding::Branding( const QString& brandingFilePath,
initSimpleSettings( doc );
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() );
}
#ifdef WITH_KOSRelease
KOSRelease relInfo;
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, QLatin1Char( '@' ) ); }
);
#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
{
QFileInfo imageFi( componentDir.absoluteFilePath( s ) );
if ( !imageFi.exists() )
bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) );
return imageFi.absoluteFilePath();
}
);
loadStrings( m_style, doc, "style",
[]( const QString& s ) -> QString { return s; }
);
if ( doc[ "slideshow" ].IsSequence() )
{
@ -174,20 +225,11 @@ 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 )
{
CalamaresUtils::explainYamlException( e, ba, file.fileName() );
bail( e.what() );
}
QDir translationsDir( componentDir.filePath( "lang" ) );

@ -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
@ -84,3 +83,9 @@ 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 )
target_link_libraries( calamaresui PRIVATE KF5::CoreAddons )
endif()

@ -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()

Loading…
Cancel
Save