]>
cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/updateitemstatesthread.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "updateitemstatesthread.h"
22 #include <kversioncontrolplugin2.h>
24 #include <QMutexLocker>
26 UpdateItemStatesThread::UpdateItemStatesThread() :
28 m_globalPluginMutex(0),
31 m_retrievedItems(false),
34 // Several threads may share one instance of a plugin. A global
35 // mutex is required to serialize the retrieval of version control
36 // states inside run().
37 static QMutex globalMutex
;
38 m_globalPluginMutex
= &globalMutex
;
41 UpdateItemStatesThread::~UpdateItemStatesThread()
45 void UpdateItemStatesThread::setData(KVersionControlPlugin
* plugin
,
46 const QList
<VersionControlObserver::ItemState
>& itemStates
)
48 QMutexLocker
itemLocker(&m_itemMutex
);
49 m_itemStates
= itemStates
;
51 QMutexLocker
pluginLocker(m_globalPluginMutex
);
55 void UpdateItemStatesThread::run()
57 Q_ASSERT(!m_itemStates
.isEmpty());
60 QMutexLocker
itemLocker(&m_itemMutex
);
61 const QString directory
= m_itemStates
.first().item
.url().directory(KUrl::AppendTrailingSlash
);
64 QMutexLocker
pluginLocker(m_globalPluginMutex
);
65 m_retrievedItems
= false;
66 if (m_plugin
->beginRetrieval(directory
)) {
68 const int count
= m_itemStates
.count();
70 KVersionControlPlugin2
* pluginV2
= qobject_cast
<KVersionControlPlugin2
*>(m_plugin
);
72 for (int i
= 0; i
< count
; ++i
) {
73 m_itemStates
[i
].version
= pluginV2
->itemVersion(m_itemStates
[i
].item
);
76 for (int i
= 0; i
< count
; ++i
) {
77 const KVersionControlPlugin::VersionState state
= m_plugin
->versionState(m_itemStates
[i
].item
);
78 m_itemStates
[i
].version
= static_cast<KVersionControlPlugin2::ItemVersion
>(state
);
82 m_plugin
->endRetrieval();
83 m_retrievedItems
= true;
87 bool UpdateItemStatesThread::lockPlugin()
89 return m_globalPluginMutex
->tryLock(300);
92 void UpdateItemStatesThread::unlockPlugin()
94 m_globalPluginMutex
->unlock();
97 QList
<VersionControlObserver::ItemState
> UpdateItemStatesThread::itemStates() const
99 QMutexLocker
locker(&m_itemMutex
);
103 bool UpdateItemStatesThread::retrievedItems() const
105 QMutexLocker
locker(&m_itemMutex
);
106 return m_retrievedItems
;
109 #include "updateitemstatesthread.moc"