Commit d48b7334 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Load KFileItemAction plugins with json metadata

REVIEW: 128088
parent 29f12d91
......@@ -37,6 +37,7 @@
#include <KJobWidgets>
#include <KMimeTypeTrader>
#include <KNewFileMenu>
#include <KPluginMetaData>
#include <KService>
#include <KLocalizedString>
#include <KStandardAction>
......@@ -503,6 +504,7 @@ void DolphinContextMenu::addFileItemPluginActions()
const KConfig config(QStringLiteral("kservicemenurc"), KConfig::NoGlobals);
const KConfigGroup showGroup = config.group("Show");
QSet<QString> addedPlugins;
foreach (const KService::Ptr& service, pluginServices) {
if (!showGroup.readEntry(service->desktopEntryName(), true)) {
// The plugin has been disabled
......@@ -510,6 +512,30 @@ void DolphinContextMenu::addFileItemPluginActions()
}
KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance<KAbstractFileItemActionPlugin>();
if (abstractPlugin) {
abstractPlugin->setParent(this);
addActions(abstractPlugin->actions(props, m_mainWindow));
addedPlugins << service->desktopEntryName();
}
}
const auto jsonPlugins = KPluginLoader::findPlugins(QString(), [](const KPluginMetaData& metaData) {
return metaData.serviceTypes().contains(QStringLiteral("KFileItemAction/Plugin"));
});
foreach (const auto& jsonMetadata, jsonPlugins) {
// The plugin has been disabled
if (!showGroup.readEntry(jsonMetadata.pluginId(), true)) {
continue;
}
// The plugin also has a .desktop file and has already been added.
if (addedPlugins.contains(jsonMetadata.pluginId())) {
continue;
}
KPluginFactory *factory = KPluginLoader(jsonMetadata.fileName()).factory();
KAbstractFileItemActionPlugin* abstractPlugin = factory->create<KAbstractFileItemActionPlugin>();
if (abstractPlugin) {
abstractPlugin->setParent(this);
addActions(abstractPlugin->actions(props, m_mainWindow));
......
......@@ -30,6 +30,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KNS3/Button>
#include <KPluginMetaData>
#include <KService>
#include <KServiceTypeTrader>
#include <QStandardPaths>
......@@ -228,6 +229,19 @@ void ServicesSettingsPage::loadServices()
}
}
// Load JSON-based plugins that implement the KFileItemActionPlugin interface
const auto jsonPlugins = KPluginLoader::findPlugins(QString(), [](const KPluginMetaData& metaData) {
return metaData.serviceTypes().contains(QStringLiteral("KFileItemAction/Plugin"));
});
foreach (const auto& jsonMetadata, jsonPlugins) {
const QString desktopEntryName = jsonMetadata.pluginId();
if (!isInServicesList(desktopEntryName)) {
const bool checked = showGroup.readEntry(desktopEntryName, true);
addRow(jsonMetadata.iconName(), jsonMetadata.name(), desktopEntryName, checked);
}
}
m_sortModel->sort(Qt::DisplayRole);
}
......
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