From 822bbaad9c3021a922aaf7b85c6663b0375a72e6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 May 2019 15:26:57 +0200 Subject: [PATCH 1/4] [libcalamaresui] Allow icon names in branding images - It's ok to use path / filenames in images, but you can also use icon names according to the FDO icon spec. This makes sense for at least *productLogo*, possibly *productIcon*, but not really for *productWelcome*. --- src/libcalamaresui/Branding.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a27b39ae6..680e9b926 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) * * Calamares is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -185,9 +186,16 @@ Branding::Branding( const QString& brandingFilePath, loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString { - QFileInfo imageFi( componentDir.absoluteFilePath( expand( s ) ) ); + const QString imageName( expand( s ) ); + QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) ); if ( !imageFi.exists() ) - bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) ); + { + const auto icon = QIcon::fromTheme( imageName ); + // Not found, bail out with the filename used + if ( icon.isNull() ) + bail( QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) ); + return imageName; // Not turned into a path + } return imageFi.absoluteFilePath(); } ); From 976ad7e3e72025bf81add89b75a0968dd5d587fe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 May 2019 15:35:56 +0200 Subject: [PATCH 2/4] [libcalamaresui] Look up icons via theme - Don't cache icons, because they could be changed via the active desktop theme. --- src/libcalamaresui/Branding.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 680e9b926..4dc07ff19 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -297,15 +297,21 @@ Branding::imagePath( Branding::ImageEntry imageEntry ) const QPixmap Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const { - QPixmap pixmap = - ImageRegistry::instance()->pixmap( imagePath( imageEntry ), size ); - - if ( pixmap.isNull() ) + const auto path = imagePath( imageEntry ); + if ( path.contains( '/' ) ) { - Q_ASSERT( false ); - return QPixmap(); + QPixmap pixmap = ImageRegistry::instance()->pixmap( path, size ); + + Q_ASSERT( !pixmap.isNull() ); + return pixmap; + } + else + { + auto icon = QIcon::fromTheme(path); + + Q_ASSERT( !icon.isNull() ); + return icon.pixmap( size ); } - return pixmap; } QString From f64e55f0dc19a18475770c4fe9ca278aff346620 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 May 2019 15:38:37 +0200 Subject: [PATCH 3/4] [libcalamaresui] Use meaningful asserts - In debug mode, hitting assert(false) is meaningless, - In release mode, the assert is optimized out. - So assert the condition we're actually testing, for better messages. --- src/libcalamaresui/utils/ImageRegistry.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libcalamaresui/utils/ImageRegistry.cpp b/src/libcalamaresui/utils/ImageRegistry.cpp index 442017048..96ea92bbb 100644 --- a/src/libcalamaresui/utils/ImageRegistry.cpp +++ b/src/libcalamaresui/utils/ImageRegistry.cpp @@ -61,9 +61,9 @@ ImageRegistry::cacheKey( const QSize& size, float opacity, QColor tint ) QPixmap ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, QColor tint ) { + Q_ASSERT( !(size.width() < 0 || size.height() < 0) ); if ( size.width() < 0 || size.height() < 0 ) { - Q_ASSERT( false ); return QPixmap(); } @@ -159,15 +159,9 @@ ImageRegistry::putInCache( const QString& image, const QSize& size, CalamaresUti if ( s_cache.contains( image ) ) { subcache = s_cache.value( image ); - if ( subcache.contains( mode ) ) { subsubcache = subcache.value( mode ); - -/* if ( subsubcache.contains( size.width() * size.height() ) ) - { - Q_ASSERT( false ); - }*/ } } From 966604892b25f3df776d83d080336afbb202a5b4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 May 2019 16:38:06 +0200 Subject: [PATCH 4/4] CHANGES: mention icon use in branding --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 731465158..6de55bff7 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,10 @@ This release contains contributions from (alphabetically by first name): - *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 + - *branding* allows the use of FreeDesktop.org icon names for the + *productLogo* and *productIcon* keys. If a file is named there, then + the file is used, and otherwise the icon is looked up in the current + theme. # 3.2.8 (2019-05-10) #