]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/versioncontrol/updateitemstatesthread.cpp
Merge branch 'master' into frameworks
[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 <kversioncontrolplugin2.h>
23 #include <QVector>
24
25 #include <QMutexLocker>
26
27 UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin,
28 const QMap<QString, QVector<VersionControlObserver::ItemState> >& itemStates) :
29 QThread(),
30 m_globalPluginMutex(0),
31 m_plugin(plugin),
32 m_itemStates(itemStates)
33 {
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;
39 }
40
41 UpdateItemStatesThread::~UpdateItemStatesThread()
42 {
43 }
44
45 void UpdateItemStatesThread::run()
46 {
47 Q_ASSERT(!m_itemStates.isEmpty());
48 Q_ASSERT(m_plugin);
49
50 QMutexLocker pluginLocker(m_globalPluginMutex);
51 QMap<QString, QVector<VersionControlObserver::ItemState> >::iterator it = m_itemStates.begin();
52 for (; it != m_itemStates.end(); ++it) {
53 if (m_plugin->beginRetrieval(it.key())) {
54 QVector<VersionControlObserver::ItemState>& items = it.value();
55 const int count = items.count();
56
57 KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
58 if (pluginV2) {
59 for (int i = 0; i < count; ++i) {
60 items[i].version = pluginV2->itemVersion(items[i].item);
61 }
62 } else {
63 for (int i = 0; i < count; ++i) {
64 const KVersionControlPlugin::VersionState state = m_plugin->versionState(items[i].item);
65 items[i].version = static_cast<KVersionControlPlugin2::ItemVersion>(state);
66 }
67 }
68 }
69
70 m_plugin->endRetrieval();
71 }
72 }
73
74 QMap<QString, QVector<VersionControlObserver::ItemState> > UpdateItemStatesThread::itemStates() const
75 {
76 return m_itemStates;
77 }
78
79 #include "updateitemstatesthread.moc"