[plasmalnf] Simplify code, remove redundant implementations

This commit is contained in:
Adriaan de Groot 2017-12-03 15:34:06 -05:00
parent 4e2e55a935
commit fe8ff3ab05
4 changed files with 19 additions and 94 deletions

View File

@ -1,6 +1,6 @@
find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service Package ) find_package( KF5 5.29 REQUIRED CoreAddons Plasma Package )
calamares_add_plugin( plasmalnf calamares_add_plugin( plasmalnf
TYPE viewmodule TYPE viewmodule
@ -16,6 +16,5 @@ calamares_add_plugin( plasmalnf
calamaresui calamaresui
KF5::Package KF5::Package
KF5::Plasma KF5::Plasma
KF5::Service
SHARED_LIB SHARED_LIB
) )

View File

@ -38,88 +38,6 @@
namespace Calamares 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;
KServiceTypeTrader* trader = KServiceTypeTrader::self();
cDebug() << "Plasma themes by service:";
QStringList packages;
services = trader->query("Plasma/Theme");
int c = 0;
for ( const auto s : services )
{
cDebug() << " .. Plasma theme" << s->name();
packages << s->name();
c++;
}
return packages;
}
QStringList themes_by_kcm()
{
QString component;
QList<Plasma::Package> packages;
QStringList paths;
QStringList packageNames;
const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
for (const QString &path : dataPaths) {
QDir dir(path + "/plasma/look-and-feel");
paths << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
}
cDebug() << "Plasma themes by kcm:";
for (const QString &path : paths) {
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
pkg.setPath(path);
pkg.setFallbackPackage(Plasma::Package());
if (component.isEmpty() || !pkg.filePath(component.toUtf8()).isEmpty()) {
packages << pkg;
packageNames << pkg.metadata().pluginName();
cDebug() << " .. Plasma theme" << pkg.metadata().pluginName();
}
}
return packageNames;
}
QStringList themes_by_lnftool()
{
QStringList packages;
QProcess lnftool;
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');
}
return packages;
}
QStringList plasma_themes()
{
QStringList l( themes_by_package() );
if (l.isEmpty())
return themes_by_lnftool();
return l;
}
static QString *p_lnfPath = nullptr; static QString *p_lnfPath = nullptr;
QString lnftool() QString lnftool()

View File

@ -26,14 +26,6 @@ namespace Calamares
{ {
QString lnftool(); QString lnftool();
void set_lnftool( const QString& ); void set_lnftool( const QString& );
/* Internal */
QStringList themes_by_package();
QStringList themes_by_service();
QStringList themes_by_kcm();
QStringList themes_by_lnftool();
QStringList plasma_themes();
} }
#endif // PLASMALNFINFO_H #endif // PLASMALNFINFO_H

View File

@ -29,11 +29,28 @@
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "ViewManager.h" #include "ViewManager.h"
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include <QButtonGroup> #include <QButtonGroup>
#include <QDesktopServices> #include <QDesktopServices>
#include <QLabel> #include <QLabel>
#include <QProcess> #include <QProcess>
static QStringList plasma_themes()
{
QStringList packages;
QList<KPluginMetaData> pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel");
for (const KPluginMetaData &data : pkgs) {
packages << data.pluginId();
}
return packages;
}
PlasmaLnfPage::PlasmaLnfPage(QWidget *parent) PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::PlasmaLnfPage ) , ui( new Ui::PlasmaLnfPage )
@ -46,8 +63,7 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) ); ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) );
) )
Calamares::themes_by_package(); ui->lnfCombo->addItems( plasma_themes() );
ui->lnfCombo->addItems( Calamares::plasma_themes() );
QObject::connect<void(QComboBox::*)(const QString&)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated); QObject::connect<void(QComboBox::*)(const QString&)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated);
} }