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 "revisioncontrolplugin.h"
22 #include <kfileitem.h>
25 #include <QTextStream>
27 RevisionControlPlugin::RevisionControlPlugin()
31 RevisionControlPlugin::~RevisionControlPlugin()
35 // ----------------------------------------------------------------------------
37 SubversionPlugin::SubversionPlugin() :
43 SubversionPlugin::~SubversionPlugin()
47 QString
SubversionPlugin::fileName() const
52 bool SubversionPlugin::beginRetrieval(const QString
& directory
)
54 Q_ASSERT(directory
.endsWith('/'));
55 m_directory
= directory
;
56 const QString path
= directory
+ ".svn/text-base/";
59 const QFileInfoList fileInfoList
= dir
.entryInfoList();
60 const int size
= fileInfoList
.size();
62 for (int i
= 0; i
< size
; ++i
) {
63 fileName
= fileInfoList
.at(i
).fileName();
64 // Remove the ".svn-base" postfix to be able to compare the filenames
65 // in a fast way in SubversionPlugin::revisionState().
66 fileName
.chop(sizeof(".svn-base") / sizeof(char) - 1);
67 if (!fileName
.isEmpty()) {
69 info
.size
= fileInfoList
.at(i
).size();
70 info
.timeStamp
= fileInfoList
.at(i
).lastModified();
71 m_revisionInfoHash
.insert(fileName
, info
);
77 void SubversionPlugin::endRetrieval()
81 RevisionControlPlugin::RevisionState
SubversionPlugin::revisionState(const KFileItem
& item
)
83 const QString name
= item
.name();
85 QFile
file(m_directory
+ name
+ "/.svn");
86 if (file
.open(QIODevice::ReadOnly
)) {
89 return RevisionControlPlugin::LatestRevision
;
91 } else if (m_revisionInfoHash
.contains(name
)) {
92 const RevisionInfo info
= m_revisionInfoHash
.value(item
.name());
93 const QDateTime localTimeStamp
= item
.time(KFileItem::ModificationTime
).dateTime();
94 const QDateTime versionedTimeStamp
= info
.timeStamp
;
96 if (localTimeStamp
> versionedTimeStamp
) {
97 if (info
.size
!= item
.size()) {
98 return RevisionControlPlugin::EditingRevision
;
100 // TODO: a comparison of the content is required
101 } else if (localTimeStamp
< versionedTimeStamp
) {
102 if (info
.size
!= item
.size()) {
103 return RevisionControlPlugin::UpdateRequiredRevision
;
105 // TODO: a comparison of the content is required
107 return RevisionControlPlugin::LatestRevision
;
110 return RevisionControlPlugin::LocalRevision
;