X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2f045c60109e0a5811f68bcce617236e3478e402..d47557dcd17a028596c4e0e7b0aabc5db4847bed:/src/views/versioncontrol/versioncontrolobserver.cpp diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index 51502398c..c41803c16 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -52,8 +52,8 @@ VersionControlObserver::VersionControlObserver(QObject* parent) : m_dirVerificationTimer = new QTimer(this); m_dirVerificationTimer->setSingleShot(true); m_dirVerificationTimer->setInterval(500); - connect(m_dirVerificationTimer, SIGNAL(timeout()), - this, SLOT(verifyDirectory())); + connect(m_dirVerificationTimer, &QTimer::timeout, + this, &VersionControlObserver::verifyDirectory); } VersionControlObserver::~VersionControlObserver() @@ -67,19 +67,19 @@ VersionControlObserver::~VersionControlObserver() void VersionControlObserver::setModel(KFileItemModel* model) { if (m_model) { - disconnect(m_model, SIGNAL(itemsInserted(KItemRangeList)), - this, SLOT(delayedDirectoryVerification())); - disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet)), - this, SLOT(delayedDirectoryVerification())); + disconnect(m_model, &KFileItemModel::itemsInserted, + this, &VersionControlObserver::delayedDirectoryVerification); + disconnect(m_model, &KFileItemModel::itemsChanged, + this, &VersionControlObserver::delayedDirectoryVerification); } m_model = model; if (model) { - connect(m_model, SIGNAL(itemsInserted(KItemRangeList)), - this, SLOT(delayedDirectoryVerification())); - connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet)), - this, SLOT(delayedDirectoryVerification())); + connect(m_model, &KFileItemModel::itemsInserted, + this, &VersionControlObserver::delayedDirectoryVerification); + connect(m_model, &KFileItemModel::itemsChanged, + this, &VersionControlObserver::delayedDirectoryVerification); } } @@ -159,18 +159,18 @@ void VersionControlObserver::verifyDirectory() if (m_plugin) { KVersionControlPlugin2* pluginV2 = qobject_cast(m_plugin); if (pluginV2) { - connect(pluginV2, SIGNAL(itemVersionsChanged()), - this, SLOT(silentDirectoryVerification())); + connect(pluginV2, &KVersionControlPlugin2::itemVersionsChanged, + this, &VersionControlObserver::silentDirectoryVerification); } else { - connect(m_plugin, SIGNAL(versionStatesChanged()), - this, SLOT(silentDirectoryVerification())); + connect(m_plugin, &KVersionControlPlugin::versionStatesChanged, + this, &VersionControlObserver::silentDirectoryVerification); } - connect(m_plugin, SIGNAL(infoMessage(QString)), - this, SIGNAL(infoMessage(QString))); - connect(m_plugin, SIGNAL(errorMessage(QString)), - this, SIGNAL(errorMessage(QString))); - connect(m_plugin, SIGNAL(operationCompletedMessage(QString)), - this, SIGNAL(operationCompletedMessage(QString))); + connect(m_plugin, &KVersionControlPlugin::infoMessage, + this, &VersionControlObserver::infoMessage); + connect(m_plugin, &KVersionControlPlugin::errorMessage, + this, &VersionControlObserver::errorMessage); + connect(m_plugin, &KVersionControlPlugin::operationCompletedMessage, + this, &VersionControlObserver::operationCompletedMessage); if (!m_versionedDirectory) { m_versionedDirectory = true; @@ -242,10 +242,10 @@ void VersionControlObserver::updateItemStates() emit infoMessage(i18nc("@info:status", "Updating version information...")); } m_updateItemStatesThread = new UpdateItemStatesThread(m_plugin, itemStates); - connect(m_updateItemStatesThread, SIGNAL(finished()), - this, SLOT(slotThreadFinished())); - connect(m_updateItemStatesThread, SIGNAL(finished()), - m_updateItemStatesThread, SLOT(deleteLater())); + connect(m_updateItemStatesThread, &UpdateItemStatesThread::finished, + this, &VersionControlObserver::slotThreadFinished); + connect(m_updateItemStatesThread, &UpdateItemStatesThread::finished, + m_updateItemStatesThread, &UpdateItemStatesThread::deleteLater); m_updateItemStatesThread->start(); // slotThreadFinished() is called when finished } @@ -317,11 +317,18 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director } } + // We use the number of upUrl() calls to find the best matching plugin + // for the given directory. The smaller value, the better it is (0 is best). + KVersionControlPlugin* bestPlugin = 0; + int bestScore = INT_MAX; + // Verify whether the current directory contains revision information // like .svn, .git, ... foreach (KVersionControlPlugin* plugin, plugins) { const QString fileName = directory.path(KUrl::AddTrailingSlash) + plugin->fileName(); 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; } @@ -334,18 +341,24 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director if (m_versionedDirectory) { KUrl dirUrl(directory); KUrl upUrl = dirUrl.upUrl(); - while (upUrl != dirUrl) { + int upUrlCounter = 1; + while ((upUrlCounter < bestScore) && (upUrl != dirUrl)) { const QString fileName = dirUrl.path(KUrl::AddTrailingSlash) + plugin->fileName(); if (QFile::exists(fileName)) { - return plugin; + if (upUrlCounter < bestScore) { + bestPlugin = plugin; + bestScore = upUrlCounter; + } + break; } dirUrl = upUrl; upUrl = dirUrl.upUrl(); + ++upUrlCounter; } } } - return 0; + return bestPlugin; } bool VersionControlObserver::isVersioned() const @@ -353,4 +366,3 @@ bool VersionControlObserver::isVersioned() const return m_versionedDirectory && m_plugin; } -#include "versioncontrolobserver.moc"