Commit 9a9fbae9 authored by Anthony Fieroni's avatar Anthony Fieroni
Browse files

[versioncontrolobserver] Do not use static plugin objects

Differential Revision: https://phabricator.kde.org/D17640

Signed-off-by: Anthony Fieroni's avatarAnthony Fieroni <bvbfan@abv.bg>
parent df3c2c13
......@@ -37,6 +37,7 @@ VersionControlObserver::VersionControlObserver(QObject* parent) :
m_silentUpdate(false),
m_model(nullptr),
m_dirVerificationTimer(nullptr),
m_pluginsInitialized(false),
m_plugin(nullptr),
m_updateItemStatesThread(nullptr)
{
......@@ -256,18 +257,9 @@ int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState
return index - firstIndex; // number of processed items
}
KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& directory) const
KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& directory)
{
static bool pluginsAvailable = true;
static QList<KVersionControlPlugin*> plugins;
if (!pluginsAvailable) {
// A searching for plugins has already been done, but no
// plugins are installed
return nullptr;
}
if (plugins.isEmpty()) {
if (!m_pluginsInitialized) {
// No searching for plugins has been done yet. Query the KServiceTypeTrader for
// all fileview version control plugins and remember them in 'plugins'.
const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
......@@ -275,16 +267,19 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& director
const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) {
if (enabledPlugins.contains((*it)->name())) {
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>();
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
if (plugin) {
plugins.append(plugin);
m_plugins.append(plugin);
}
}
}
if (plugins.isEmpty()) {
pluginsAvailable = false;
return nullptr;
}
m_pluginsInitialized = true;
}
if (m_plugins.empty()) {
// A searching for plugins has already been done, but no
// plugins are installed
return nullptr;
}
// We use the number of upUrl() calls to find the best matching plugin
......@@ -294,7 +289,7 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& director
// Verify whether the current directory contains revision information
// like .svn, .git, ...
foreach (KVersionControlPlugin* plugin, plugins) {
foreach (KVersionControlPlugin* plugin, m_plugins) {
const QString fileName = directory.path() + '/' + plugin->fileName();
if (QFile::exists(fileName)) {
// The score of this plugin is 0 (best), so we can just return this plugin,
......
......@@ -126,7 +126,7 @@ private:
* Returns a matching plugin for the given directory.
* 0 is returned, if no matching plugin has been found.
*/
KVersionControlPlugin* searchPlugin(const QUrl& directory) const;
KVersionControlPlugin* searchPlugin(const QUrl& directory);
/**
* Returns true, if the directory contains a version control information.
......@@ -143,7 +143,9 @@ private:
QTimer* m_dirVerificationTimer;
bool m_pluginsInitialized;
KVersionControlPlugin* m_plugin;
QList<KVersionControlPlugin*> m_plugins;
UpdateItemStatesThread* m_updateItemStatesThread;
friend class UpdateItemStatesThread;
......
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