mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Load KFileItemAction plugins with json metadata
REVIEW: 128088
This commit is contained in:
parent
29f12d91e5
commit
d48b733492
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue