File indexing completed on 2024-05-12 17:16:24

0001 /*
0002  * Port for usage with qt-framework and development for kdesvn
0003  * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
0004  * http://kdesvn.alwins-world.de
0005  */
0006 /*
0007  * ====================================================================
0008  * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
0009  * dev@rapidsvn.tigris.org
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Lesser General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2.1 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Lesser General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Lesser General Public
0022  * License along with this library (in the file LGPL.txt); if not,
0023  * write to the Free Software Foundation, Inc., 51 Franklin St,
0024  * Fifth Floor, Boston, MA  02110-1301  USA
0025  *
0026  * This software consists of voluntary contributions made by many
0027  * individuals.  For exact contribution history, see the revision
0028  * history and logs, available at http://rapidsvn.tigris.org/.
0029  * ====================================================================
0030  */
0031 
0032 // svncpp
0033 #include "entry.h"
0034 
0035 namespace svn
0036 {
0037 class SVNQT_NOEXPORT Entry_private
0038 {
0039 protected:
0040     void init_clean();
0041 public:
0042     Entry_private();
0043 
0044     bool m_valid;
0045     LockEntry m_Lock;
0046 
0047     QUrl _url, _repos;
0048     QString _name, _uuid, _cmt_author;
0049     bool _copied;
0050     svn_revnum_t _revision, _cmt_rev;
0051     svn_node_kind_t _kind;
0052     DateTime _cmt_date;
0053 
0054     /**
0055     * initializes the members
0056     */
0057     void
0058     init(const svn_client_status_t *src);
0059     void
0060     init(const Entry_private &src);
0061     void
0062     init(const QString &url, const DirEntry &src);
0063     void
0064     init(const QString &url, const InfoEntry &src);
0065 };
0066 
0067 void Entry_private::init_clean()
0068 {
0069     _name.clear();
0070     _url.clear();
0071     _repos.clear();
0072     _uuid.clear();
0073     _cmt_author.clear();
0074     _revision = _cmt_rev = SVN_INVALID_REVNUM;
0075     _kind = svn_node_unknown;
0076     _cmt_date = DateTime();
0077     _copied = false;
0078 }
0079 
0080 Entry_private::Entry_private()
0081     : m_valid(false), m_Lock()
0082 {
0083     init_clean();
0084 }
0085 
0086 void
0087 Entry_private::init(const svn_client_status_t *src)
0088 {
0089     if (src) {
0090         // copy & convert the contents of src
0091         _name = QString::fromUtf8(src->local_abspath);
0092         _revision = src->revision;
0093         _repos = QUrl::fromEncoded(src->repos_root_url);
0094         _url = _repos;
0095         _url.setPath(_url.path() +  QLatin1Char('/') + QString::fromUtf8(src->repos_relpath));
0096         _uuid = QString::fromUtf8(src->repos_uuid);
0097         _kind = src->kind;
0098         _copied = src->copied != 0;
0099         _cmt_rev = src->changed_rev;
0100         _cmt_date = DateTime(src->changed_date);
0101         _cmt_author = QString::fromUtf8(src->changed_author);
0102         m_Lock.init(src->lock);
0103         m_valid = true;
0104     } else {
0105         init_clean();
0106     }
0107 }
0108 
0109 void
0110 Entry_private::init(const Entry_private &src)
0111 {
0112     _name = src._name;
0113     _url = src._url;
0114     _repos = src._repos;
0115     _uuid = src._uuid;
0116     _cmt_author = src._cmt_author;
0117     _copied = src._copied;
0118     _revision = src._revision;
0119     _cmt_rev = src._cmt_rev;
0120     _kind = src._kind;
0121     _cmt_date = src._cmt_date;
0122     m_Lock = src.m_Lock;
0123     m_valid = src.m_valid;
0124 }
0125 
0126 void Entry_private::init(const QString &url, const DirEntry &dirEntry)
0127 {
0128     init_clean();
0129     _url = QUrl(url);
0130     if (!dirEntry.isEmpty()) {
0131         _name = dirEntry.name();
0132         _revision = dirEntry.createdRev();
0133         _kind = dirEntry.kind();
0134         _cmt_rev = dirEntry.createdRev();
0135         _cmt_date = dirEntry.time();
0136         _cmt_author = dirEntry.lastAuthor();
0137         m_Lock = dirEntry.lockEntry();
0138         m_valid = true;
0139     }
0140 }
0141 
0142 void Entry_private::init(const QString &url, const InfoEntry &src)
0143 {
0144     init(nullptr);
0145     _name = src.Name();
0146     _url = QUrl(url);
0147     _revision = src.revision();
0148     _kind = src.kind();
0149     _cmt_rev = src.cmtRev();
0150     _cmt_date = src.cmtDate();
0151     _cmt_author = src.cmtAuthor();
0152     m_Lock = src.lockEntry();
0153     m_valid = true;
0154 }
0155 
0156 Entry::Entry(const svn_client_status_t *src)
0157     : m_Data(new Entry_private())
0158 {
0159     m_Data->init(src);
0160 }
0161 
0162 Entry::Entry(const Entry &src)
0163     : m_Data(new Entry_private())
0164 {
0165     if (src.m_Data) {
0166         m_Data->init(*(src.m_Data));
0167     } else {
0168         m_Data->init(nullptr);
0169     }
0170 }
0171 
0172 Entry::Entry(const QString &url, const DirEntry &src)
0173     : m_Data(new Entry_private())
0174 {
0175     m_Data->init(url, src);
0176 }
0177 
0178 Entry::Entry(const QString &url, const InfoEntry &src)
0179     : m_Data(new Entry_private())
0180 {
0181     m_Data->init(url, src);
0182 }
0183 
0184 Entry::~Entry()
0185 {
0186     delete m_Data;
0187 }
0188 
0189 Entry &
0190 Entry::operator = (const Entry &src)
0191 {
0192     if (this == &src) {
0193         return *this;
0194     }
0195     if (src.m_Data) {
0196         m_Data->init(*(src.m_Data));
0197     } else {
0198         m_Data->init(nullptr);
0199     }
0200     return *this;
0201 }
0202 
0203 const LockEntry &
0204 Entry::lockEntry()const
0205 {
0206     return m_Data->m_Lock;
0207 }
0208 
0209 const QString &
0210 Entry::cmtAuthor() const
0211 {
0212     return m_Data->_cmt_author;
0213 }
0214 
0215 const DateTime &
0216 Entry::cmtDate() const
0217 {
0218     return m_Data->_cmt_date;
0219 }
0220 
0221 svn_revnum_t
0222 Entry::cmtRev() const
0223 {
0224     return m_Data->_cmt_rev;
0225 }
0226 
0227 bool
0228 Entry::isCopied() const
0229 {
0230     return m_Data->_copied != 0;
0231 }
0232 
0233 svn_node_kind_t
0234 Entry::kind() const
0235 {
0236     return m_Data->_kind;
0237 }
0238 const QString &
0239 Entry::uuid() const
0240 {
0241     return m_Data->_uuid;
0242 }
0243 const QUrl &
0244 Entry::repos() const
0245 {
0246     return m_Data->_repos;
0247 }
0248 const QUrl &
0249 Entry::url() const
0250 {
0251     return m_Data->_url;
0252 }
0253 svn_revnum_t
0254 Entry::revision() const
0255 {
0256     return m_Data->_revision;
0257 }
0258 const QString &
0259 Entry::name() const
0260 {
0261     return m_Data->_name;
0262 }
0263 
0264 bool Entry::isValid() const
0265 {
0266     return m_Data->m_valid;
0267 }
0268 }
0269 
0270 /*!
0271     \fn svn::Entry::isDir()
0272  */
0273 bool svn::Entry::isDir() const
0274 {
0275     return kind() == svn_node_dir;
0276 }
0277 
0278 /*!
0279     \fn svn::Entry::isFile()
0280  */
0281 bool svn::Entry::isFile() const
0282 {
0283     return kind() == svn_node_file;
0284 }