Verified Commit c1d32178 authored by Alexander Lohnau's avatar Alexander Lohnau
Browse files

Port away from KPuginInfo where possible

parent 070a4dab
......@@ -30,6 +30,7 @@ PluginActivity::PluginActivity(PluginManager *pman)
connect(pmw, &KPluginSelector::changed, this, &PluginActivity::changed);
connect(pmw, &KPluginSelector::configCommitted, this, &PluginActivity::changed);
layout->addWidget(pmw);
list = pman->pluginInfoList();
}
PluginActivity::~PluginActivity()
......@@ -38,13 +39,16 @@ PluginActivity::~PluginActivity()
void PluginActivity::updatePluginList()
{
pmw->addPlugins(pman->pluginInfoList(), KPluginSelector::IgnoreConfigFile, i18n("Plugins"));
pmw->addPlugins(list, KPluginSelector::IgnoreConfigFile, i18n("Plugins"));
}
void PluginActivity::update()
{
pmw->updatePluginsState();
pman->loadPlugins();
for (auto &i : list) {
i.save();
}
}
void PluginActivity::changed()
......
......@@ -6,6 +6,7 @@
#ifndef KTPLUGINACTIVITY_H
#define KTPLUGINACTIVITY_H
#include <KPluginInfo>
#include <QWidget>
#include <interfaces/activity.h>
......@@ -35,6 +36,7 @@ private Q_SLOTS:
private:
PluginManager *pman;
KPluginSelector *pmw;
KPluginInfo::List list;
};
}
......
......@@ -10,7 +10,6 @@
#include <KLocalizedString>
#include <KPluginMetaData>
#include <KSharedConfig>
#include "pluginactivity.h"
#include <interfaces/guiinterface.h>
......@@ -41,14 +40,6 @@ void PluginManager::loadPluginList()
{
pluginsMetaData = KPluginLoader::findPlugins(QStringLiteral("ktorrent"));
for (const KPluginMetaData &module : qAsConst(pluginsMetaData)) {
KPluginInfo pi(module);
pi.setConfig(KSharedConfig::openConfig()->group(pi.pluginName()));
pi.load();
plugins << pi;
}
if (!prefpage) {
prefpage = new PluginActivity(this);
gui->addActivity(prefpage);
......@@ -59,28 +50,30 @@ void PluginManager::loadPluginList()
prefpage->update();
}
inline bool isPluginEnabled(const KPluginMetaData &data)
{
return KSharedConfig::openConfig()->group(data.pluginId()).readEntry(data.pluginId() + QLatin1String("Enabled"), data.isEnabledByDefault());
}
void PluginManager::loadPlugins()
{
int idx = 0;
for (auto i = plugins.begin(); i != plugins.end(); i++) {
KPluginInfo &pi = *i;
if (loaded.contains(idx) && !pi.isPluginEnabled()) {
for (const KPluginMetaData &data : qAsConst(pluginsMetaData)) {
if (loaded.contains(idx) && !isPluginEnabled(data)) {
// unload it
unload(pi, idx);
pi.save();
} else if (!loaded.contains(idx) && pi.isPluginEnabled()) {
unload(data, idx);
} else if (!loaded.contains(idx) && isPluginEnabled(data)) {
// load it
load(pi, idx);
pi.save();
load(data, idx);
}
idx++;
}
}
void PluginManager::load(const KPluginInfo &pi, int idx)
void PluginManager::load(const KPluginMetaData &data, int idx)
{
Q_UNUSED(pi)
KPluginLoader loader(pluginsMetaData.at(idx).fileName());
Q_UNUSED(data)
KPluginLoader loader(data.fileName());
KPluginFactory *factory = loader.factory();
if (!factory)
return;
......@@ -106,9 +99,9 @@ void PluginManager::load(const KPluginInfo &pi, int idx)
}
}
void PluginManager::unload(const KPluginInfo &pi, int idx)
void PluginManager::unload(const KPluginMetaData &data, int idx)
{
Q_UNUSED(pi)
Q_UNUSED(data)
Plugin *p = loaded.find(idx);
if (!p)
......
......@@ -12,6 +12,7 @@
#include <KPluginInfo>
#include <KPluginMetaData>
#include <KSharedConfig>
#include <interfaces/plugin.h>
#include <ktcore_export.h>
......@@ -31,7 +32,6 @@ class PluginActivity;
*/
class KTCORE_EXPORT PluginManager
{
KPluginInfo::List plugins;
QVector<KPluginMetaData> pluginsMetaData;
CoreInterface *core;
GUIInterface *gui;
......@@ -45,9 +45,18 @@ public:
/**
* Get the plugin info list.
*/
const KPluginInfo::List &pluginInfoList() const
KPluginInfo::List pluginInfoList() const
{
return plugins;
// This should be removed when the KPluginSelector alternative which is based
// on KPluginMetaData is published, see https://phabricator.kde.org/T12265
KPluginInfo::List list;
for (const KPluginMetaData &data : qAsConst(pluginsMetaData)) {
KPluginInfo info = KPluginInfo::fromMetaData(data);
info.setConfig(KSharedConfig::openConfig()->group(data.pluginId()));
info.load();
list << info;
}
return list;
}
/**
......@@ -74,8 +83,8 @@ public:
void unloadAll();
private:
void load(const KPluginInfo &pi, int idx);
void unload(const KPluginInfo &pi, int idx);
void load(const KPluginMetaData &data, int idx);
void unload(const KPluginMetaData &data, int idx);
};
}
......
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