]>
cloud.milkyroute.net Git - dolphin.git/blob - src/versioncontrol/updateitemstatesthread.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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 UpdateItemStatesThread::UpdateItemStatesThread() :
24 m_retrievedItems(false),
28 static QMutex globalMutex
;
29 m_mutex
= &globalMutex
;
32 UpdateItemStatesThread::~UpdateItemStatesThread()
36 void UpdateItemStatesThread::setData(KVersionControlPlugin
* plugin
,
37 const QList
<VersionControlObserver::ItemState
>& itemStates
)
40 m_itemStates
= itemStates
;
43 void UpdateItemStatesThread::run()
45 Q_ASSERT(!m_itemStates
.isEmpty());
46 Q_ASSERT(m_plugin
!= 0);
48 // The items from m_itemStates may be located in different directory levels. The version
49 // plugin requires the root directory for KVersionControlPlugin::beginRetrieval(). Instead
50 // of doing an expensive search, we utilize the knowledge of the implementation of
51 // VersionControlObserver::addDirectory() to be sure that the last item contains the root.
52 const QString directory
= m_itemStates
.last().item
.url().directory(KUrl::AppendTrailingSlash
);
54 QMutexLocker
locker(m_mutex
);
55 m_retrievedItems
= false;
56 if (m_plugin
->beginRetrieval(directory
)) {
57 const int count
= m_itemStates
.count();
58 for (int i
= 0; i
< count
; ++i
) {
59 m_itemStates
[i
].version
= m_plugin
->versionState(m_itemStates
[i
].item
);
61 m_plugin
->endRetrieval();
62 m_retrievedItems
= true;
66 bool UpdateItemStatesThread::beginReadItemStates()
68 return m_mutex
->tryLock(300);
71 void UpdateItemStatesThread::endReadItemStates()
76 QList
<VersionControlObserver::ItemState
> UpdateItemStatesThread::itemStates() const
81 bool UpdateItemStatesThread::retrievedItems() const
83 return m_retrievedItems
;
86 void UpdateItemStatesThread::deleteWhenFinished()
88 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
91 void UpdateItemStatesThread::slotFinished()
96 #include "updateitemstatesthread.moc"