Commit 30371aed authored by Tobias Fella's avatar Tobias Fella Committed by Elvis Angelaccio
Browse files

Port the VCS plugin system to KPluginLoader

The loader looks for the plugins in ${QT_PLUGIN_PATH}/dolphin/vcs.
The old method of loading the plugins is kept around for now, to support
external, legacy plugins.
parent d9778280
Pipeline #56537 passed with stage
in 7 minutes and 6 seconds
......@@ -304,9 +304,24 @@ void ContextMenuSettingsPage::loadVersionControlSystems()
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
// Create a checkbox for each available version control plugin
QSet<QString> loadedPlugins;
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("dolphin/vcs"));
for (const auto &plugin : plugins) {
const QString pluginName = plugin.name();
addRow(QStringLiteral("code-class"),
pluginName,
VersionControlServicePrefix + pluginName,
enabledPlugins.contains(pluginName));
loadedPlugins += pluginName;
}
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
for (const auto &plugin : pluginServices) {
const QString pluginName = plugin->name();
if (loadedPlugins.contains(pluginName)) {
continue;
}
addRow(QStringLiteral("code-class"),
pluginName,
VersionControlServicePrefix + pluginName,
......
......@@ -23,14 +23,15 @@ class KFileItem;
* steps are required (in the example below it is assumed that a plugin for
* Subversion will be written):
*
* - Create a fileviewsvnplugin.desktop file with the following content:
* - Create a fileviewsvnplugin.json file with the following content:
* <code>
* [Desktop Entry]
* Type=Service
* Name=Subversion
* X-KDE-ServiceTypes=FileViewVersionControlPlugin
* MimeType=text/plain;
* X-KDE-Library=fileviewsvnplugin
* {
* "KPlugin": {
* "Description": "The svn plugin",
* "Name": "Svn"
* }
* }
* </code>
*
* - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and
......@@ -45,15 +46,13 @@ class KFileItem;
* <code>
* #include <KPluginFactory>
* #include <KPluginLoader>
* K_PLUGIN_FACTORY(FileViewSvnPluginFactory, registerPlugin<FileViewSvnPlugin>();)
* K_EXPORT_PLUGIN(FileViewSvnPluginFactory("fileviewsvnplugin"))
* K_PLUGIN_CLASS_WITH_JSON(FileViewSvnPlugin, "fileviewsvnplugin.json")
* </code>
*
* - Add the following lines to your CMakeLists.txt file:
* <code>
* kde4_add_plugin(fileviewsvnplugin fileviewsvnplugin.cpp)
* target_link_libraries(fileviewsvnplugin konq)
* install(FILES fileviewsvnplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
* kcoreaddons_add_plugin(fileviewsvnplugin SOURCES fileviewsvnplugin.cpp INSTALL_NAMESPACE "dolphin/vcs")
* target_link_libraries(fileviewsvnplugin DolphinVcs)
* </code>
*
* General implementation notes:
......
......@@ -15,6 +15,8 @@
#include <KLocalizedString>
#include <KService>
#include <KServiceTypeTrader>
#include <KPluginLoader>
#include <KPluginMetaData>
#include <QTimer>
......@@ -279,24 +281,47 @@ void VersionControlObserver::initPlugins()
// all fileview version control plugins and remember them in 'plugins'.
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("dolphin/vcs"));
QSet<QString> loadedPlugins;
for (const auto &p : plugins) {
if (enabledPlugins.contains(p.name())) {
KPluginLoader loader(p.fileName());
KPluginFactory *factory = loader.factory();
KVersionControlPlugin *plugin = factory->create<KVersionControlPlugin>();
if (plugin) {
m_plugins.append(plugin);
loadedPlugins += p.name();
}
}
}
// Deprecated: load plugins using KService. This mechanism will be removed with KF6
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) {
if (loadedPlugins.contains((*it)->property("Name", QVariant::String).toString())) {
continue;
}
if (enabledPlugins.contains((*it)->name())) {
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
if (plugin) {
connect(plugin, &KVersionControlPlugin::itemVersionsChanged,
this, &VersionControlObserver::silentDirectoryVerification);
connect(plugin, &KVersionControlPlugin::infoMessage,
this, &VersionControlObserver::infoMessage);
connect(plugin, &KVersionControlPlugin::errorMessage,
this, &VersionControlObserver::errorMessage);
connect(plugin, &KVersionControlPlugin::operationCompletedMessage,
this, &VersionControlObserver::operationCompletedMessage);
m_plugins.append(plugin);
}
}
}
for (auto &plugin : qAsConst(m_plugins)) {
connect(plugin, &KVersionControlPlugin::itemVersionsChanged,
this, &VersionControlObserver::silentDirectoryVerification);
connect(plugin, &KVersionControlPlugin::infoMessage,
this, &VersionControlObserver::infoMessage);
connect(plugin, &KVersionControlPlugin::errorMessage,
this, &VersionControlObserver::errorMessage);
connect(plugin, &KVersionControlPlugin::operationCompletedMessage,
this, &VersionControlObserver::operationCompletedMessage);
}
m_pluginsInitialized = true;
}
}
......
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