#include <kservicetypetrader.h>
#include <kversioncontrolplugin.h>
+#include "pendingthreadsmaintainer.h"
#include "updateitemstatesthread.h"
#include <QAbstractProxyModel>
VersionControlObserver::~VersionControlObserver()
{
if (m_updateItemStatesThread != 0) {
- disconnect(m_updateItemStatesThread, SIGNAL(finished()),
- this, SLOT(applyUpdatedItemStates()));
if (m_updateItemStatesThread->isFinished()) {
delete m_updateItemStatesThread;
+ m_updateItemStatesThread = 0;
} else {
- m_updateItemStatesThread->deleteWhenFinished();
+ // 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;
}
- m_updateItemStatesThread = 0;
}
- m_plugin->disconnect();
- m_plugin = 0;
+ if (m_plugin != 0) {
+ m_plugin->disconnect();
+ m_plugin = 0;
+ }
}
QList<QAction*> VersionControlObserver::contextMenuActions(const KFileItemList& items) const
{
QList<QAction*> actions;
- if (isVersioned() && m_updateItemStatesThread->beginReadItemStates()) {
+ if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
actions = m_plugin->contextMenuActions(items);
- m_updateItemStatesThread->endReadItemStates();
+ m_updateItemStatesThread->unlockPlugin();
}
return actions;
}
QList<QAction*> VersionControlObserver::contextMenuActions(const QString& directory) const
{
QList<QAction*> actions;
- if (isVersioned() && m_updateItemStatesThread->beginReadItemStates()) {
+ if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
actions = m_plugin->contextMenuActions(directory);
- m_updateItemStatesThread->endReadItemStates();
+ m_updateItemStatesThread->unlockPlugin();
}
return actions;
}
}
-void VersionControlObserver::applyUpdatedItemStates()
+void VersionControlObserver::slotThreadFinished()
{
if (m_plugin == 0) {
- // The signal finished() has been emitted, but the thread has been marked
- // as invalid in the meantime. Just ignore the signal in this case.
return;
}
// operation has been completed because of the icon emblems.
emit operationCompletedMessage(QString());
}
-
+
if (m_pendingItemStatesUpdate) {
m_pendingItemStatesUpdate = false;
updateItemStates();
if (m_updateItemStatesThread == 0) {
m_updateItemStatesThread = new UpdateItemStatesThread();
connect(m_updateItemStatesThread, SIGNAL(finished()),
- this, SLOT(applyUpdatedItemStates()));
+ this, SLOT(slotThreadFinished()));
}
if (m_updateItemStatesThread->isRunning()) {
// An update is currently ongoing. Wait until the thread has finished
- // the update (see applyUpdatedItemStates()).
+ // the update (see slotThreadFinished()).
m_pendingItemStatesUpdate = true;
return;
}
emit infoMessage(i18nc("@info:status", "Updating version information..."));
}
m_updateItemStatesThread->setData(m_plugin, itemStates);
- m_updateItemStatesThread->start(); // applyUpdatedItemStates() is called when finished
+ m_updateItemStatesThread->start(); // slotThreadFinished() is called when finished
}
}