]>
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"
23 UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin
* plugin
,
24 const QMap
<QString
, QVector
<VersionControlObserver::ItemState
> >& itemStates
) :
26 m_globalPluginMutex(nullptr),
28 m_itemStates(itemStates
)
30 // Several threads may share one instance of a plugin. A global
31 // mutex is required to serialize the retrieval of version control
32 // states inside run().
33 static QMutex globalMutex
;
34 m_globalPluginMutex
= &globalMutex
;
37 UpdateItemStatesThread::~UpdateItemStatesThread()
41 void UpdateItemStatesThread::run()
43 Q_ASSERT(!m_itemStates
.isEmpty());
46 QMutexLocker
pluginLocker(m_globalPluginMutex
);
47 QMap
<QString
, QVector
<VersionControlObserver::ItemState
> >::iterator it
= m_itemStates
.begin();
48 for (; it
!= m_itemStates
.end(); ++it
) {
49 if (m_plugin
->beginRetrieval(it
.key())) {
50 QVector
<VersionControlObserver::ItemState
>& items
= it
.value();
51 const int count
= items
.count();
52 for (int i
= 0; i
< count
; ++i
) {
53 const KFileItem
& item
= items
.at(i
).first
;
54 const KVersionControlPlugin::ItemVersion version
= m_plugin
->itemVersion(item
);
55 items
[i
].second
= version
;
59 m_plugin
->endRetrieval();
63 QMap
<QString
, QVector
<VersionControlObserver::ItemState
> > UpdateItemStatesThread::itemStates() const