]> cloud.milkyroute.net Git - dolphin.git/blob - src/revisioncontrolplugin.cpp
- interface cleanups
[dolphin.git] / src / revisioncontrolplugin.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 "revisioncontrolplugin.h"
21
22 #include <kfileitem.h>
23 #include <QDir>
24 #include <QString>
25 #include <QTextStream>
26
27 RevisionControlPlugin::RevisionControlPlugin()
28 {
29 }
30
31 RevisionControlPlugin::~RevisionControlPlugin()
32 {
33 }
34
35 // ----------------------------------------------------------------------------
36
37 SubversionPlugin::SubversionPlugin() :
38 m_directory(),
39 m_revisionInfoHash()
40 {
41 }
42
43 SubversionPlugin::~SubversionPlugin()
44 {
45 }
46
47 QString SubversionPlugin::fileName() const
48 {
49 return ".svn";
50 }
51
52 bool SubversionPlugin::beginRetrieval(const QString& directory)
53 {
54 Q_ASSERT(directory.endsWith('/'));
55 m_directory = directory;
56 const QString path = directory + ".svn/text-base/";
57
58 QDir dir(path);
59 const QFileInfoList fileInfoList = dir.entryInfoList();
60 const int size = fileInfoList.size();
61 QString fileName;
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()) {
68 RevisionInfo info;
69 info.size = fileInfoList.at(i).size();
70 info.timeStamp = fileInfoList.at(i).lastModified();
71 m_revisionInfoHash.insert(fileName, info);
72 }
73 }
74 return size > 0;
75 }
76
77 void SubversionPlugin::endRetrieval()
78 {
79 }
80
81 RevisionControlPlugin::RevisionState SubversionPlugin::revisionState(const KFileItem& item)
82 {
83 const QString name = item.name();
84 if (item.isDir()) {
85 QFile file(m_directory + name + "/.svn");
86 if (file.open(QIODevice::ReadOnly)) {
87 file.close();
88 // TODO...
89 return RevisionControlPlugin::LatestRevision;
90 }
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;
95
96 if (localTimeStamp > versionedTimeStamp) {
97 if (info.size != item.size()) {
98 return RevisionControlPlugin::EditingRevision;
99 }
100 // TODO: a comparison of the content is required
101 } else if (localTimeStamp < versionedTimeStamp) {
102 if (info.size != item.size()) {
103 return RevisionControlPlugin::UpdateRequiredRevision;
104 }
105 // TODO: a comparison of the content is required
106 }
107 return RevisionControlPlugin::LatestRevision;
108 }
109
110 return RevisionControlPlugin::LocalRevision;
111 }