From c2efae765da30d3c3e28518ed8f8a976143bc007 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 29 Mar 2018 08:49:22 -0400 Subject: [PATCH] [plasmalnf] Add auto-detection of Plasma theme. - Although it's not necessarily accurate for an extensively-modified Plasma configuration, we can read the Look-and-Feel from the configuration files. Allows auto-detection. --- src/modules/plasmalnf/CMakeLists.txt | 16 +++++++++++++++- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 19 +++++++++++++++++++ src/modules/plasmalnf/plasmalnf.conf | 6 +++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 15897f98c..e39b1af9f 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -4,8 +4,13 @@ find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) # needs a runtime support component (which we don't test for). set( lnf_ver 5.41 ) +find_package( KF5Config ${lnf_ver} ) find_package( KF5Plasma ${lnf_ver} ) find_package( KF5Package ${lnf_ver} ) +set_package_properties( + KF5Config PROPERTIES + PURPOSE "For finding default Plasma Look-and-Feel" +) set_package_properties( KF5Plasma PROPERTIES PURPOSE "For Plasma Look-and-Feel selection" @@ -16,11 +21,19 @@ set_package_properties( ) if ( KF5Plasma_FOUND AND KF5Package_FOUND ) - find_package( KF5 ${lnf_ver} REQUIRED CoreAddons Plasma Package ) + 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 + COMPILE_DEFINITIONS + ${option_defs} SOURCES PlasmaLnfViewStep.cpp PlasmaLnfPage.cpp @@ -32,6 +45,7 @@ if ( KF5Plasma_FOUND AND KF5Package_FOUND ) page_plasmalnf.ui LINK_PRIVATE_LIBRARIES calamaresui + ${option_libs} KF5::Package KF5::Plasma SHARED_LIB diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index a14b8e338..2ba4f7bca 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -26,8 +26,25 @@ #include #include +#ifdef WITH_KCONFIG +#include +#include +#endif + CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin(); ) +static QString +currentPlasmaTheme() +{ +#ifdef WITH_KCONFIG + KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" ); + return cg.readEntry( "LookAndFeelPackage", QString() ); +#else + cWarning() << "No KConfig support, cannot determine Plasma theme."; + return QString(); +#endif +} + PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new PlasmaLnfPage ) @@ -140,6 +157,8 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap ) QString preselect; if ( configurationMap.contains( "preselect" ) && configurationMap.value( "preselect" ).type() == QVariant::String ) preselect = configurationMap.value( "preselect" ).toString(); + if ( preselect == QStringLiteral( "*" ) ) + preselect = currentPlasmaTheme(); if ( !preselect.isEmpty() ) m_widget->setPreselect( preselect ); diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index 49a91b3b5..e6ed88e77 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -38,4 +38,8 @@ themes: # If this key is present, its value should be the id of the theme # which should be pre-selected. If absent, empty, or the pre-selected # theme is not found on the live system, no theme will be pre-selected. -preselect: org.kde.breeze.desktop +# +# As a special setting, use "*", to try to find the currently- +# selected theme by reading the Plasma configuration. This requires +# KF5::Config at build- and run-time. +preselect: "*"