From 9dbd073951f999d6b6fad46864622baf0a25ef35 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 9 Sep 2011 12:27:11 +0200 Subject: [PATCH] Version control: Get rid of PendingThreadsMaintainer --- src/CMakeLists.txt | 1 - .../pendingthreadsmaintainer.cpp | 77 ---------------- .../versioncontrol/pendingthreadsmaintainer.h | 88 ------------------- .../versioncontrol/versioncontrolobserver.cpp | 31 ++----- 4 files changed, 9 insertions(+), 188 deletions(-) delete mode 100644 src/views/versioncontrol/pendingthreadsmaintainer.cpp delete mode 100644 src/views/versioncontrol/pendingthreadsmaintainer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5913ab85..9c2a86766 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index ee143a94a..000000000 --- a/src/views/versioncontrol/pendingthreadsmaintainer.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz * - * * - * 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 -#include -#include - -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::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 index b529a5667..000000000 --- a/src/views/versioncontrol/pendingthreadsmaintainer.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz * - * * - * 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 - -#include - -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 m_threads; - QTimer* m_timer; - - friend class PendingThreadsMaintainerSingleton; -}; - -#endif diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index b454607c1..ba83b7515 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -28,7 +28,6 @@ #include #include -#include "pendingthreadsmaintainer.h" #include "updateitemstatesthread.h" #include @@ -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 itemStates = m_updateItemStatesThread->itemStates(); + const QList itemStates = thread->itemStates(); foreach (const ItemState& itemState, itemStates) { QHash 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(); -- 2.47.3