Commit e7a6affd authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Andrius Štikonas
Browse files

Port from KPluginSelector to KPluginWidget class

Task: https://phabricator.kde.org/T12265
parent 85f73ce6
Pipeline #108420 passed with stage
in 1 minute and 40 seconds
......@@ -13,7 +13,7 @@ add_definitions(-D'VERSION="${RELEASE_SERVICE_VERSION}"'
-D'VERSION_MICRO=${RELEASE_SERVICE_VERSION_MICRO}')
set (QT_MIN_VERSION "5.15.0")
set (KF5_MIN_VERSION "5.88")
set (KF5_MIN_VERSION "5.89")
set (LIBKTORRENT_MIN_VERSION "20.11.70")
set (Boost_MIN_VERSION "1.71.0")
......
......@@ -22,9 +22,11 @@
#include <QFile>
#include <KAboutData>
#include <KConfigGroup>
#include <KCrash>
#include <KDBusService>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KStartupInfo>
#include <KWindowSystem>
#include <kwindowsystem_version.h>
......@@ -177,6 +179,22 @@ int main(int argc, char **argv)
parser.process(app);
about.processCommandLine(&parser);
// config migration code
auto config = KSharedConfig::openConfig();
if (!config->hasGroup("Plugins")) {
KConfigGroup pluginsGroup = config->group("Plugins");
const QStringList groups = config->groupList();
for (const QString &grpName : groups) {
const QString entryName = grpName + QLatin1String("Enabled");
KConfigGroup grp = config->group(grpName);
if (grp.hasKey(entryName)) {
// bool is just for typing reasons - we know that there is a value
pluginsGroup.writeEntry(entryName, grp.readEntry(entryName, true));
grp.deleteEntry(entryName);
}
}
}
const KDBusService dbusService(KDBusService::Unique);
#if 0 // ndef Q_WS_WIN
......
......@@ -8,7 +8,7 @@
#include <QVBoxLayout>
#include <KLocalizedString>
#include <KPluginSelector>
#include <KPluginWidget>
#include "pluginactivity.h"
#include "pluginmanager.h"
......@@ -26,11 +26,11 @@ PluginActivity::PluginActivity(PluginManager *pman)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
pmw = new KPluginSelector(this);
connect(pmw, &KPluginSelector::changed, this, &PluginActivity::changed);
connect(pmw, &KPluginSelector::configCommitted, this, &PluginActivity::changed);
pmw = new KPluginWidget(this);
connect(pmw, &KPluginWidget::changed, this, &PluginActivity::update);
connect(pmw, &KPluginWidget::pluginConfigSaved, this, &PluginActivity::update);
layout->addWidget(pmw);
list = pman->pluginInfoList();
list = pman->pluginsMetaDataList();
}
PluginActivity::~PluginActivity()
......@@ -39,20 +39,14 @@ PluginActivity::~PluginActivity()
void PluginActivity::updatePluginList()
{
pmw->addPlugins(list, KPluginSelector::IgnoreConfigFile, i18n("Plugins"));
pmw->clear();
pmw->setConfig(KSharedConfig::openConfig()->group("Plugins"));
pmw->addPlugins(list, i18n("Plugins"));
}
void PluginActivity::update()
{
pmw->updatePluginsState();
pmw->save();
pman->loadPlugins();
for (auto &i : list) {
i.save();
}
}
void PluginActivity::changed()
{
update();
}
}
......@@ -10,7 +10,7 @@
#include <QWidget>
#include <interfaces/activity.h>
class KPluginSelector;
class KPluginWidget;
namespace kt
{
......@@ -30,13 +30,11 @@ public:
void updatePluginList();
void update();
private Q_SLOTS:
void changed();
private:
PluginManager *pman;
KPluginSelector *pmw;
KPluginInfo::List list;
KPluginWidget *pmw;
QVector<KPluginMetaData> list;
};
}
......
......@@ -12,6 +12,7 @@
#include <KPluginMetaData>
#include "pluginactivity.h"
#include <KSharedConfig>
#include <interfaces/guiinterface.h>
#include <torrent/globals.h>
#include <util/error.h>
......@@ -50,19 +51,16 @@ 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()
{
const KConfigGroup cfg = KSharedConfig::openConfig()->group("Plugins");
int idx = 0;
for (const KPluginMetaData &data : qAsConst(pluginsMetaData)) {
if (loaded.contains(idx) && !isPluginEnabled(data)) {
if (loaded.contains(idx) && !data.isEnabled(cfg)) {
// unload it
unload(data, idx);
} else if (!loaded.contains(idx) && isPluginEnabled(data)) {
} else if (!loaded.contains(idx) && data.isEnabled(cfg)) {
// load it
load(data, idx);
}
......
......@@ -42,21 +42,9 @@ public:
PluginManager(CoreInterface *core, GUIInterface *gui);
~PluginManager();
/**
* Get the plugin info list.
*/
KPluginInfo::List pluginInfoList() const
QVector<KPluginMetaData> pluginsMetaDataList() const
{
// 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;
return pluginsMetaData;
}
/**
......
Supports Markdown
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