]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/versioncontrol/versioncontrolobserver.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[dolphin.git] / src / views / versioncontrol / versioncontrolobserver.cpp
index 888d93461134398fcf7ed58d9f9a95f7692c7016..9033e19dababb69d148b348a2cf4319b36468d17 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <KLocale>
 #include <KService>
+#include <KDebug>
 #include <KServiceTypeTrader>
 #include <kitemviews/kfileitemmodel.h>
 #include <kversioncontrolplugin2.h>
@@ -51,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()
@@ -66,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<QByteArray>)),
-                   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<QByteArray>)),
-                this, SLOT(delayedDirectoryVerification()));
+        connect(m_model, &KFileItemModel::itemsInserted,
+                this, &VersionControlObserver::delayedDirectoryVerification);
+        connect(m_model, &KFileItemModel::itemsChanged,
+                this, &VersionControlObserver::delayedDirectoryVerification);
     }
 }
 
@@ -116,7 +117,7 @@ QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) cons
         if (items.count() == 1) {
             const KFileItem rootItem = m_model->rootItem();
             if (!rootItem.isNull() && items.first().url() == rootItem.url()) {
-                directory = rootItem.url().path(KUrl::AddTrailingSlash);
+                directory = rootItem.url().path();
             }
         }
 
@@ -158,18 +159,18 @@ void VersionControlObserver::verifyDirectory()
     if (m_plugin) {
         KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(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;
@@ -206,7 +207,7 @@ void VersionControlObserver::slotThreadFinished()
         foreach (const ItemState& item, items) {
             QHash<QByteArray, QVariant> values;
             values.insert("version", QVariant(item.version));
-            m_model->setData(item.index, values);
+            m_model->setData(m_model->index(item.item), values);
         }
     }
 
@@ -241,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
     }
@@ -265,7 +266,6 @@ int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState
 
         if (expansionLevel == currentExpansionLevel) {
             ItemState itemState;
-            itemState.index = index;
             itemState.item = m_model->fileItem(index);
             itemState.version = KVersionControlPlugin2::UnversionedVersion;
 
@@ -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