File indexing completed on 2024-04-28 05:42:10

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  * https://kde.org/applications/development/org.kde.kdesvn
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 
0042 public:
0043     Entry_private();
0044 
0045     LockEntry m_Lock;
0046 
0047     QUrl _url, _repos;
0048     DateTime _cmt_date;
0049     QString _name, _uuid, _cmt_author;
0050     svn_revnum_t _revision, _cmt_rev;
0051     svn_node_kind_t _kind;
0052     bool m_valid;
0053     bool _copied;
0054 
0055     /**
0056      * initializes the members
0057      */
0058     void init(const svn_client_status_t *src);
0059     void init(const Entry_private &src);
0060     void init(const QString &url, const DirEntry &src);
0061     void init(const QString &url, const InfoEntry &src);
0062 };
0063 
0064 void Entry_private::init_clean()
0065 {
0066     _name.clear();
0067     _url.clear();
0068     _repos.clear();
0069     _uuid.clear();
0070     _cmt_author.clear();
0071     _revision = _cmt_rev = SVN_INVALID_REVNUM;
0072     _kind = svn_node_unknown;
0073     _cmt_date = DateTime();
0074     _copied = false;
0075 }
0076 
0077 Entry_private::Entry_private()
0078     : m_valid(false)
0079 {
0080     init_clean();
0081 }
0082 
0083 void Entry_private::init(const svn_client_status_t *src)
0084 {
0085     if (src) {
0086         // copy & convert the contents of src
0087         _name = QString::fromUtf8(src->local_abspath);
0088         _revision = src->revision;
0089         _repos = QUrl::fromEncoded(src->repos_root_url);
0090         _url = _repos;
0091         _url.setPath(_url.path() + QLatin1Char('/') + QString::fromUtf8(src->repos_relpath));
0092         _uuid = QString::fromUtf8(src->repos_uuid);
0093         _kind = src->kind;
0094         _copied = src->copied != 0;
0095         _cmt_rev = src->changed_rev;
0096         _cmt_date = DateTime(src->changed_date);
0097         _cmt_author = QString::fromUtf8(src->changed_author);
0098         m_Lock.init(src->lock);
0099         m_valid = true;
0100     } else {
0101         init_clean();
0102     }
0103 }
0104 
0105 void Entry_private::init(const Entry_private &src)
0106 {
0107     _name = src._name;
0108     _url = src._url;
0109     _repos = src._repos;
0110     _uuid = src._uuid;
0111     _cmt_author = src._cmt_author;
0112     _copied = src._copied;
0113     _revision = src._revision;
0114     _cmt_rev = src._cmt_rev;
0115     _kind = src._kind;
0116     _cmt_date = src._cmt_date;
0117     m_Lock = src.m_Lock;
0118     m_valid = src.m_valid;
0119 }
0120 
0121 void Entry_private::init(const QString &url, const DirEntry &dirEntry)
0122 {
0123     init_clean();
0124     _url = QUrl(url);
0125     if (!dirEntry.isEmpty()) {
0126         _name = dirEntry.name();
0127         _revision = dirEntry.createdRev();
0128         _kind = dirEntry.kind();
0129         _cmt_rev = dirEntry.createdRev();
0130         _cmt_date = dirEntry.time();
0131         _cmt_author = dirEntry.lastAuthor();
0132         m_Lock = dirEntry.lockEntry();
0133         m_valid = true;
0134     }
0135 }
0136 
0137 void Entry_private::init(const QString &url, const InfoEntry &src)
0138 {
0139     init(nullptr);
0140     _name = src.Name();
0141     _url = QUrl(url);
0142     _revision = src.revision();
0143     _kind = src.kind();
0144     _cmt_rev = src.cmtRev();
0145     _cmt_date = src.cmtDate();
0146     _cmt_author = src.cmtAuthor();
0147     m_Lock = src.lockEntry();
0148     m_valid = true;
0149 }
0150 
0151 Entry::Entry(const svn_client_status_t *src)
0152     : m_Data(new Entry_private())
0153 {
0154     m_Data->init(src);
0155 }
0156 
0157 Entry::Entry(const Entry &src)
0158     : m_Data(new Entry_private())
0159 {
0160     if (src.m_Data) {
0161         m_Data->init(*(src.m_Data));
0162     } else {
0163         m_Data->init(nullptr);
0164     }
0165 }
0166 
0167 Entry::Entry(const QString &url, const DirEntry &src)
0168     : m_Data(new Entry_private())
0169 {
0170     m_Data->init(url, src);
0171 }
0172 
0173 Entry::Entry(const QString &url, const InfoEntry &src)
0174     : m_Data(new Entry_private())
0175 {
0176     m_Data->init(url, src);
0177 }
0178 
0179 Entry::~Entry()
0180 {
0181     delete m_Data;
0182 }
0183 
0184 Entry &Entry::operator=(const Entry &src)
0185 {
0186     if (this == &src) {
0187         return *this;
0188     }
0189     if (src.m_Data) {
0190         m_Data->init(*(src.m_Data));
0191     } else {
0192         m_Data->init(nullptr);
0193     }
0194     return *this;
0195 }
0196 
0197 const LockEntry &Entry::lockEntry() const
0198 {
0199     return m_Data->m_Lock;
0200 }
0201 
0202 const QString &Entry::cmtAuthor() const
0203 {
0204     return m_Data->_cmt_author;
0205 }
0206 
0207 const DateTime &Entry::cmtDate() const
0208 {
0209     return m_Data->_cmt_date;
0210 }
0211 
0212 svn_revnum_t Entry::cmtRev() const
0213 {
0214     return m_Data->_cmt_rev;
0215 }
0216 
0217 bool Entry::isCopied() const
0218 {
0219     return m_Data->_copied != 0;
0220 }
0221 
0222 svn_node_kind_t Entry::kind() const
0223 {
0224     return m_Data->_kind;
0225 }
0226 const QString &Entry::uuid() const
0227 {
0228     return m_Data->_uuid;
0229 }
0230 const QUrl &Entry::repos() const
0231 {
0232     return m_Data->_repos;
0233 }
0234 const QUrl &Entry::url() const
0235 {
0236     return m_Data->_url;
0237 }
0238 svn_revnum_t Entry::revision() const
0239 {
0240     return m_Data->_revision;
0241 }
0242 const QString &Entry::name() const
0243 {
0244     return m_Data->_name;
0245 }
0246 
0247 bool Entry::isValid() const
0248 {
0249     return m_Data->m_valid;
0250 }
0251 }
0252 
0253 /*!
0254     \fn svn::Entry::isDir()
0255  */
0256 bool svn::Entry::isDir() const
0257 {
0258     return kind() == svn_node_dir;
0259 }
0260 
0261 /*!
0262     \fn svn::Entry::isFile()
0263  */
0264 bool svn::Entry::isFile() const
0265 {
0266     return kind() == svn_node_file;
0267 }