File indexing completed on 2024-04-28 04:37:46

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "vcslocation.h"
0008 
0009 #include <QVariant>
0010 
0011 namespace KDevelop
0012 {
0013 
0014 class VcsLocationPrivate : public QSharedData
0015 {
0016 public:
0017     QUrl m_localUrl;
0018     QString m_repoServer;
0019     QString m_repoPath;
0020     QString m_repoModule;
0021     QString m_repoBranch;
0022     QString m_repoTag;
0023     VcsLocation::LocationType m_type;
0024     QVariant m_userData;
0025 };
0026 
0027 VcsLocation::VcsLocation()
0028     : d(new VcsLocationPrivate)
0029 {
0030     d->m_type = VcsLocation::LocalLocation;
0031 }
0032 
0033 
0034 VcsLocation::VcsLocation( const QUrl& u )
0035     : d(new VcsLocationPrivate)
0036 {
0037     setLocalUrl( u );
0038 }
0039 
0040 VcsLocation::VcsLocation( const QString& s )
0041     : d(new VcsLocationPrivate)
0042 {
0043     setRepositoryServer( s );
0044 }
0045 
0046 VcsLocation::~VcsLocation() = default;
0047 
0048 VcsLocation::VcsLocation( const VcsLocation& rhs )
0049     : d(rhs.d)
0050 {
0051 }
0052 
0053 VcsLocation& VcsLocation::operator=( const VcsLocation& rhs )
0054 {
0055     d = rhs.d;
0056     return *this;
0057 }
0058 
0059 QUrl VcsLocation::localUrl() const
0060 {
0061     return d->m_localUrl;
0062 }
0063 QString VcsLocation::repositoryServer() const
0064 {
0065     return d->m_repoServer;
0066 }
0067 
0068 VcsLocation::LocationType VcsLocation::type() const
0069 {
0070     return d->m_type;
0071 }
0072 
0073 bool VcsLocation::isValid() const
0074 {
0075     return( ( d->m_localUrl.isValid()
0076               && d->m_type == VcsLocation::LocalLocation )
0077             || ( !d->m_repoServer.isEmpty()
0078                 && d->m_type == VcsLocation::RepositoryLocation ) );
0079 }
0080 
0081 void VcsLocation::setLocalUrl( const QUrl& url )
0082 {
0083     d->m_repoServer.clear();
0084     d->m_repoModule.clear();
0085     d->m_repoBranch.clear();
0086     d->m_repoTag.clear();
0087     d->m_repoPath.clear();
0088     d->m_type = VcsLocation::LocalLocation;
0089     d->m_localUrl = url;
0090 }
0091 void VcsLocation::setRepositoryServer( const QString& location )
0092 {
0093     d->m_repoServer = location;
0094     d->m_type = VcsLocation::RepositoryLocation;
0095     d->m_localUrl = QUrl();
0096 }
0097 
0098 bool VcsLocation::operator==( const KDevelop::VcsLocation& rhs )
0099 {
0100     return( type() == rhs.type()
0101             && repositoryServer() == rhs.repositoryServer()
0102             && localUrl() == rhs.localUrl()
0103             && repositoryPath() == rhs.repositoryPath()
0104             && repositoryModule() == rhs.repositoryModule()
0105             && repositoryBranch() == rhs.repositoryBranch()
0106             && repositoryTag() == rhs.repositoryTag()
0107             && userData() == rhs.userData() );
0108 }
0109 
0110 
0111 QString VcsLocation::repositoryModule( ) const
0112 {
0113     return d->m_repoModule;
0114 }
0115 
0116 QString VcsLocation::repositoryTag( ) const
0117 {
0118     return d->m_repoTag;
0119 }
0120 
0121 QString VcsLocation::repositoryBranch( ) const
0122 {
0123     return d->m_repoBranch;
0124 }
0125 
0126 QString VcsLocation::repositoryPath( ) const
0127 {
0128     return d->m_repoPath;
0129 }
0130 
0131 void VcsLocation::setRepositoryModule( const QString & module )
0132 {
0133     d->m_repoModule = module;
0134     d->m_type = VcsLocation::RepositoryLocation;
0135     d->m_localUrl.clear();
0136 }
0137 
0138 void VcsLocation::setRepositoryBranch( const QString & branch )
0139 {
0140     d->m_repoBranch = branch;
0141     d->m_type = VcsLocation::RepositoryLocation;
0142     d->m_localUrl.clear();
0143 }
0144 
0145 void VcsLocation::setRepositoryTag( const QString & tag )
0146 {
0147     d->m_repoTag = tag;
0148     d->m_type = VcsLocation::RepositoryLocation;
0149     d->m_localUrl.clear();
0150 }
0151 
0152 void VcsLocation::setRepositoryPath( const QString & path )
0153 {
0154     d->m_repoPath = path;
0155     d->m_type = VcsLocation::RepositoryLocation;
0156     d->m_localUrl.clear();
0157 }
0158 
0159 
0160 QVariant VcsLocation::userData( ) const
0161 {
0162     return d->m_userData;
0163 }
0164 
0165 void VcsLocation::setUserData( const QVariant& data )
0166 {
0167     d->m_type = VcsLocation::RepositoryLocation;
0168     d->m_localUrl.clear();
0169     d->m_userData = data;
0170 }
0171 
0172 }
0173