]>
cloud.milkyroute.net Git - dolphin.git/blob - src/revisioncontrolobserver.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 "revisioncontrolobserver.h"
22 #include "dolphinmodel.h"
23 #include "revisioncontrolplugin.h"
25 #include <kdirlister.h>
27 #include <QAbstractProxyModel>
28 #include <QAbstractItemView>
31 RevisionControlObserver::RevisionControlObserver(QAbstractItemView
* view
) :
36 m_dirVerificationTimer(0),
41 QAbstractProxyModel
* proxyModel
= qobject_cast
<QAbstractProxyModel
*>(view
->model());
42 m_dolphinModel
= (proxyModel
== 0) ?
43 qobject_cast
<DolphinModel
*>(view
->model()) :
44 qobject_cast
<DolphinModel
*>(proxyModel
->sourceModel());
45 if (m_dolphinModel
!= 0) {
46 m_dirLister
= m_dolphinModel
->dirLister();
47 connect(m_dirLister
, SIGNAL(completed()),
48 this, SLOT(delayedDirectoryVerification()));
50 // connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
51 // this, SLOT(refreshItems()));
53 // The verification timer specifies the timeout until the shown directory
54 // is checked whether it is versioned. Per default it is assumed that users
55 // don't iterate through versioned directories and a high timeout is used
56 // The timeout will be decreased as soon as a versioned directory has been
57 // found (see verifyDirectory()).
58 m_dirVerificationTimer
= new QTimer(this);
59 m_dirVerificationTimer
->setSingleShot(true);
60 m_dirVerificationTimer
->setInterval(500);
61 connect(m_dirVerificationTimer
, SIGNAL(timeout()),
62 this, SLOT(verifyDirectory()));
66 RevisionControlObserver::~RevisionControlObserver()
72 void RevisionControlObserver::delayedDirectoryVerification()
74 m_dirVerificationTimer
->start();
77 void RevisionControlObserver::verifyDirectory()
79 KUrl revisionControlUrl
= m_dirLister
->url();
80 if (!revisionControlUrl
.isLocalFile()) {
85 // TODO: just for testing purposes. A plugin approach will be used later.
86 m_plugin
= new SubversionPlugin();
89 revisionControlUrl
.addPath(m_plugin
->fileName());
90 KFileItem item
= m_dirLister
->findByUrl(revisionControlUrl
);
92 // The directory is not versioned. Reset the verification timer to a higher
93 // value, so that browsing through non-versioned directories is not slown down
94 // by an immediate verification.
95 m_dirVerificationTimer
->setInterval(500);
97 // The directory is versioned. Assume that the user will further browse through
98 // versioned directories and decrease the verification timer.
99 m_dirVerificationTimer
->setInterval(100);
104 void RevisionControlObserver::updateItemStates()
106 Q_ASSERT(m_plugin
!= 0);
107 const KUrl directory
= m_dirLister
->url();
108 if (!m_plugin
->beginRetrieval(directory
.toLocalFile(KUrl::AddTrailingSlash
))) {
112 const int rowCount
= m_dolphinModel
->rowCount();
113 for (int row
= 0; row
< rowCount
; ++row
) {
114 const QModelIndex index
= m_dolphinModel
->index(row
, DolphinModel::Revision
);
115 const KFileItem item
= m_dolphinModel
->itemForIndex(index
);
116 const RevisionControlPlugin::RevisionState revision
= m_plugin
->revisionState(item
.name());
117 m_dolphinModel
->setData(index
, QVariant(static_cast<int>(revision
)), Qt::DecorationRole
);
119 m_view
->viewport()->repaint(); // TODO: this should not be necessary, as DolphinModel::setData() calls dataChanged()
121 m_plugin
->endRetrieval();
124 #include "revisioncontrolobserver.moc"