From 1438729b727d9fd5b805dfc86e695b01b418e30e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:06:35 +0200 Subject: [PATCH 1/4] [libcalamaresui] Do filename checks more sanely - check directory exists before trying to open file from it - re-use the componentDir already found for later tests. --- src/libcalamaresui/Branding.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 4dc07ff19..4e573e091 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -129,16 +129,16 @@ Branding::Branding( const QString& brandingFilePath, , m_welcomeExpandingLogo( true ) { cDebug() << "Using Calamares branding file at" << brandingFilePath; + + QDir componentDir( componentDirectory() ); + if ( !componentDir.exists() ) + bail( "Bad component directory path." ); + QFile file( brandingFilePath ); if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) ) { QByteArray ba = file.readAll(); - QFileInfo fi ( m_descriptorPath ); - QDir componentDir = fi.absoluteDir(); - if ( !componentDir.exists() ) - bail( "Bad component directory path." ); - try { YAML::Node doc = YAML::Load( ba.constData() ); @@ -146,7 +146,7 @@ Branding::Branding( const QString& brandingFilePath, m_componentName = QString::fromStdString( doc[ "componentName" ] .as< std::string >() ); - if ( m_componentName != QFileInfo( m_descriptorPath ).absoluteDir().dirName() ) + if ( m_componentName != componentDir.dirName() ) bail( "The branding component name should match the name of the " "component directory." ); From 75ce391e7e158eae620fef64738d68e35723dfb6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:22:03 +0200 Subject: [PATCH 2/4] [libcalamaresui] Add branding-aware function for loading image by name --- src/libcalamaresui/Branding.cpp | 17 +++++++++++++++++ src/libcalamaresui/Branding.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 4e573e091..48917f1ba 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -186,6 +186,7 @@ Branding::Branding( const QString& brandingFilePath, loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString { + // See also image() const QString imageName( expand( s ) ); QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) ); if ( !imageFi.exists() ) @@ -314,6 +315,22 @@ Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const } } +QPixmap +Branding::image(const QString& imageName, const QSize& size) const +{ + QDir componentDir( componentDirectory() ); + QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) ); + if ( !imageFi.exists() ) + { + const auto icon = QIcon::fromTheme( imageName ); + // Not found, bail out with the filename used + if ( icon.isNull() ) + return QPixmap(); + return icon.pixmap( size ); + } + return ImageRegistry::instance()->pixmap( imageFi.absoluteFilePath(), size ); +} + QString Branding::stylesheet() const { diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 00174f604..23a7a7a49 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -123,6 +123,16 @@ public: QString styleString( Branding::StyleEntry styleEntry ) const; QString imagePath( Branding::ImageEntry imageEntry ) const; QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; + + /** @brief Look up an image in the branding directory or as an icon + * + * The @p name is checked in the branding directory: if it is an image + * file, return the pixmap from that file, at the requested size. + * If it isn't a file, look it up as an icon name in the current theme. + * May return a null pixmap if nothing is found. + */ + QPixmap image( const QString& name, const QSize& size ) const; + /** @brief Stylesheet to apply for this branding. May be empty. * * The file is loaded every time this function is called, so From 07c638ed48b8b3e99333eb59f9a02ac3faf09386 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 16:59:38 +0200 Subject: [PATCH 3/4] [welcome] Allow theming the international language-select icon --- src/modules/welcome/WelcomePage.cpp | 6 ++++++ src/modules/welcome/WelcomePage.h | 2 ++ src/modules/welcome/WelcomePage.ui | 2 +- src/modules/welcome/WelcomeViewStep.cpp | 9 +++++++++ src/modules/welcome/welcome.conf | 13 +++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index ae78aa8ff..66429ec07 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -270,6 +270,12 @@ WelcomePage::externallySelectedLanguage( int row ) ui->languageWidget->setCurrentIndex( row ); } +void +WelcomePage::setLanguageIcon( QIcon i ) +{ + ui->languageIcon->setPixmap( i.pixmap(48) ); +} + void LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index f05426d38..ec9044a68 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -42,6 +42,8 @@ public: void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); + /// @brief Set international language-selector icon + void setLanguageIcon( QIcon ); /// @brief Results of requirements checking bool verdict() const; diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 51fa19c04..548bd5d27 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -67,7 +67,7 @@ - + Select language diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index e115565b7..0f18cfa2d 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -137,6 +137,15 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } ); future->setFuture( handler->queryRaw() ); } + + + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { + auto icon = QIcon::fromTheme( language ); + if ( !icon.isNull() ) + m_widget->setLanguageIcon( icon ); + } } Calamares::RequirementsList diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index 32b026085..a89b63854 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -64,3 +64,16 @@ geoip: style: "none" url: "https://geoip.kde.org/v1/ubiquity" # extended XML format selector: "CountryCode" # blank uses default, which is wrong + +# User interface +# +# The "select language" icon is an international standard, but it +# might not theme very well with your desktop environment. +# Fill in an icon name (following FreeDesktop standards) to +# use that named icon instead of the usual one. +# +# Leave blank or unset to use the international standard. +# +# Known icons in this space are "set-language" and "config-language". +# +# languageIcon: set-language From f54b7dee9f4a88856fc8f0ec584e4d6c25774edb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 31 May 2019 17:26:30 +0200 Subject: [PATCH 4/4] [welcome] Use convenience image loader from Branding --- src/modules/welcome/WelcomePage.cpp | 4 ++-- src/modules/welcome/WelcomePage.h | 2 +- src/modules/welcome/WelcomeViewStep.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 66429ec07..b29b2e23e 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -271,9 +271,9 @@ WelcomePage::externallySelectedLanguage( int row ) } void -WelcomePage::setLanguageIcon( QIcon i ) +WelcomePage::setLanguageIcon( QPixmap i ) { - ui->languageIcon->setPixmap( i.pixmap(48) ); + ui->languageIcon->setPixmap( i ); } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index ec9044a68..6c244bf0c 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -43,7 +43,7 @@ public: bool showKnownIssuesUrl, bool showReleaseNotesUrl ); /// @brief Set international language-selector icon - void setLanguageIcon( QIcon ); + void setLanguageIcon( QPixmap ); /// @brief Results of requirements checking bool verdict() const; diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 0f18cfa2d..a27cc4cf0 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -24,10 +24,12 @@ #include "geoip/Handler.h" #include "locale/Lookup.h" -#include "modulesystem/ModuleManager.h" #include "utils/Logger.h" #include "utils/Variant.h" +#include "Branding.h" +#include "modulesystem/ModuleManager.h" + #include #include @@ -142,7 +144,7 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); if ( !language.isEmpty() ) { - auto icon = QIcon::fromTheme( language ); + auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); if ( !icon.isNull() ) m_widget->setLanguageIcon( icon ); }