]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/updateitemstatesthread.cpp
Move the KVersionControlPlugin2 interface from konqlib to Dolphin and remove the...
[dolphin.git] / src / views / versioncontrol / updateitemstatesthread.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "updateitemstatesthread.h"
21
22 #include <QVector>
23 #include <QMutexLocker>
24
25 UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin,
26 const QMap<QString, QVector<VersionControlObserver::ItemState> >& itemStates) :
27 QThread(),
28 m_globalPluginMutex(0),
29 m_plugin(plugin),
30 m_itemStates(itemStates)
31 {
32 // Several threads may share one instance of a plugin. A global
33 // mutex is required to serialize the retrieval of version control
34 // states inside run().
35 static QMutex globalMutex;
36 m_globalPluginMutex = &globalMutex;
37 }
38
39 UpdateItemStatesThread::~UpdateItemStatesThread()
40 {
41 }
42
43 void UpdateItemStatesThread::run()
44 {
45 Q_ASSERT(!m_itemStates.isEmpty());
46 Q_ASSERT(m_plugin);
47
48 QMutexLocker pluginLocker(m_globalPluginMutex);
49 QMap<QString, QVector<VersionControlObserver::ItemState> >::iterator it = m_itemStates.begin();
50 for (; it != m_itemStates.end(); ++it) {
51 if (m_plugin->beginRetrieval(it.key())) {
52 QVector<VersionControlObserver::ItemState>& items = it.value();
53 const int count = items.count();
54 for (int i = 0; i < count; ++i) {
55 const KFileItem& item = items.at(i).first;
56 const KVersionControlPlugin::ItemVersion version = m_plugin->itemVersion(item);
57 items[i].second = version;
58 }
59 }
60
61 m_plugin->endRetrieval();
62 }
63 }
64
65 QMap<QString, QVector<VersionControlObserver::ItemState> > UpdateItemStatesThread::itemStates() const
66 {
67 return m_itemStates;
68 }
69