1 /*
2 * Port for usage with qt-framework and development for kdesvn
3 * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
4 * http://kdesvn.alwins-world.de
5 */
6 /*
7 * ====================================================================
8 * Copyright (c) 2002-2005 The RapidSvn Group. All rights reserved.
9 * dev@rapidsvn.tigris.org
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library (in the file LGPL.txt); if not,
23 * write to the Free Software Foundation, Inc., 51 Franklin St,
24 * Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 * This software consists of voluntary contributions made by many
27 * individuals. For exact contribution history, see the revision
28 * history and logs, available at http://rapidsvn.tigris.org/.
29 * ====================================================================
30 */
31
32 // svncpp
33 #include "entry.h"
34
35 namespace svn
36 {
37 class SVNQT_NOEXPORT Entry_private
38 {
39 protected:
40 void init_clean();
41 public:
42 Entry_private();
43
44 bool m_valid;
45 LockEntry m_Lock;
46
47 QUrl _url, _repos;
48 QString _name, _uuid, _cmt_author;
49 bool _copied;
50 svn_revnum_t _revision, _cmt_rev;
51 svn_node_kind_t _kind;
52 DateTime _cmt_date;
53
54 /**
55 * initializes the members
56 */
57 void
58 init(const svn_client_status_t *src);
59 void
60 init(const Entry_private &src);
61 void
62 init(const QString &url, const DirEntry &src);
63 void
64 init(const QString &url, const InfoEntry &src);
65 };
66
init_clean()67 void Entry_private::init_clean()
68 {
69 _name.clear();
70 _url.clear();
71 _repos.clear();
72 _uuid.clear();
73 _cmt_author.clear();
74 _revision = _cmt_rev = SVN_INVALID_REVNUM;
75 _kind = svn_node_unknown;
76 _cmt_date = DateTime();
77 _copied = false;
78 }
79
Entry_private()80 Entry_private::Entry_private()
81 : m_valid(false), m_Lock()
82 {
83 init_clean();
84 }
85
86 void
init(const svn_client_status_t * src)87 Entry_private::init(const svn_client_status_t *src)
88 {
89 if (src) {
90 // copy & convert the contents of src
91 _name = QString::fromUtf8(src->local_abspath);
92 _revision = src->revision;
93 _repos = QUrl::fromEncoded(src->repos_root_url);
94 _url = _repos;
95 _url.setPath(_url.path() + QLatin1Char('/') + QString::fromUtf8(src->repos_relpath));
96 _uuid = QString::fromUtf8(src->repos_uuid);
97 _kind = src->kind;
98 _copied = src->copied != 0;
99 _cmt_rev = src->changed_rev;
100 _cmt_date = DateTime(src->changed_date);
101 _cmt_author = QString::fromUtf8(src->changed_author);
102 m_Lock.init(src->lock);
103 m_valid = true;
104 } else {
105 init_clean();
106 }
107 }
108
109 void
init(const Entry_private & src)110 Entry_private::init(const Entry_private &src)
111 {
112 _name = src._name;
113 _url = src._url;
114 _repos = src._repos;
115 _uuid = src._uuid;
116 _cmt_author = src._cmt_author;
117 _copied = src._copied;
118 _revision = src._revision;
119 _cmt_rev = src._cmt_rev;
120 _kind = src._kind;
121 _cmt_date = src._cmt_date;
122 m_Lock = src.m_Lock;
123 m_valid = src.m_valid;
124 }
125
init(const QString & url,const DirEntry & dirEntry)126 void Entry_private::init(const QString &url, const DirEntry &dirEntry)
127 {
128 init_clean();
129 _url = QUrl(url);
130 if (!dirEntry.isEmpty()) {
131 _name = dirEntry.name();
132 _revision = dirEntry.createdRev();
133 _kind = dirEntry.kind();
134 _cmt_rev = dirEntry.createdRev();
135 _cmt_date = dirEntry.time();
136 _cmt_author = dirEntry.lastAuthor();
137 m_Lock = dirEntry.lockEntry();
138 m_valid = true;
139 }
140 }
141
init(const QString & url,const InfoEntry & src)142 void Entry_private::init(const QString &url, const InfoEntry &src)
143 {
144 init(nullptr);
145 _name = src.Name();
146 _url = QUrl(url);
147 _revision = src.revision();
148 _kind = src.kind();
149 _cmt_rev = src.cmtRev();
150 _cmt_date = src.cmtDate();
151 _cmt_author = src.cmtAuthor();
152 m_Lock = src.lockEntry();
153 m_valid = true;
154 }
155
Entry(const svn_client_status_t * src)156 Entry::Entry(const svn_client_status_t *src)
157 : m_Data(new Entry_private())
158 {
159 m_Data->init(src);
160 }
161
Entry(const Entry & src)162 Entry::Entry(const Entry &src)
163 : m_Data(new Entry_private())
164 {
165 if (src.m_Data) {
166 m_Data->init(*(src.m_Data));
167 } else {
168 m_Data->init(nullptr);
169 }
170 }
171
Entry(const QString & url,const DirEntry & src)172 Entry::Entry(const QString &url, const DirEntry &src)
173 : m_Data(new Entry_private())
174 {
175 m_Data->init(url, src);
176 }
177
Entry(const QString & url,const InfoEntry & src)178 Entry::Entry(const QString &url, const InfoEntry &src)
179 : m_Data(new Entry_private())
180 {
181 m_Data->init(url, src);
182 }
183
~Entry()184 Entry::~Entry()
185 {
186 delete m_Data;
187 }
188
189 Entry &
operator =(const Entry & src)190 Entry::operator = (const Entry &src)
191 {
192 if (this == &src) {
193 return *this;
194 }
195 if (src.m_Data) {
196 m_Data->init(*(src.m_Data));
197 } else {
198 m_Data->init(nullptr);
199 }
200 return *this;
201 }
202
203 const LockEntry &
lockEntry() const204 Entry::lockEntry()const
205 {
206 return m_Data->m_Lock;
207 }
208
209 const QString &
cmtAuthor() const210 Entry::cmtAuthor() const
211 {
212 return m_Data->_cmt_author;
213 }
214
215 const DateTime &
cmtDate() const216 Entry::cmtDate() const
217 {
218 return m_Data->_cmt_date;
219 }
220
221 svn_revnum_t
cmtRev() const222 Entry::cmtRev() const
223 {
224 return m_Data->_cmt_rev;
225 }
226
227 bool
isCopied() const228 Entry::isCopied() const
229 {
230 return m_Data->_copied != 0;
231 }
232
233 svn_node_kind_t
kind() const234 Entry::kind() const
235 {
236 return m_Data->_kind;
237 }
238 const QString &
uuid() const239 Entry::uuid() const
240 {
241 return m_Data->_uuid;
242 }
243 const QUrl &
repos() const244 Entry::repos() const
245 {
246 return m_Data->_repos;
247 }
248 const QUrl &
url() const249 Entry::url() const
250 {
251 return m_Data->_url;
252 }
253 svn_revnum_t
revision() const254 Entry::revision() const
255 {
256 return m_Data->_revision;
257 }
258 const QString &
name() const259 Entry::name() const
260 {
261 return m_Data->_name;
262 }
263
isValid() const264 bool Entry::isValid() const
265 {
266 return m_Data->m_valid;
267 }
268 }
269
270 /*!
271 \fn svn::Entry::isDir()
272 */
isDir() const273 bool svn::Entry::isDir() const
274 {
275 return kind() == svn_node_dir;
276 }
277
278 /*!
279 \fn svn::Entry::isFile()
280 */
isFile() const281 bool svn::Entry::isFile() const
282 {
283 return kind() == svn_node_file;
284 }
285