]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/versioncontrol/versioncontrolobserver.cpp
Improve cache handling in KItemListWidget
[dolphin.git] / src / views / versioncontrol / versioncontrolobserver.cpp
index b454607c19752e717dccadb51850e9f21f43ff4a..c8d9d6874fb5c3d3b1945741c2b5a91774e3df54 100644 (file)
@@ -28,7 +28,6 @@
 #include <kitemviews/kfileitemmodel.h>
 #include <kversioncontrolplugin.h>
 
-#include "pendingthreadsmaintainer.h"
 #include "updateitemstatesthread.h"
 
 #include <QMutexLocker>
@@ -58,24 +57,8 @@ VersionControlObserver::VersionControlObserver(QObject* parent) :
 
 VersionControlObserver::~VersionControlObserver()
 {
-    if (m_updateItemStatesThread) {
-        if (m_updateItemStatesThread->isFinished()) {
-            delete m_updateItemStatesThread;
-            m_updateItemStatesThread = 0;
-        } else {
-            // The version controller gets deleted, while a thread still
-            // is working to get the version information. To avoid a blocking
-            // user interface, the thread will be forwarded to the
-            // PendingThreadsMaintainer, which will delete the thread later.
-            disconnect(m_updateItemStatesThread, SIGNAL(finished()),
-                       this, SLOT(slotThreadFinished()));
-            PendingThreadsMaintainer::instance().append(m_updateItemStatesThread);
-            m_updateItemStatesThread = 0;
-        }
-    }
-
     if (m_plugin) {
-        m_plugin->disconnect();
+        m_plugin->disconnect(this);
         m_plugin = 0;
     }
 }
@@ -107,19 +90,28 @@ KFileItemModel* VersionControlObserver::model() const
 QList<QAction*> VersionControlObserver::contextMenuActions(const KFileItemList& items) const
 {
     QList<QAction*> actions;
-    if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
-        actions = m_plugin->contextMenuActions(items);
-        m_updateItemStatesThread->unlockPlugin();
+    if (isVersioned()) {
+        if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) {
+            actions = m_plugin->contextMenuActions(items);
+            m_updateItemStatesThread->unlockPlugin();
+        } else {
+            actions = m_plugin->contextMenuActions(items);
+        }
     }
+
     return actions;
 }
 
 QList<QAction*> VersionControlObserver::contextMenuActions(const QString& directory) const
 {
     QList<QAction*> actions;
-    if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
-        actions = m_plugin->contextMenuActions(directory);
-        m_updateItemStatesThread->unlockPlugin();
+    if (isVersioned()) {
+        if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) {
+            actions = m_plugin->contextMenuActions(directory);
+            m_updateItemStatesThread->unlockPlugin();
+        } else {
+            actions = m_plugin->contextMenuActions(directory);
+        }
     }
 
     return actions;
@@ -149,7 +141,7 @@ void VersionControlObserver::verifyDirectory()
     }
 
     if (m_plugin) {
-        m_plugin->disconnect();
+        m_plugin->disconnect(this);
     }
 
     m_plugin = searchPlugin(versionControlUrl);
@@ -183,17 +175,20 @@ void VersionControlObserver::verifyDirectory()
 
 void VersionControlObserver::slotThreadFinished()
 {
+    UpdateItemStatesThread* thread = m_updateItemStatesThread;
+    m_updateItemStatesThread = 0; // The thread deletes itself automatically (see updateItemStates())
+
     if (!m_plugin) {
         return;
     }
 
-    if (!m_updateItemStatesThread->retrievedItems()) {
+    if (!thread->retrievedItems()) {
         // Ignore m_silentUpdate for an error message
         emit errorMessage(i18nc("@info:status", "Update of version information failed."));
         return;
     }
 
-    const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates();
+    const QList<ItemState> itemStates = thread->itemStates();
     foreach (const ItemState& itemState, itemStates) {
         QHash<QByteArray, QVariant> values;
         values.insert("version", QVariant(itemState.version));
@@ -220,6 +215,8 @@ void VersionControlObserver::updateItemStates()
         m_updateItemStatesThread = new UpdateItemStatesThread();
         connect(m_updateItemStatesThread, SIGNAL(finished()),
                 this, SLOT(slotThreadFinished()));
+        connect(m_updateItemStatesThread, SIGNAL(finished()),
+                m_updateItemStatesThread, SLOT(deleteLater()));
     }
     if (m_updateItemStatesThread->isRunning()) {
         // An update is currently ongoing. Wait until the thread has finished
@@ -283,7 +280,6 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
 
     // Verify whether the current directory contains revision information
     // like .svn, .git, ...
-    Q_UNUSED(directory);
     foreach (KVersionControlPlugin* plugin, plugins) {
         // Use the KDirLister cache to check for .svn, .git, ... files
         const QString fileName = directory.path(KUrl::AddTrailingSlash) + plugin->fileName();
@@ -316,7 +312,7 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
 
 bool VersionControlObserver::isVersioned() const
 {
-    return false; //m_dolphinModel->hasVersionData() && m_plugin;
+    return m_versionedDirectory && m_plugin;
 }
 
 #include "versioncontrolobserver.moc"