]> cloud.milkyroute.net Git - dolphin.git/blob - src/versioncontrol/updateitemstatesthread.cpp
* enable the loading of version control plugins (thanks to Aaron for the hint)
[dolphin.git] / src / versioncontrol / updateitemstatesthread.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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 UpdateItemStatesThread::UpdateItemStatesThread(QObject* parent) :
23 QThread(parent),
24 m_retrievedItems(false),
25 m_mutex(QMutex::Recursive),
26 m_itemStates()
27 {
28 }
29
30 UpdateItemStatesThread::~UpdateItemStatesThread()
31 {
32 }
33
34 void UpdateItemStatesThread::setData(KVersionControlPlugin* plugin,
35 const QList<VersionControlObserver::ItemState>& itemStates)
36 {
37 m_plugin = plugin;
38 m_itemStates = itemStates;
39 }
40
41 void UpdateItemStatesThread::run()
42 {
43 Q_ASSERT(!m_itemStates.isEmpty());
44 Q_ASSERT(m_plugin != 0);
45
46 // The items from m_itemStates may be located in different directory levels. The version
47 // plugin requires the root directory for KVersionControlPlugin::beginRetrieval(). Instead
48 // of doing an expensive search, we utilize the knowledge of the implementation of
49 // VersionControlObserver::addDirectory() to be sure that the last item contains the root.
50 const QString directory = m_itemStates.last().item.url().directory(KUrl::AppendTrailingSlash);
51
52 QMutexLocker locker(&m_mutex);
53 m_retrievedItems = false;
54 if (m_plugin->beginRetrieval(directory)) {
55 const int count = m_itemStates.count();
56 for (int i = 0; i < count; ++i) {
57 m_itemStates[i].version = m_plugin->versionState(m_itemStates[i].item);
58 }
59 m_plugin->endRetrieval();
60 m_retrievedItems = true;
61 }
62 }
63
64 bool UpdateItemStatesThread::beginReadItemStates()
65 {
66 return m_mutex.tryLock(300);
67 }
68
69 void UpdateItemStatesThread::endReadItemStates()
70 {
71 m_mutex.unlock();
72 }
73
74 QList<VersionControlObserver::ItemState> UpdateItemStatesThread::itemStates() const
75 {
76 return m_itemStates;
77 }
78
79 bool UpdateItemStatesThread::retrievedItems() const
80 {
81 return m_retrievedItems;
82 }
83
84 void UpdateItemStatesThread::deleteWhenFinished()
85 {
86 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
87 }
88
89 void UpdateItemStatesThread::slotFinished()
90 {
91 deleteLater();
92 }
93
94 #include "updateitemstatesthread.moc"