File indexing completed on 2024-04-28 04:37:46
0001 /* 0002 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0003 SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_VCSLOCATION_H 0009 #define KDEVPLATFORM_VCSLOCATION_H 0010 0011 #include <QHash> 0012 #include <QUrl> 0013 #include <QMetaType> 0014 #include <QSharedDataPointer> 0015 0016 class QVariant; 0017 0018 #include "vcsexport.h" 0019 0020 namespace KDevelop 0021 { 0022 /** 0023 * Denotes a local or repository location for a Vcs system. 0024 * 0025 * For the RepositoryLocation type, most of the information 0026 * is vcs-specific. 0027 */ 0028 class KDEVPLATFORMVCS_EXPORT VcsLocation 0029 { 0030 public: 0031 enum LocationType 0032 { 0033 LocalLocation = 0 /**< this is a local location */, 0034 RepositoryLocation = 1 /**< this is a repository location */ 0035 }; 0036 0037 VcsLocation(); 0038 explicit VcsLocation( const QUrl& ); 0039 explicit VcsLocation( const QString& ); 0040 ~VcsLocation(); 0041 VcsLocation( const VcsLocation& ); 0042 VcsLocation& operator=( const VcsLocation& ); 0043 0044 /** 0045 * @returns Local url if this location is a LocalLocation 0046 */ 0047 QUrl localUrl() const; 0048 0049 /** 0050 * Returns a string for the repository, usually this identifies the server. 0051 * @returns a vcs-implementation-specific string identifying the server 0052 */ 0053 QString repositoryServer() const; 0054 /** 0055 * Returns the module or module path inside the server. 0056 * @returns a vcs-implementation-specific string identifying the module 0057 */ 0058 QString repositoryModule() const; 0059 /** 0060 * Identifies the tag which this location belongs to. 0061 * @returns a vcs-implementation-specific string identifying the tag 0062 */ 0063 QString repositoryTag() const; 0064 /** 0065 * Identifies the branch to which this location belongs to. 0066 * @returns a vcs-implementation-specific string identifying the branch 0067 */ 0068 QString repositoryBranch() const; 0069 /** 0070 * This can define a path relative to the module. This is used 0071 * when identifying a subdirectory or file inside a repository location 0072 * @returns a path relative to module 0073 */ 0074 QString repositoryPath() const; 0075 /** 0076 * @returns the type of this location 0077 */ 0078 LocationType type() const; 0079 0080 /** 0081 * Set the local url for this location, automatically sets the type to LocalLocation 0082 * @param url the local url 0083 */ 0084 void setLocalUrl( const QUrl& url ); 0085 0086 /** 0087 * Set the server string for this location, automatically sets the type to RepositoryLocation 0088 */ 0089 void setRepositoryServer( const QString& ); 0090 /** 0091 * Set the module for this location, automatically sets the type to RepositoryLocation 0092 */ 0093 void setRepositoryModule( const QString& ); 0094 /** 0095 * Set the branch string for this location, automatically sets the type to RepositoryLocation 0096 */ 0097 void setRepositoryBranch( const QString& ); 0098 /** 0099 * Set the tag string for this location, automatically sets the type to RepositoryLocation 0100 */ 0101 void setRepositoryTag( const QString& ); 0102 /** 0103 * Set the path for this location, automatically sets the type to RepositoryLocation 0104 */ 0105 void setRepositoryPath( const QString& ); 0106 0107 /** 0108 * Allows to add vcs-specific data to this location. 0109 * Automatically sets the type to RepositoryLocation 0110 * @param data the vcs-specific data 0111 */ 0112 void setUserData( const QVariant& data ); 0113 0114 /** 0115 * retrieve vcs-specific data 0116 */ 0117 QVariant userData() const; 0118 0119 bool operator==( const KDevelop::VcsLocation& ); 0120 0121 bool isValid() const; 0122 0123 private: 0124 QSharedDataPointer<class VcsLocationPrivate> d; 0125 }; 0126 0127 inline uint qHash( const KDevelop::VcsLocation& loc ) 0128 { 0129 if( loc.type() == KDevelop::VcsLocation::LocalLocation ) 0130 { 0131 return qHash(loc.localUrl()); 0132 }else 0133 { 0134 return qHash(loc.repositoryServer()); 0135 } 0136 } 0137 0138 inline bool operator==( const KDevelop::VcsLocation& lhs, const KDevelop::VcsLocation& rhs ) 0139 { 0140 return( lhs.type() == rhs.type() 0141 && lhs.repositoryServer() == rhs.repositoryServer() 0142 && lhs.localUrl() == rhs.localUrl() ); 0143 } 0144 0145 } 0146 0147 Q_DECLARE_METATYPE( KDevelop::VcsLocation ) 0148 Q_DECLARE_TYPEINFO(KDevelop::VcsLocation, Q_MOVABLE_TYPE); 0149 0150 #endif 0151