|
|
A class for URL processing.
The KURL class deals with uniform resource locators in a protocol independent way. It works on file:-type URLs much like QDir does on normal directories; but KURL extends the directory operations to work on general URLs. In fact, the part of KURL that only deals with syntax doesn't care about the protocol at all, so feel free to use it to format any URL-like string.
NOTE: KURL doesn't support URL's that don't look like files (for example mailto:someone@somewhere). [If URL's like this were OK, there would be no reason for isMalformed() since any string with a ":" would be a valid URL. Comments please.]
First version by Torben Weis, redesigned by Steffen Hansen (stefh@mip.ou.dk), maintained by Torben Weis (weis@kde.org). Endcoding/Decoding done by Stephan Kulow (coolo@kde.org).
|
Construct a KURL object.
|
Construct a KURL object from _url.
A KURL object is always constructed, but if you plan to use it, you should check it with isMalformed().
if the parameter is an absolute filename, it adds a file: prefix and encodes the path.
|
Construct a KURL object from its components.
|
Constructs a URL.
The second argument may be a relative URL, like '/home/weis/test.txt'. If for example the first parameter is 'http://uni-frankfurt/pub/incoming' then the result will be 'http://uni-frankfurt/home/weis/test.txt'.
Of course the second argument may be a complete URL, too.
bool |
[const]
Returns true if the URL is not a valid URL. This is only syntax-checking; whether the resource to which the URL points exists is not checked.
NOTE: Syntax checking is only done when constructing a KURL from a string.
void |
[static]
Escapes some reserved characters within URLs (e.g. '#', '%').
Some characters in filenames or directory names make troubles For example '#' or '%' makes problem, if they are interpreted and not ment to be interpreted. This why we must encode them. This functions encodes the given URL and returns a reference to the result for convidence.
void |
[static]
Decodes escaped characters within URLs.
This function looks for '%' within the URL and replaces this character with hexcode of the next two characters. If the next characters are not hex chararcters, 0 will be used and the character will be skipped.
QString |
[const]
Returns the URL as a QString.
const char* |
[const]
The function returns the protocolname up to, but not including the ":".
const char* |
[const]
This function returns the host. If there is no host (i.e. the URL refers to a local file) this function returns "".
const char* |
[const]
This function returns the path-part of the URL.
For example, path() on "tar://ftp.foo.org/bar/stuff.tar.gz#tex/doc.tex" returns "/bar/stuff.tar.gz".
const char* |
[const]
This function returns the path-part of an URL and leaves it as is.
For example, path() on "http://www.foo.org/bar/cgi%2Dbin?value=blue%3f" returns "/bar/cgi%2Dbin".
bool |
[const]
If we parse for example ftp://weis@localhost then we dont have a path. The URL means: enter the home directory of user weis, while ftp://weis@localhost/ means, login as user weis and enter the root directory. KURL returns "/" as path in both cases. This function lets you distinguish both URLs. It returns true in the first case.
const char* |
[const]
The search-part.
Returns: the search-part, or NULL if no search-part was specified.
const char* |
[const]
This function returns the reference.
If the URL is "http://www.nowhere/path/file.html#toc", this function will return "toc". If there is no reference it returns "". If we have some subprotocol in the URL like in file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section then only the last reference is going to be returned, in this case "section". A URL like file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html would return "" since there is no reference. The stuff behind the '#' is a subprotocol!
const char* |
[const]
This function returns the user name or an empty string if no user has been specified.
const char* |
[const]
The password.
Returns: the password, or an empty string if no password was specified.
unsigned int |
[const]
The port number.
Returns: the port number, or 0 if none was specified.
const char * |
Returns the directory only.
If for example the URL is "file:/tmp/weis/file.html", then this call will return "/tmp/weis/". If you pass "file:/tmp/weis/" to this function, you will get "/tmp/weis/", because you already passed a directory. Turning the '_trailing' flag off, causes the trailing '/' to be ignored. "file:/tmp/weis/file.html" will result in "/tmp/weis/", too, but "file:/tmp/weis/" will lead to "/tmp/". As you see, this is a smart method to get the parent directory of a file/directory.
This function is supplied for convenience only.
const char * |
Returns the URL with the directory only.
If for example the URL is "file:/tmp/weis/file.html", then this call will return "file:/tmp/weis/". For more details look at 'directory(...)'
bool |
Returns: TRUE if the URL has a sub protocol. For example file:/tmp/kde.tgz#tar:/kfm/main.cpp is a URL with subprotocol. Use this function to check wether some URL really references a complete file on your local hard disk and not some special data inside the file, like the example shows.
QString |
If the URL has no subprotocol, parentURL behaves like a call to url. Otherwise the part of the URL left to the last subprotocol is returned. For example file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section will return file:/tmp/kde.tgz#tar:/kfm.rpm. As you can see, the last subprotocol is stripped. If the original URL is for example file:/httpd/index.html#section then exact this string is going to be returned.
QString |
This call returnes the other part of the URL, the part that is stripped by parentURL. It returns always the right most subprotocol. If there is no subprotocol, the call to this function returns an empty string. For example a URL file:/tmp/kde.tgz#tar:/kfm.rpm#rpm:/doc/index.html#section would return rpm:/doc/index.html#section.
QString |
This function behaves like childURL, but if there is no subprotocol, this function returns the same url returns instead of an empty string.
void |
Parse a string.
void |
Sets the protocol to newProto. Useful for example if an app hits "file:/tmp/interesting.zip", then it might do setProtocol( "zip").
void |
Sets the path to newPath.
void |
Sets the host
void |
Set the password.
void |
Set the user.
void |
Set the port.
void |
Set the search-part.
The search part of an URL is the part behind the '?'. Example the URL "http://www.yahoo.com/search.cgi?country=netherland" has "country=netherland" as search-part
If NULL is specified, the search-part is cleared.
bool |
Set reference.
A reference may be removed with setRef( ""). The function returns false if it could not make a reference (if there were no path to reference from) and true on succes.
bool |
Changes directory by descending into the given directory. If dir starts with a "/" the current URL will be "protocol://host/dir" otherwise dir will be appended to the path. If 'zapRef' is true, the reference will be deleted.
bool |
Go to parent dir. If zapRef is true, the reference is removed, otherwise it stays, but normally no one would want that.
const char * |
Returns the filename or directory name of the URL.
If 'file:/home/weis/test.txt' is the URL, the result will be 'test.txt' If the URL us 'tar:/home/weis/test.tgz#foo/myfile' and isReference is TRUE, the function will return 'myfile'
KURL & |
Makes a copy of a URL.
KURL & |
Initialize the URL with the given string. '_url' must be a valid URL.
bool |
[const]
Compare URL's.
Returns: true if the URLs are equal, false otherwise.
bool |
Checks, if the URL refers to a usual file, that can be openend with usual methods.
Note: It doesn't check, if the file exist
Returns: true, if the URL is a file, that can be opened
bool |
[protected]
If we parse for example ftp://weis@localhost then we dont have a path. The URL means: enter the home directory of user weis, while ftp://weis@localhost/ means, login as user weis and enter the root directory. KURL returns "/" as path in both cases. This variable is used to distinguish both URLs. It is true in the first case.