#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),
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) {
}
}
- if (items.count() > 0) {
+ if (!items.isEmpty()) {
const QUrl& url = items.first().first.url();
itemStates.insert(url.adjusted(QUrl::RemoveFilename).path(), items);
}
if (enabledPlugins.contains((*it)->name())) {
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
if (plugin) {
- m_plugins.append(plugin);
+ m_plugins.append( qMakePair(plugin, plugin->fileName()) );
}
}
}
// Verify whether the current directory contains revision information
// like .svn, .git, ...
- foreach (KVersionControlPlugin* plugin, m_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;