#include "dolphin_versioncontrolsettings.h"
#include "dolphindebug.h"
+#include "views/dolphinview.h"
#include "kitemviews/kfileitemmodel.h"
#include "updateitemstatesthread.h"
m_pendingItemStatesUpdate(false),
m_versionedDirectory(false),
m_silentUpdate(false),
+ m_view(nullptr),
m_model(nullptr),
m_dirVerificationTimer(nullptr),
+ m_pluginsInitialized(false),
m_plugin(nullptr),
m_updateItemStatesThread(nullptr)
{
disconnect(m_model, &KFileItemModel::itemsInserted,
this, &VersionControlObserver::delayedDirectoryVerification);
disconnect(m_model, &KFileItemModel::itemsChanged,
- this, &VersionControlObserver::delayedDirectoryVerification);
+ this, &VersionControlObserver::slotItemsChanged);
}
m_model = model;
connect(m_model, &KFileItemModel::itemsInserted,
this, &VersionControlObserver::delayedDirectoryVerification);
connect(m_model, &KFileItemModel::itemsChanged,
- this, &VersionControlObserver::delayedDirectoryVerification);
+ this, &VersionControlObserver::slotItemsChanged);
}
}
return m_model;
}
+void VersionControlObserver::setView(DolphinView* view)
+{
+ if (m_view) {
+ disconnect(m_view, &DolphinView::activated,
+ this, &VersionControlObserver::delayedDirectoryVerification);
+ }
+
+ m_view = view;
+
+ if (m_view) {
+ connect(m_view, &DolphinView::activated,
+ this, &VersionControlObserver::delayedDirectoryVerification);
+ }
+}
+
+DolphinView* VersionControlObserver::view() const
+{
+ return m_view;
+}
+
QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const
{
bool hasNullItems = false;
m_dirVerificationTimer->start();
}
+void VersionControlObserver::slotItemsChanged(const KItemRangeList& itemRanges, const QSet<QByteArray>& roles)
+{
+ Q_UNUSED(itemRanges)
+
+ // Because "version" role is emitted by VCS plugin (ourselfs) we don't need to
+ // analyze it and update directory item states information. So lets check if
+ // there is only "version".
+ if ( !(roles.count() == 1 && roles.contains("version")) ) {
+ delayedDirectoryVerification();
+ }
+}
+
void VersionControlObserver::verifyDirectory()
{
if (!m_model) {
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();
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( qMakePair(plugin, plugin->fileName()) );
}
}
}
- 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
// Verify whether the current directory contains revision information
// like .svn, .git, ...
- foreach (KVersionControlPlugin* plugin, plugins) {
- const QString fileName = directory.path() + '/' + plugin->fileName();
+ for (const auto &it : qAsConst(m_plugins)) {
+ const QString fileName = directory.path() + '/' + it.second;
if (QFile::exists(fileName)) {
// The score of this plugin is 0 (best), so we can just return this plugin,
// instead of going through the plugin scoring procedure, we can't find a better one ;)
- return plugin;
+ return it.first;
}
// Version control systems like Git provide the version information
QUrl upUrl = KIO::upUrl(dirUrl);
int upUrlCounter = 1;
while ((upUrlCounter < bestScore) && (upUrl != dirUrl)) {
- const QString fileName = dirUrl.path() + '/' + plugin->fileName();
+ const QString fileName = dirUrl.path() + '/' + it.second;
if (QFile::exists(fileName)) {
if (upUrlCounter < bestScore) {
- bestPlugin = plugin;
+ bestPlugin = it.first;
bestScore = upUrlCounter;
}
break;