15
15
You should have received a copy of the GNU Library General Public License
16
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
21
#ifndef _URLUTIL_H_
22
22
#define _URLUTIL_H_
25
#include <qvaluelist.h>
24
#include <QtCore/QString>
30
enum SlashesPosition { SLASH_PREFIX = 1, SLASH_SUFFIX = 2 };
33
* Returns the filename part of a pathname (i.e. everything past the last slash)
35
QString filename(const QString & pathName);
37
* Returns the directory part of a path (i.e. everything up to but not including the last slash)
39
QString directory(const QString & pathName);
41
* Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
43
QString relativePath(const KURL & parent, const KURL & child, uint slashPolicy = SLASH_PREFIX);
45
* Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
47
QString relativePath(const QString & parent, const QString & child, uint slashPolicy = SLASH_PREFIX);
49
* Returns the relative path between a directory and file. Should never return empty path.
51
* dirUrl: /home/test/src
52
* fileUrl: /home/test/lib/mylib.cpp
53
* returns: ../lib/mylib.cpp
55
QString relativePathToFile( const QString & dirUrl, const QString & fileUrl );
57
*Returns the path 'up one level' - the opposite of what filename returns
59
QString upDir(const QString & path, bool slashSuffix = false);
61
* 'Merges' URLs - changes a URL that starts with dest to start with source instead
65
* child is /home/you/dir1/file1
66
* returns /home/me/dir1/fil1
68
KURL mergeURL(const KURL & source, const KURL & dest, const KURL & child);
70
* Returns the file extension for a filename or path
72
QString getExtension(const QString & path);
75
* Given a base directory url in @p baseDirUrl and the url referring to a date sub-directory or file,
76
* it will return the path relative to @p baseDirUrl.
77
* If baseDirUrl == url.path() then it will return ".".
79
* KURL baseUrl, dirUrl;
80
* baseUrl.setPath( "/home/mario/src/kdevelop/" );
81
* dirUrl.setPath( "/home/mario/src/kdevelop/parts/cvs/" );
82
* QString relPathName = extractDirPathRelative( baseUrl, url ); // == "parts/cvs/"
83
* QString absPathName = extractDirPathAbsolute( url ); // == "/home/mario/src/kdevelop/parts/cvs/"
85
* Note that if you pass a file name in @p url (instead of a directory) or the @p baseUrl is not contained
86
* in @p url then the function will return "" (void string).
88
QString extractPathNameRelative(const KURL &baseDirUrl, const KURL &url );
89
QString extractPathNameRelative(const QString &basePath, const KURL &url );
90
QString extractPathNameRelative(const QString &basePath, const QString &absFilePath );
93
* Will return the absolute path name referred in @p url.
94
* Look at above for an example.
96
QString extractPathNameAbsolute( const KURL &url );
99
* Returns a QStringList of relative (to @p baseDir) paths from a list of KURLs in @p urls
101
QStringList toRelativePaths( const QString &baseDir, const KURL::List &urls);
104
* If @p url is a directory will return true, false otherwise.
106
bool isDirectory( const KURL &url );
107
bool isDirectory( const QString &absFilePath );
110
* Will dump the list of KURL @p urls on standard output, eventually printing @ aMessage if it
113
void dump( const KURL::List &urls, const QString &aMessage = QString::null );
116
* Same as QDir::canonicalPath in later versions of QT. Earlier versions of QT
117
* had this broken, so it's reproduced here.
119
QString canonicalPath( const QString & path );
122
* Performs environment variable expansion on @p variable.
124
* @param variable the string with the environment variable to expand.
125
* @return the expanded environment variable value. if the variable
126
* cannot be expanded, @p variable itself is returned.
128
QString envExpand ( const QString &variable );
30
enum SlashesPosition { SLASH_PREFIX = 1, SLASH_SUFFIX = 2 };
33
* Returns the filename part of a pathname (i.e. everything past the last slash)
35
QString filename(const QString & pathName);
37
* Returns the directory part of a path (i.e. everything up to but not including the last slash)
39
QString directory(const QString & pathName);
41
* Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
43
QString relativePath(const KUrl & parent, const KUrl & child, uint slashPolicy = SLASH_PREFIX);
45
* Returns the relative path between a parent and child URL, or blank if the specified child is not a child of parent
47
QString relativePath(const QString & parent, const QString & child, uint slashPolicy = SLASH_PREFIX);
49
* Returns the relative path between a directory and file. Should never return empty path.
51
* dirUrl: /home/test/src
52
* fileUrl: /home/test/lib/mylib.cpp
53
* returns: ../lib/mylib.cpp
55
QString relativePathToFile(const QString & dirUrl, const QString & fileUrl);
57
* Returns the path 'up one level' - the opposite of what filename returns
59
QString upDir(const QString & path, bool slashSuffix = false);
61
* 'Merges' URLs - changes a URL that starts with dest to start with source instead
65
* child is /home/you/dir1/file1
66
* returns /home/me/dir1/fil1
68
KUrl mergeURL(const KUrl & source, const KUrl & dest, const KUrl & child);
70
* Returns the file extension for a filename or path
72
QString getExtension(const QString & path);
75
* Given a base directory url in @p baseDirUrl and the url referring to a date sub-directory or file,
76
* it will return the path relative to @p baseDirUrl.
77
* If baseDirUrl == url.path() then it will return ".".
79
* KUrl baseUrl, dirUrl;
80
* baseUrl.setPath( "/home/mario/src/kdevelop/" );
81
* dirUrl.setPath( "/home/mario/src/kdevelop/parts/cvs/" );
82
* QString relPathName = extractDirPathRelative( baseUrl, url ); // == "parts/cvs/"
83
* QString absPathName = extractDirPathAbsolute( url ); // == "/home/mario/src/kdevelop/parts/cvs/"
85
* Note that if you pass a file name in @p url (instead of a directory) or the @p baseUrl is not contained
86
* in @p url then the function will return "" (void string).
88
QString extractPathNameRelative(const KUrl &baseDirUrl, const KUrl &url);
89
QString extractPathNameRelative(const QString &basePath, const KUrl &url);
90
QString extractPathNameRelative(const QString &basePath, const QString &absFilePath);
93
* Will return the absolute path name referred in @p url.
94
* Look at above for an example.
96
QString extractPathNameAbsolute(const KUrl &url);
99
* Returns a QStringList of relative (to @p baseDir) paths from a list of KURLs in @p urls
101
QStringList toRelativePaths(const QString &baseDir, const KUrl::List &urls);
104
* If @p url is a directory will return true, false otherwise.
106
bool isDirectory(const KUrl &url);
107
bool isDirectory(const QString &absFilePath);
110
* Will dump the list of KUrl @p urls on standard output, eventually printing @ aMessage if it
113
void dump(const KUrl::List &urls, const QString &aMessage = QString());
116
* Same as QDir::canonicalPath in later versions of QT. Earlier versions of QT
117
* had this broken, so it's reproduced here.
119
QString canonicalPath(const QString & path);
122
* Performs environment variable expansion on @p variable.
124
* @param variable the string with the environment variable to expand.
125
* @return the expanded environment variable value. if the variable
126
* cannot be expanded, @p variable itself is returned.
128
QString envExpand(const QString &variable);