mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
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.
This commit is contained in:
parent
d97782809a
commit
30371aedc8
|
@ -304,9 +304,24 @@ void ContextMenuSettingsPage::loadVersionControlSystems()
|
||||||
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
|
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
|
||||||
|
|
||||||
// Create a checkbox for each available version control plugin
|
// 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"));
|
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
|
||||||
for (const auto &plugin : pluginServices) {
|
for (const auto &plugin : pluginServices) {
|
||||||
const QString pluginName = plugin->name();
|
const QString pluginName = plugin->name();
|
||||||
|
if (loadedPlugins.contains(pluginName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
addRow(QStringLiteral("code-class"),
|
addRow(QStringLiteral("code-class"),
|
||||||
pluginName,
|
pluginName,
|
||||||
VersionControlServicePrefix + pluginName,
|
VersionControlServicePrefix + pluginName,
|
||||||
|
|
|
@ -23,14 +23,15 @@ class KFileItem;
|
||||||
* steps are required (in the example below it is assumed that a plugin for
|
* steps are required (in the example below it is assumed that a plugin for
|
||||||
* Subversion will be written):
|
* Subversion will be written):
|
||||||
*
|
*
|
||||||
* - Create a fileviewsvnplugin.desktop file with the following content:
|
* - Create a fileviewsvnplugin.json file with the following content:
|
||||||
* <code>
|
* <code>
|
||||||
* [Desktop Entry]
|
* {
|
||||||
* Type=Service
|
* "KPlugin": {
|
||||||
* Name=Subversion
|
* "Description": "The svn plugin",
|
||||||
* X-KDE-ServiceTypes=FileViewVersionControlPlugin
|
* "Name": "Svn"
|
||||||
* MimeType=text/plain;
|
* }
|
||||||
* X-KDE-Library=fileviewsvnplugin
|
* }
|
||||||
|
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and
|
* - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and
|
||||||
|
@ -45,15 +46,13 @@ class KFileItem;
|
||||||
* <code>
|
* <code>
|
||||||
* #include <KPluginFactory>
|
* #include <KPluginFactory>
|
||||||
* #include <KPluginLoader>
|
* #include <KPluginLoader>
|
||||||
* K_PLUGIN_FACTORY(FileViewSvnPluginFactory, registerPlugin<FileViewSvnPlugin>();)
|
* K_PLUGIN_CLASS_WITH_JSON(FileViewSvnPlugin, "fileviewsvnplugin.json")
|
||||||
* K_EXPORT_PLUGIN(FileViewSvnPluginFactory("fileviewsvnplugin"))
|
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* - Add the following lines to your CMakeLists.txt file:
|
* - Add the following lines to your CMakeLists.txt file:
|
||||||
* <code>
|
* <code>
|
||||||
* kde4_add_plugin(fileviewsvnplugin fileviewsvnplugin.cpp)
|
* kcoreaddons_add_plugin(fileviewsvnplugin SOURCES fileviewsvnplugin.cpp INSTALL_NAMESPACE "dolphin/vcs")
|
||||||
* target_link_libraries(fileviewsvnplugin konq)
|
* target_link_libraries(fileviewsvnplugin DolphinVcs)
|
||||||
* install(FILES fileviewsvnplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
|
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* General implementation notes:
|
* General implementation notes:
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KService>
|
#include <KService>
|
||||||
#include <KServiceTypeTrader>
|
#include <KServiceTypeTrader>
|
||||||
|
#include <KPluginLoader>
|
||||||
|
#include <KPluginMetaData>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
@ -279,24 +281,47 @@ void VersionControlObserver::initPlugins()
|
||||||
// all fileview version control plugins and remember them in 'plugins'.
|
// all fileview version control plugins and remember them in 'plugins'.
|
||||||
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
|
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"));
|
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
|
||||||
for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) {
|
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())) {
|
if (enabledPlugins.contains((*it)->name())) {
|
||||||
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
|
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
|
||||||
if (plugin) {
|
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);
|
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;
|
m_pluginsInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue