Commit 8a79f38d authored by Cyril Rossi's avatar Cyril Rossi

KCM KWinScripts implement KCModuleData to highlight default at module level

Use highlight in KPluginSelector
Also remove PluginKeyword in .desktop file
parent 247d9c38
......@@ -7,6 +7,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(kcm_SRCS
main.cpp
module.cpp
kwinscriptsdata.cpp
)
ki18n_wrap_ui(kcm_SRCS module.ui)
......
......@@ -4,7 +4,6 @@ Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_kwin_scripts
X-KDE-PluginKeyword=kwin-scripts
X-KDE-ParentApp=kcontrol
X-KDE-Keywords=kwin script
......
/*
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwinscriptsdata.h"
#include <KPluginFactory>
#include <KPackage/PackageLoader>
#include <KPackage/Package>
#include <KPackage/PackageStructure>
#include "kpluginselector.h"
KWinScriptsData::KWinScriptsData(QObject *parent, const QVariantList &args)
: KCModuleData(parent, args)
, m_kwinConfig(KSharedConfig::openConfig("kwinrc"))
{
}
QList<KPluginInfo> KWinScriptsData::pluginInfoList() const
{
auto filter = [](const KPluginMetaData &md) {
return md.isValid() && !md.rawData().value("X-KWin-Exclude-Listing").toBool();
};
const QString scriptFolder = QStringLiteral("kwin/scripts/");
const auto scripts = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Script"), scriptFolder, filter);
return KPluginInfo::fromMetaData(scripts.toVector());
}
bool KWinScriptsData::isDefaults() const
{
QList<KPluginInfo> scriptinfos = pluginInfoList();
KConfigGroup cfgGroup(m_kwinConfig, "Plugins");
for (auto &script : scriptinfos) {
script.load(cfgGroup);
if (script.isPluginEnabled() != script.isPluginEnabledByDefault()) {
return false;
}
}
return true;
}
#include "kwinscriptsdata.moc"
/*
SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KWINSCRIPTSDATA_H
#define KWINSCRIPTSDATA_H
#include <QObject>
#include <QList>
#include <KCModuleData>
#include <KPluginInfo>
#include <KSharedConfig>
class KWinScriptsData : public KCModuleData
{
Q_OBJECT
public:
KWinScriptsData(QObject *parent = nullptr, const QVariantList &args = QVariantList());
bool isDefaults() const override;
QList<KPluginInfo> pluginInfoList() const;
private:
KSharedConfigPtr m_kwinConfig;
};
#endif // KWINSCRIPTSDATA_H
......@@ -7,8 +7,11 @@
#include <KPluginFactory>
#include "module.h"
#include "kwinscriptsdata.h"
K_PLUGIN_FACTORY(KcmKWinScriptsFactory,
registerPlugin<Module>("kwin-scripts");)
registerPlugin<Module>();
registerPlugin<KWinScriptsData>();
)
#include "main.moc"
......@@ -28,11 +28,13 @@
#include <KNewStuff3/KNS3/Button>
#include "version.h"
#include "kwinscriptsdata.h"
Module::Module(QWidget *parent, const QVariantList &args) :
KCModule(parent, args),
ui(new Ui::Module),
m_kwinConfig(KSharedConfig::openConfig("kwinrc"))
m_kwinConfig(KSharedConfig::openConfig("kwinrc")),
m_kwinScriptsData(new KWinScriptsData(this))
{
KAboutData *about = new KAboutData("kwin-scripts",
i18n("KWin Scripts"),
......@@ -57,6 +59,7 @@ Module::Module(QWidget *parent, const QVariantList &args) :
connect(ui->scriptSelector, &KPluginSelector::changed, this, qOverload<bool>(&KCModule::changed));
connect(ui->scriptSelector, &KPluginSelector::defaulted, this, qOverload<bool>(&KCModule::defaulted));
connect(this, &Module::defaultsIndicatorsVisibleChanged, ui->scriptSelector, &KPluginSelector::setDefaultsIndicatorsVisible);
connect(ui->importScriptButton, &QPushButton::clicked, this, &Module::importScript);
ui->scriptSelector->setAdditionalButtonHandler([this](const KPluginInfo &info) {
......@@ -142,16 +145,7 @@ void Module::importScriptInstallFinished(KJob *job)
void Module::updateListViewContents()
{
auto filter = [](const KPluginMetaData &md) {
return md.isValid() && !md.rawData().value("X-KWin-Exclude-Listing").toBool();
};
const QString scriptFolder = QStringLiteral("kwin/scripts/");
const auto scripts = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Script"), scriptFolder, filter);
QList<KPluginInfo> scriptinfos = KPluginInfo::fromMetaData(scripts.toVector());
ui->scriptSelector->addPlugins(scriptinfos, KPluginSelector::ReadConfigFile, QString(), QString(), m_kwinConfig);
ui->scriptSelector->addPlugins(m_kwinScriptsData->pluginInfoList(), KPluginSelector::ReadConfigFile, QString(), QString(), m_kwinConfig);
}
void Module::defaults()
......@@ -176,3 +170,5 @@ void Module::save()
emit changed(false);
}
#include "module.moc"
......@@ -16,6 +16,7 @@ class Module;
}
class KJob;
class KWinScriptsData;
class Module : public KCModule
{
......@@ -56,6 +57,7 @@ private:
*/
void updateListViewContents();
KSharedConfigPtr m_kwinConfig;
KWinScriptsData *m_kwinScriptsData;
};
#endif // MODULE_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment