[plasmalnf] Hammer in theme-changing

- Tool is currently a hard-coded path.
This commit is contained in:
Adriaan de Groot 2017-12-03 09:18:18 -05:00
parent 8c65ee5481
commit 2d3defcca3
5 changed files with 57 additions and 4 deletions

View File

@ -1,6 +1,6 @@
find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service )
find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service Package )
calamares_add_plugin( plasmalnf
TYPE viewmodule
@ -13,6 +13,7 @@ calamares_add_plugin( plasmalnf
page_plasmalnf.ui
LINK_PRIVATE_LIBRARIES
calamaresui
KF5::Package
KF5::Plasma
KF5::Service
SHARED_LIB

View File

@ -29,6 +29,8 @@
#include <KPluginLoader> // Future
#include <Plasma/PluginLoader> // TODO: port to KPluginLoader
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include "utils/Logger.h"
@ -36,6 +38,20 @@
namespace Calamares
{
QStringList themes_by_package()
{
QStringList packages;
QList<KPluginMetaData> pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel");
for (const KPluginMetaData &data : pkgs) {
packages << data.pluginId();
}
return packages;
}
QStringList themes_by_service()
{
KService::List services;
@ -88,7 +104,7 @@ QStringList themes_by_lnftool()
QStringList packages;
QProcess lnftool;
lnftool.start( "lookandfeeltool", {"--list"} );
lnftool.start( Calamares::lnftool(), {"--list"} );
if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
{
packages = QString::fromLocal8Bit( lnftool.readAllStandardOutput() ).trimmed().split('\n');
@ -96,4 +112,17 @@ QStringList themes_by_lnftool()
return packages;
}
QStringList plasma_themes()
{
QStringList l( themes_by_package() );
if (l.isEmpty())
return themes_by_lnftool();
return l;
}
QString lnftool()
{
return "/home/adridg/bin/lookandfeeltool";
}
} // namespace Calamares

View File

@ -23,11 +23,15 @@
namespace Calamares
{
QString lnftool();
/* Internal */
QStringList themes_by_package();
QStringList themes_by_service();
QStringList themes_by_kcm();
QStringList themes_by_lnftool();
QStringList plasma_themes();
}
#endif // PLASMALNFINFO_H

View File

@ -32,6 +32,7 @@
#include <QButtonGroup>
#include <QDesktopServices>
#include <QLabel>
#include <QProcess>
PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
: QWidget( parent )
@ -45,7 +46,22 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) );
)
Calamares::themes_by_service();
ui->lnfCombo->addItems( Calamares::themes_by_lnftool() );
Calamares::themes_by_package();
ui->lnfCombo->addItems( Calamares::plasma_themes() );
QObject::connect<void(QComboBox::*)(const QString&)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated);
}
void
PlasmaLnfPage::activated(const QString& name)
{
cDebug() << "Changed to" << name;
QProcess lnftool;
lnftool.start( Calamares::lnftool(), {"--apply", name} );
if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
; // OK
else
cDebug() << "WARNING: could not apply look-and-feel" << name;
}

View File

@ -33,6 +33,9 @@ class PlasmaLnfPage : public QWidget
public:
explicit PlasmaLnfPage( QWidget* parent = nullptr );
public slots:
void activated(const QString& name);
private:
Ui::PlasmaLnfPage* ui;
};