PluginEffectLoader doesn't use KPluginTrader any more
Requires that plugins change to new KPlugin json metadata.
This commit is contained in:
parent
b01b03aa84
commit
93ef184356
5 changed files with 47 additions and 35 deletions
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"KPlugin": {
|
||||
"Id": "fakeeffectplugin",
|
||||
"ServiceTypes": ["KWin/Effect"]
|
||||
},
|
||||
"Type": "Service",
|
||||
"X-KDE-Library": "fakeeffectplugin",
|
||||
"X-KDE-PluginInfo-EnabledByDefault": true,
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"KPlugin": {
|
||||
"Id": "effectversion",
|
||||
"ServiceTypes": ["KWin/Effect"]
|
||||
},
|
||||
"Type": "Service",
|
||||
"X-KDE-Library": "effectversionplugin",
|
||||
"X-KDE-PluginInfo-EnabledByDefault": true,
|
||||
|
|
|
@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// KDE
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <KPluginTrader>
|
||||
#include <KPluginLoader>
|
||||
// Qt
|
||||
#include <QtTest/QtTest>
|
||||
#include <QStringList>
|
||||
|
@ -286,9 +286,11 @@ void TestPluginEffectLoader::testLoadPluginEffect()
|
|||
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
||||
loader.setConfig(config);
|
||||
|
||||
const auto plugins = KPluginTrader::self()->query(QString(),
|
||||
QStringLiteral("KWin/Effect"),
|
||||
QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name));
|
||||
const auto plugins = KPluginLoader::findPlugins(QString(),
|
||||
[name] (const KPluginMetaData &data) {
|
||||
return data.pluginId().compare(name, Qt::CaseInsensitive) == 0 && data.serviceTypes().contains(QStringLiteral("KWin/Effect"));
|
||||
}
|
||||
);
|
||||
QCOMPARE(plugins.size(), 1);
|
||||
|
||||
qRegisterMetaType<KWin::Effect*>();
|
||||
|
|
|
@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "utils.h"
|
||||
// KDE
|
||||
#include <KConfigGroup>
|
||||
#include <KPluginTrader>
|
||||
#include <KPluginLoader>
|
||||
#include <KPackage/Package>
|
||||
#include <KPackage/PackageLoader>
|
||||
// Qt
|
||||
|
@ -291,7 +291,7 @@ KPluginMetaData ScriptedEffectLoader::findEffect(const QString &name) const
|
|||
|
||||
PluginEffectLoader::PluginEffectLoader(QObject *parent)
|
||||
: AbstractEffectLoader(parent)
|
||||
, m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginInfo>(this))
|
||||
, m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginMetaData>(this))
|
||||
, m_pluginSubDirectory(QStringLiteral("kwin/effects/plugins/"))
|
||||
{
|
||||
}
|
||||
|
@ -302,16 +302,19 @@ PluginEffectLoader::~PluginEffectLoader()
|
|||
|
||||
bool PluginEffectLoader::hasEffect(const QString &name) const
|
||||
{
|
||||
KPluginInfo info = findEffect(name);
|
||||
const auto info = findEffect(name);
|
||||
return info.isValid();
|
||||
}
|
||||
|
||||
KPluginInfo PluginEffectLoader::findEffect(const QString &name) const
|
||||
KPluginMetaData PluginEffectLoader::findEffect(const QString &name) const
|
||||
{
|
||||
const QString constraint = QStringLiteral("[%1] == '%2'").arg(s_nameProperty).arg(name.toLower());
|
||||
KPluginInfo::List plugins = KPluginTrader::self()->query(m_pluginSubDirectory, s_serviceType, constraint);
|
||||
const auto plugins = KPluginLoader::findPlugins(m_pluginSubDirectory,
|
||||
[name] (const KPluginMetaData &data) {
|
||||
return data.pluginId().compare(name, Qt::CaseInsensitive) == 0 && data.serviceTypes().contains(s_serviceType);
|
||||
}
|
||||
);
|
||||
if (plugins.isEmpty()) {
|
||||
return KPluginInfo();
|
||||
return KPluginMetaData();
|
||||
}
|
||||
return plugins.first();
|
||||
}
|
||||
|
@ -324,19 +327,19 @@ bool PluginEffectLoader::isEffectSupported(const QString &name) const
|
|||
return false;
|
||||
}
|
||||
|
||||
EffectPluginFactory *PluginEffectLoader::factory(const KPluginInfo &info) const
|
||||
EffectPluginFactory *PluginEffectLoader::factory(const KPluginMetaData &info) const
|
||||
{
|
||||
if (!info.isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
KPluginLoader loader(info.libraryPath());
|
||||
KPluginLoader loader(info.fileName());
|
||||
if (loader.pluginVersion() != KWIN_EFFECT_API_VERSION) {
|
||||
qCDebug(KWIN_CORE) << info.pluginName() << " has not matching plugin version, expected " << KWIN_EFFECT_API_VERSION << "got " << loader.pluginVersion();
|
||||
qCDebug(KWIN_CORE) << info.pluginId() << " has not matching plugin version, expected " << KWIN_EFFECT_API_VERSION << "got " << loader.pluginVersion();
|
||||
return nullptr;
|
||||
}
|
||||
KPluginFactory *factory = loader.factory();
|
||||
if (!factory) {
|
||||
qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginName();
|
||||
qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginId();
|
||||
return nullptr;
|
||||
}
|
||||
return dynamic_cast< EffectPluginFactory* >(factory);
|
||||
|
@ -344,30 +347,31 @@ EffectPluginFactory *PluginEffectLoader::factory(const KPluginInfo &info) const
|
|||
|
||||
QStringList PluginEffectLoader::listOfKnownEffects() const
|
||||
{
|
||||
const KPluginInfo::List plugins = findAllEffects();
|
||||
const auto plugins = findAllEffects();
|
||||
QStringList result;
|
||||
for (const KPluginInfo &plugin : plugins) {
|
||||
result << plugin.pluginName();
|
||||
for (const auto &plugin : plugins) {
|
||||
result << plugin.pluginId();
|
||||
}
|
||||
qDebug() << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool PluginEffectLoader::loadEffect(const QString &name)
|
||||
{
|
||||
KPluginInfo info = findEffect(name);
|
||||
const auto info = findEffect(name);
|
||||
if (!info.isValid()) {
|
||||
return false;
|
||||
}
|
||||
return loadEffect(info, LoadEffectFlag::Load);
|
||||
}
|
||||
|
||||
bool PluginEffectLoader::loadEffect(const KPluginInfo &info, LoadEffectFlags flags)
|
||||
bool PluginEffectLoader::loadEffect(const KPluginMetaData &info, LoadEffectFlags flags)
|
||||
{
|
||||
if (!info.isValid()) {
|
||||
qCDebug(KWIN_CORE) << "Plugin info is not valid";
|
||||
return false;
|
||||
}
|
||||
const QString name = info.pluginName();
|
||||
const QString name = info.pluginId();
|
||||
if (!flags.testFlag(LoadEffectFlag::Load)) {
|
||||
qCDebug(KWIN_CORE) << "Loading flags disable effect: " << name;
|
||||
return false;
|
||||
|
@ -418,12 +422,12 @@ bool PluginEffectLoader::loadEffect(const KPluginInfo &info, LoadEffectFlags fla
|
|||
void PluginEffectLoader::queryAndLoadAll()
|
||||
{
|
||||
// perform querying for the services in a thread
|
||||
QFutureWatcher<KPluginInfo::List> *watcher = new QFutureWatcher<KPluginInfo::List>(this);
|
||||
connect(watcher, &QFutureWatcher<KPluginInfo::List>::finished, this,
|
||||
QFutureWatcher<QVector<KPluginMetaData>> *watcher = new QFutureWatcher<QVector<KPluginMetaData>>(this);
|
||||
connect(watcher, &QFutureWatcher<QVector<KPluginMetaData>>::finished, this,
|
||||
[this, watcher]() {
|
||||
const KPluginInfo::List effects = watcher->result();
|
||||
for (const KPluginInfo &effect : effects) {
|
||||
const LoadEffectFlags flags = readConfig(effect.pluginName(), effect.isPluginEnabledByDefault());
|
||||
const auto effects = watcher->result();
|
||||
for (const auto &effect : effects) {
|
||||
const LoadEffectFlags flags = readConfig(effect.pluginId(), effect.isEnabledByDefault());
|
||||
if (flags.testFlag(LoadEffectFlag::Load)) {
|
||||
m_queue->enqueue(qMakePair(effect, flags));
|
||||
}
|
||||
|
@ -434,9 +438,9 @@ void PluginEffectLoader::queryAndLoadAll()
|
|||
watcher->setFuture(QtConcurrent::run(this, &PluginEffectLoader::findAllEffects));
|
||||
}
|
||||
|
||||
KPluginInfo::List PluginEffectLoader::findAllEffects() const
|
||||
QVector<KPluginMetaData> PluginEffectLoader::findAllEffects() const
|
||||
{
|
||||
return KPluginTrader::self()->query(m_pluginSubDirectory, s_serviceType);
|
||||
return KPluginLoader::findPlugins(m_pluginSubDirectory, [] (const KPluginMetaData &data) { return data.serviceTypes().contains(s_serviceType); });
|
||||
}
|
||||
|
||||
void PluginEffectLoader::setPluginSubDirectory(const QString &directory)
|
||||
|
|
|
@ -29,8 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QPair>
|
||||
#include <QQueue>
|
||||
|
||||
class KPluginInfo;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
class Effect;
|
||||
|
@ -326,16 +324,16 @@ public:
|
|||
|
||||
void queryAndLoadAll() override;
|
||||
bool loadEffect(const QString &name) override;
|
||||
bool loadEffect(const KPluginInfo &info, LoadEffectFlags flags);
|
||||
bool loadEffect(const KPluginMetaData &info, LoadEffectFlags flags);
|
||||
|
||||
void setPluginSubDirectory(const QString &directory);
|
||||
|
||||
private:
|
||||
QList<KPluginInfo> findAllEffects() const;
|
||||
KPluginInfo findEffect(const QString &name) const;
|
||||
EffectPluginFactory *factory(const KPluginInfo &info) const;
|
||||
QVector<KPluginMetaData> findAllEffects() const;
|
||||
KPluginMetaData findEffect(const QString &name) const;
|
||||
EffectPluginFactory *factory(const KPluginMetaData &info) const;
|
||||
QStringList m_loadedEffects;
|
||||
EffectLoadQueue< PluginEffectLoader, KPluginInfo> *m_queue;
|
||||
EffectLoadQueue< PluginEffectLoader, KPluginMetaData> *m_queue;
|
||||
QString m_pluginSubDirectory;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue