8
Classes and functions to work with relative URLs.
11
/**Classes and functions to work with relative URLs.*/
15
/**Relative name of a file or directory.*/
18
enum Type { File, Directory, Auto };
20
/**Constructor takes the relative name of a directory or file.
21
Leading slash in the name will be deleted.
22
If type is Auto names like:
23
name/name/ are directories
25
Trailing slash will be deleted for files (type == File).*/
26
Name(const QString &rurl, const Type type = Auto);
27
Name(const char *rurl, const Type type = Auto);
29
/**Sets the relative name.*/
30
void setRURL(const QString &rurl, const Type type);
31
/**Gets the relative name in form
34
dir/dir/file -> file.*/
37
/**Adds addendum to the directory path. This honors file names so
38
if RName represents /dir1/dir2/fname.ext
39
addPath(dir3) will change RName to /dir1/dir2/dir3/fname.ext*/
40
void addPath(const QString &addendum);
41
/**Removes "//" from the name.*/
44
/**Returns the extension of a file or QString::null for directories.
45
If complete is true then returns extensions like "tar.gz".
47
QString extension(bool complete = true) const;
48
/**Returns the name of the file without the path or QString::null
50
QString fileName() const;
51
/**Returns the name of the directory or QString::null if there are no dirs in path.*/
52
QString directory() const;
54
/**Returns true if the type of RName is file.*/
56
/**Returns true if the type of RName is directory.*/
57
bool isDirectory() const;
58
/**Checks if RName is valid.*/
61
/**Returns a type of the relative name - file or directory.*/
63
/**Sets a type of the relative name - file or directory.
64
If Auto is passed, nothing happens.*/
65
void setType(const Type type);
67
/**Creates and returns relative name between base and url. Base and url should be absolute.
68
Base is considered to be a directory.*/
69
static Name relativeName(const QString &base, const QString &url);
70
/**Cleans rurl by removing extra slashes.*/
71
static QString cleanName(const QString &rurl);
72
/**Corrects rurl according to the given type and returns corrected url.
73
Also cleans url (see @ref cleanRURL).*/
74
static QString correctName(const QString &rurl, const Type type = Auto);
76
bool operator == (const Name &rname);
77
bool operator != (const Name &rname);
80
/**Corrects m_rurl and m_type according to the relative name storing policy,
81
i.e. removes leading slash, removes trailing slash for files, changes type
82
to be either File or Directory, but not Auto. Also cleans url (see @ref cleanRURL).*/
90
/**Relative name of file or directory to some base location.*/
91
class URL: public Name{
93
/**Evaluates the relative path between url and base and creates RURL object.
94
base should be an url to the directory or location, not a file.
95
The check is not performed. url should be the usual url. Only the
96
path of this url is taken into account when evaluating relative path.*/
97
URL(KURL base, KURL url, Type type = Auto);
98
/**Creates RURL object with given base and relative or full url (according to
99
the isUrlRelative value).*/
100
URL(KURL base, QString url, bool isUrlRelative, Type type = Auto);
102
/**Sets a new base for a RURL.*/
103
void setBase(const KURL &base);
104
/**Sets a new base for a RURL. Base is is considered to be a
105
directory and converted to KURL using KURL::setPath().*/
106
void setBase(const QString &base);
107
/**Returns RURL base.*/
109
/**Returns a path of a base KURL (using KURL::path()). Trailing slash is guaranteed.*/
110
QString basePath() const;
112
/**Returns a complete url to the RURL location. This is basically base + rurl.
113
This also resolves ".." components in path.
114
Directories always have trailing slash in KURL
115
(this means that if url() == "file:/test/dir/" then
116
url() != KURL("/test/dir") and
117
url() == KURL("/test/dir/").*/
119
/**Returns a path of a complete url to the location. The url is basically base + rurl.
120
This method only returns a path part of the KURL (using KURL::path()).
121
Trailing slash is guaranteed for directories and no trailing slash - for files.
122
This also resolves ".." components in path.*/
123
QString urlPath() const;
124
/**Returns a directory of a complete url to the location. The url is constructed as base + rurl.
125
Returns the same as urlPath() for directories.
126
This method uses KURL::directory to determine the directory.
127
Trailing slash is guaranteed.
128
This also resolves ".." components in path.*/
129
QString urlDirectory() const;
131
/**Returns a new URL that is relative to given base. Relative part is taken from
132
current URL object.*/
133
URL relativeTo(KURL base);
135
/**Returns a new relative URL constructed from base and given url.*/
136
static URL relativeURL(KURL base, KURL url);
137
/**Returns a new relative URL constructed from base and given url. url parameter
138
is either relative or full (depends on isUrlRelative value).*/
139
static URL relativeURL(KURL base, QString url, bool isUrlRelative);
141
bool operator == (const URL &url);
142
bool operator != (const URL &url);
148
/**Relative directory name.*/
149
class Directory: public URL{
151
/**Works as URL::URL(KURL, KURL), only implies Name::Directory mode.*/
152
Directory(KURL base, KURL url);
153
/**Works as URL::URL(KURL, QString, bool), only implies Name::Directory mode.*/
154
Directory(KURL base, QString url, bool isRelativeUrl);
156
/**Works as URL::setRURL(QString), only implies Name::Directory mode.*/
157
void setRURL(QString rurl);
160
void setRURL(QString rurl, Type type);
164
/**Relative file name.*/
165
class File: public URL{
167
/**Works as URL::URL(KURL, KURL), only implies Name::File mode.*/
168
File(KURL base, KURL url);
169
/**Works as URL::URL(KURL, KURL), only implies Name::File mode.*/
170
File(KURL base, QString url, bool isRelativeUrl);
172
/**Works as URL::setRURL(QString), only implies Name::File mode.*/
173
void setRURL(QString rurl);
176
void setRURL(QString rurl, Type type);