2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Private() : ref(1), renameAcceptance(Vng::Undecided
), protectionAcceptance(Vng::Undecided
), isBinaryFile(false)
27 QString protection
, oldProtection
;
28 QString sha1
, oldSha1
;
30 QByteArray oldFilename
;
33 Vng::Acceptance renameAcceptance
;
34 Vng::Acceptance protectionAcceptance
;
43 File::File(const File
&other
)
55 void File::addHunk(const Hunk
&hunk
)
61 QList
<Hunk
> File::hunks() const
66 bool File::isValid() const
68 return !d
->filename
.isEmpty();
71 void File::setFileName(const QByteArray
&filename
)
73 d
->filename
= filename
;
74 d
->renameAcceptance
= d
->oldFilename
== d
->filename
? Vng::Accepted
: Vng::Undecided
;
77 QByteArray
File::fileName() const
82 File
& File::operator=(const File
&other
)
91 bool File::operator==(const File
&other
)
96 int File::count() const
98 return d
->hunks
.count();
101 void File::setOldFileName(const QByteArray
&filename
)
103 d
->oldFilename
= filename
;
104 d
->renameAcceptance
= d
->oldFilename
== d
->filename
? Vng::Accepted
: Vng::Undecided
;
107 QByteArray
File::oldFileName() const
109 return d
->oldFilename
;
112 void File::setProtection(const QString
&string
)
114 d
->protection
= string
;
115 d
->protectionAcceptance
= string
== d
->oldProtection
? Vng::Accepted
: Vng::Undecided
;
118 void File::setOldProtection(const QString
&string
)
120 d
->oldProtection
= string
;
121 d
->protectionAcceptance
= string
== d
->protection
? Vng::Accepted
: Vng::Undecided
;
124 QString
File::protection() const
126 return d
->protection
;
129 QString
File::oldProtection() const
131 return d
->oldProtection
;
135 void File::setOldSha1(const QString
&string
)
140 void File::setSha1(const QString
&string
)
145 QString
File::oldSha1() const
150 QString
File::sha1() const
155 bool File::hasChanged() const
157 return count() || d
->protection
!= d
->oldProtection
||
158 d
->filename
!= d
->oldFilename
;
161 void File::setRenameAcceptance(Vng::Acceptance accepted
)
163 if (d
->filename
!= d
->oldFilename
)
164 d
->renameAcceptance
= accepted
;
167 void File::setProtectionAcceptance(Vng::Acceptance accepted
)
169 if (d
->protection
!= d
->oldProtection
)
170 d
->protectionAcceptance
= accepted
;
173 Vng::Acceptance
File::renameAcceptance() const
175 return d
->renameAcceptance
;
178 Vng::Acceptance
File::protectionAcceptance() const
180 return d
->protectionAcceptance
;
183 QFile::Permissions
File::permissions() const
185 QFile::Permissions perms
;
186 if (d
->protection
.length() != 6)
188 Q_ASSERT(d
->protection
.length() == 6);
189 const int user
= d
->protection
.mid(3,1).toInt();
190 if (user
& 1) perms
|= QFile::ExeOwner
;
191 if (user
& 2) perms
|= QFile::WriteOwner
;
192 if (user
& 4) perms
|= QFile::ReadOwner
;
193 const int group
= d
->protection
.mid(4,1).toInt();
194 if (group
& 1) perms
|= QFile::ExeGroup
;
195 if (group
& 2) perms
|= QFile::WriteGroup
;
196 if (group
& 4) perms
|= QFile::ReadGroup
;
197 const int other
= d
->protection
.mid(5,1).toInt();
198 if (other
& 1) perms
|= QFile::ExeOther
;
199 if (other
& 2) perms
|= QFile::WriteOther
;
200 if (other
& 4) perms
|= QFile::ReadOther
;
204 int File::linesAdded() const
207 foreach(Hunk hunk
, d
->hunks
)
208 total
+= hunk
.linesAdded();
212 int File::linesRemoved() const
215 foreach(Hunk hunk
, d
->hunks
)
216 total
+= hunk
.linesRemoved();
220 void File::setBinary(bool binary
)
222 d
->isBinaryFile
= binary
;
225 bool File::isBinary() const
227 return d
->isBinaryFile
;