Port scripted effect loading from KService to KPackage

Advantage: no more ksycoca cache for loading scripted effects.
master
Martin Gräßlin 9 years ago
parent a4ca6f196e
commit ca14073b54

@ -73,6 +73,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Init
Notifications
Service
Package
Plasma
WidgetsAddons
WindowSystem
@ -502,6 +503,7 @@ set(kwin_KDE_LIBS
KF5::I18n
KF5::Notifications
KF5::Service
KF5::Package
KF5::Plasma
KF5::WindowSystem
KDecoration2::KDecoration

@ -124,6 +124,7 @@ add_executable( testBuiltInEffectLoader ${testBuiltInEffectLoader_SRCS})
target_link_libraries(testBuiltInEffectLoader
Qt5::Concurrent
Qt5::Test
KF5::Package
kwineffects
kwin4_effect_builtins
)
@ -151,6 +152,7 @@ target_link_libraries(testScriptedEffectLoader
KF5::ConfigGui
KF5::GlobalAccel
KF5::I18n
KF5::Package
kwineffects
kwin4_effect_builtins
)
@ -171,6 +173,7 @@ add_executable( testPluginEffectLoader ${testPluginEffectLoader_SRCS})
target_link_libraries(testPluginEffectLoader
Qt5::Concurrent
Qt5::Test
KF5::Package
kwineffects
kwin4_effect_builtins
)

@ -38,7 +38,7 @@ Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core")
namespace KWin
{
ScriptedEffect *ScriptedEffect::create(KService::Ptr)
ScriptedEffect *ScriptedEffect::create(const KPluginMetaData&)
{
return nullptr;
}

@ -37,7 +37,7 @@ Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core")
namespace KWin
{
ScriptedEffect *ScriptedEffect::create(KService::Ptr)
ScriptedEffect *ScriptedEffect::create(const KPluginMetaData&)
{
return nullptr;
}

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KDE
#include <KConfig>
#include <KConfigGroup>
#include <KServiceTypeTrader>
#include <KPackage/PackageLoader>
// Qt
#include <QtTest/QtTest>
#include <QStringList>
@ -262,8 +262,11 @@ void TestScriptedEffectLoader::testLoadScriptedEffect()
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
loader.setConfig(config);
const auto services = KServiceTypeTrader::self()->query(QStringLiteral("KWin/Effect"),
QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name));
const auto services = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Effect"), QStringLiteral("kwin/effects"),
[name] (const KPluginMetaData &metadata) {
return metadata.pluginId().compare(name, Qt::CaseInsensitive) == 0;
}
);
QCOMPARE(services.count(), 1);
qRegisterMetaType<KWin::Effect*>();

@ -28,7 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KDE
#include <KConfigGroup>
#include <KPluginTrader>
#include <KServiceTypeTrader>
#include <KPackage/Package>
#include <KPackage/PackageLoader>
// Qt
#include <QtConcurrentRun>
#include <QDebug>
@ -183,7 +184,7 @@ static const QString s_serviceType = QStringLiteral("KWin/Effect");
ScriptedEffectLoader::ScriptedEffectLoader(QObject *parent)
: AbstractEffectLoader(parent)
, m_queue(new EffectLoadQueue<ScriptedEffectLoader, KService::Ptr>(this))
, m_queue(new EffectLoadQueue<ScriptedEffectLoader, KPluginMetaData>(this))
{
}
@ -193,7 +194,7 @@ ScriptedEffectLoader::~ScriptedEffectLoader()
bool ScriptedEffectLoader::hasEffect(const QString &name) const
{
return findEffect(name);
return findEffect(name).isValid();
}
bool ScriptedEffectLoader::isEffectSupported(const QString &name) const
@ -204,26 +205,26 @@ bool ScriptedEffectLoader::isEffectSupported(const QString &name) const
QStringList ScriptedEffectLoader::listOfKnownEffects() const
{
const KService::List effects = findAllEffects();
const auto effects = findAllEffects();
QStringList result;
for (KService::Ptr service : effects) {
result << service->property(s_nameProperty).toString();
for (const auto &service : effects) {
result << service.pluginId();
}
return result;
}
bool ScriptedEffectLoader::loadEffect(const QString &name)
{
KService::Ptr effect = findEffect(name);
if (!effect) {
auto effect = findEffect(name);
if (!effect.isValid()) {
return false;
}
return loadEffect(effect, LoadEffectFlag::Load);
}
bool ScriptedEffectLoader::loadEffect(KService::Ptr effect, LoadEffectFlags flags)
bool ScriptedEffectLoader::loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags)
{
const QString name = effect->property(s_nameProperty).toString();
const QString name = effect.pluginId();
if (!flags.testFlag(LoadEffectFlag::Load)) {
qCDebug(KWIN_CORE) << "Loading flags disable effect: " << name;
return false;
@ -253,13 +254,12 @@ bool ScriptedEffectLoader::loadEffect(KService::Ptr effect, LoadEffectFlags flag
void ScriptedEffectLoader::queryAndLoadAll()
{
// perform querying for the services in a thread
QFutureWatcher<KService::List> *watcher = new QFutureWatcher<KService::List>(this);
connect(watcher, &QFutureWatcher<KService::List>::finished, this,
QFutureWatcher<QList<KPluginMetaData>> *watcher = new QFutureWatcher<QList<KPluginMetaData>>(this);
connect(watcher, &QFutureWatcher<QList<KPluginMetaData>>::finished, this,
[this, watcher]() {
const KService::List effects = watcher->result();
for (KService::Ptr effect : effects) {
const LoadEffectFlags flags = readConfig(effect->property(s_nameProperty).toString(),
effect->property(QStringLiteral("X-KDE-PluginInfo-EnabledByDefault")).toBool());
const auto effects = watcher->result();
for (auto effect : effects) {
const LoadEffectFlags flags = readConfig(effect.pluginId(), effect.isEnabledByDefault());
if (flags.testFlag(LoadEffectFlag::Load)) {
m_queue->enqueue(qMakePair(effect, flags));
}
@ -270,20 +270,22 @@ void ScriptedEffectLoader::queryAndLoadAll()
watcher->setFuture(QtConcurrent::run(this, &ScriptedEffectLoader::findAllEffects));
}
KService::List ScriptedEffectLoader::findAllEffects() const
QList<KPluginMetaData> ScriptedEffectLoader::findAllEffects() const
{
return KServiceTypeTrader::self()->query(s_serviceType, s_jsConstraint);
return KPackage::PackageLoader::self()->listPackages(s_serviceType, QStringLiteral("kwin/effects"));
}
KService::Ptr ScriptedEffectLoader::findEffect(const QString &name) const
KPluginMetaData ScriptedEffectLoader::findEffect(const QString &name) const
{
const QString constraint = QStringLiteral("%1 and [%2] == '%3'").arg(s_jsConstraint).arg(s_nameProperty).arg(name.toLower());
const KService::List services = KServiceTypeTrader::self()->query(s_serviceType,
constraint);
if (!services.isEmpty()) {
return services.first();
const auto plugins = KPackage::PackageLoader::self()->findPackages(s_serviceType, QStringLiteral("kwin/effects"),
[name] (const KPluginMetaData &metadata) {
return metadata.pluginId().compare(name, Qt::CaseInsensitive) == 0;
}
);
if (!plugins.isEmpty()) {
return plugins.first();
}
return KService::Ptr();
return KPluginMetaData();
}

@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_EFFECT_LOADER_H
#define KWIN_EFFECT_LOADER_H
// KDE
#include <KPluginMetaData>
#include <KSharedConfig>
#include <KService>
// Qt
#include <QObject>
#include <QFlags>
@ -304,13 +304,13 @@ public:
void queryAndLoadAll() override;
bool loadEffect(const QString &name) override;
bool loadEffect(KService::Ptr effect, LoadEffectFlags flags);
bool loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags);
private:
KService::List findAllEffects() const;
KService::Ptr findEffect(const QString &name) const;
QList<KPluginMetaData> findAllEffects() const;
KPluginMetaData findEffect(const QString &name) const;
QStringList m_loadedEffects;
EffectLoadQueue< ScriptedEffectLoader, KService::Ptr > *m_queue;
EffectLoadQueue< ScriptedEffectLoader, KPluginMetaData > *m_queue;
};
class PluginEffectLoader : public AbstractEffectLoader

@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QHash>
#include <Plasma/FrameSvg>
#include <KService>
namespace Plasma {
class Theme;
@ -38,7 +37,6 @@ class Theme;
class QDBusPendingCallWatcher;
class QDBusServiceWatcher;
class KService;
class OrgFreedesktopScreenSaverInterface;

@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KDE
#include <KConfigGroup>
#include <kconfigloader.h>
#include <KPluginMetaData>
// Qt
#include <QDebug>
#include <QFile>
@ -384,10 +385,10 @@ void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2)
}
}
ScriptedEffect *ScriptedEffect::create(KService::Ptr effect)
ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect)
{
const QString name = effect->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString();
const QString scriptName = effect->property(QStringLiteral("X-Plasma-MainScript")).toString();
const QString name = effect.pluginId();
const QString scriptName = effect.value(QStringLiteral("X-Plasma-MainScript"));
if (scriptName.isEmpty()) {
qDebug() << "X-Plasma-MainScript not set";
return nullptr;
@ -398,7 +399,7 @@ ScriptedEffect *ScriptedEffect::create(KService::Ptr effect)
qDebug() << "Could not locate the effect script";
return nullptr;
}
return ScriptedEffect::create(name, scriptFile, effect->property(QStringLiteral("X-KDE-Ordering")).toInt());
return ScriptedEffect::create(name, scriptFile, effect.value(QStringLiteral("X-KDE-Ordering")).toInt());
}
ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript, int chainPosition)

@ -22,9 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KWIN_SCRIPTEDEFFECT_H
#include <kwinanimationeffect.h>
#include <KService>
class KConfigLoader;
class KPluginMetaData;
class QScriptEngine;
class QScriptValue;
@ -65,8 +65,8 @@ public:
}
QString activeConfig() const;
void setActiveConfig(const QString &name);
static ScriptedEffect *create(KService::Ptr effect);
static ScriptedEffect *create(const QString &effectName, const QString &pathToScript, int chainPosition);
static ScriptedEffect *create(const KPluginMetaData &effect);
virtual ~ScriptedEffect();
/**
* Whether another effect has grabbed the @p w with the given @p grabRole.

Loading…
Cancel
Save