Commit d48b7334 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Load KFileItemAction plugins with json metadata

REVIEW: 128088
parent 29f12d91
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <KJobWidgets> #include <KJobWidgets>
#include <KMimeTypeTrader> #include <KMimeTypeTrader>
#include <KNewFileMenu> #include <KNewFileMenu>
#include <KPluginMetaData>
#include <KService> #include <KService>
#include <KLocalizedString> #include <KLocalizedString>
#include <KStandardAction> #include <KStandardAction>
...@@ -503,6 +504,7 @@ void DolphinContextMenu::addFileItemPluginActions() ...@@ -503,6 +504,7 @@ void DolphinContextMenu::addFileItemPluginActions()
const KConfig config(QStringLiteral("kservicemenurc"), KConfig::NoGlobals); const KConfig config(QStringLiteral("kservicemenurc"), KConfig::NoGlobals);
const KConfigGroup showGroup = config.group("Show"); const KConfigGroup showGroup = config.group("Show");
QSet<QString> addedPlugins;
foreach (const KService::Ptr& service, pluginServices) { foreach (const KService::Ptr& service, pluginServices) {
if (!showGroup.readEntry(service->desktopEntryName(), true)) { if (!showGroup.readEntry(service->desktopEntryName(), true)) {
// The plugin has been disabled // The plugin has been disabled
...@@ -510,6 +512,30 @@ void DolphinContextMenu::addFileItemPluginActions() ...@@ -510,6 +512,30 @@ void DolphinContextMenu::addFileItemPluginActions()
} }
KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance<KAbstractFileItemActionPlugin>(); 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) { if (abstractPlugin) {
abstractPlugin->setParent(this); abstractPlugin->setParent(this);
addActions(abstractPlugin->actions(props, m_mainWindow)); addActions(abstractPlugin->actions(props, m_mainWindow));
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <KNS3/Button> #include <KNS3/Button>
#include <KPluginMetaData>
#include <KService> #include <KService>
#include <KServiceTypeTrader> #include <KServiceTypeTrader>
#include <QStandardPaths> #include <QStandardPaths>
...@@ -228,6 +229,19 @@ void ServicesSettingsPage::loadServices() ...@@ -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); 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