]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Version control: Get rid of PendingThreadsMaintainer
authorPeter Penz <peter.penz19@gmail.com>
Fri, 9 Sep 2011 10:27:11 +0000 (12:27 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 9 Sep 2011 10:28:28 +0000 (12:28 +0200)
src/CMakeLists.txt
src/views/versioncontrol/pendingthreadsmaintainer.cpp [deleted file]
src/views/versioncontrol/pendingthreadsmaintainer.h [deleted file]
src/views/versioncontrol/versioncontrolobserver.cpp

index c5913ab852a1e4c5bdd088e7fa108767e69dbd9d..9c2a867664b644625adbfb7b5efbb60a95343a32 100644 (file)
@@ -55,7 +55,6 @@ set(dolphinprivate_LIB_SRCS
     views/renamedialog.cpp
     views/tooltips/filemetadatatooltip.cpp
     views/tooltips/tooltipmanager.cpp
-    views/versioncontrol/pendingthreadsmaintainer.cpp
     views/versioncontrol/updateitemstatesthread.cpp
     views/versioncontrol/versioncontrolobserver.cpp
     views/viewmodecontroller.cpp
diff --git a/src/views/versioncontrol/pendingthreadsmaintainer.cpp b/src/views/versioncontrol/pendingthreadsmaintainer.cpp
deleted file mode 100644 (file)
index ee143a9..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
-
-#include "pendingthreadsmaintainer.h"
-
-#include <KGlobal>
-#include <QThread>
-#include <QTimer>
-
-struct PendingThreadsMaintainerSingleton
-{
-    PendingThreadsMaintainer instance;
-};
-K_GLOBAL_STATIC(PendingThreadsMaintainerSingleton, s_pendingThreadsMaintainer)
-
-
-PendingThreadsMaintainer& PendingThreadsMaintainer::instance()
-{
-    return s_pendingThreadsMaintainer->instance;
-}
-
-PendingThreadsMaintainer::~PendingThreadsMaintainer()
-{
-}
-
-void PendingThreadsMaintainer::append(QThread* thread)
-{
-    Q_ASSERT(thread);
-    m_threads.append(thread);
-    m_timer->start();
-}
-
-PendingThreadsMaintainer::PendingThreadsMaintainer() :
-    QObject(),
-    m_threads(),
-    m_timer(0)
-{
-    m_timer = new QTimer(this);
-    m_timer->setSingleShot(true);
-    m_timer->setInterval(5000); // 5 seconds
-    connect(m_timer, SIGNAL(timeout()), this, SLOT(cleanup()));
-}
-
-void PendingThreadsMaintainer::cleanup()
-{
-    QList<QThread*>::iterator it = m_threads.begin();
-    while (it != m_threads.end()) {
-        if ((*it)->isFinished()) {
-            (*it)->deleteLater();
-            it = m_threads.erase(it);
-        } else {
-            ++it;
-        }
-    }
-
-    if (!m_threads.isEmpty()) {
-        m_timer->start();
-    }
-}
-
-#include "pendingthreadsmaintainer.moc"
diff --git a/src/views/versioncontrol/pendingthreadsmaintainer.h b/src/views/versioncontrol/pendingthreadsmaintainer.h
deleted file mode 100644 (file)
index b529a56..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
-
-#ifndef PENDINGTHREADSMAINTAINER_H
-#define PENDINGTHREADSMAINTAINER_H
-
-#include <libdolphin_export.h>
-
-#include <QObject>
-
-class QTimer;
-
-/**
- * TODO: Replace the PendingThreadMaintainer by a kind of
- *       VersionControlThreadFactory that is responsible for creating
- *       and deleting the threads. This would bypass the hack to poll
- *       for pending threads.
- *
- * If the creator of a thread gets deleted, although the thread is still
- * working, usually QThread::wait() is invoked. The drawback of this
- * approach is that the user interface gets blocked for an undefined amount
- * of time. If the thread does not contain references to the creator, the
- * deleting can be forwarded to the PendingThreadsMaintainer. In the following
- * example it is assumed, that m_thread will be 0, if it has been deleted by the
- * creator after receiving the signal QThread::finished():
- *
- * \code
- * ThreadCreator::~ThreadCreator()
- * {
- *     if (m_thread) {
- *         PendingThreadsMaintainer::instance().append(m_thread);
- *         m_thread = 0;
- *     }
- * }
- * \endcode
- *
- * The thread will get automatically deleted after it (or has already) been finished.
- *
- * Implementation note: Connecting to the signal QThread::finished() is
- * not sufficient, as it is possible that the thread has already emitted
- * the signal, but the signal has not been received yet by the thread creator.
- * Because of this a polling is done each 5 seconds to check, whether the
- * thread has been finished.
- */
-class LIBDOLPHINPRIVATE_EXPORT PendingThreadsMaintainer : public QObject
-{
-    Q_OBJECT
-
-public:
-    static PendingThreadsMaintainer& instance();
-    virtual ~PendingThreadsMaintainer();
-
-    /**
-     * Appends the thread \p thread to the maintainer. The thread
-     * will be deleted by the maintainer after it has been finished.
-     */
-    void append(QThread* thread);
-
-protected:
-    PendingThreadsMaintainer();
-
-private slots:
-    void cleanup();
-
-private:
-    QList<QThread*> m_threads;
-    QTimer* m_timer;
-
-    friend class PendingThreadsMaintainerSingleton;
-};
-
-#endif
index b454607c19752e717dccadb51850e9f21f43ff4a..ba83b7515516b7d730945dfb54451ad21b551476 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;
     }
 }
@@ -149,7 +132,7 @@ void VersionControlObserver::verifyDirectory()
     }
 
     if (m_plugin) {
-        m_plugin->disconnect();
+        m_plugin->disconnect(this);
     }
 
     m_plugin = searchPlugin(versionControlUrl);
@@ -183,17 +166,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 +206,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 +271,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();