KURL Class Reference
Represents and parses a URL. More...
#include <kurl.h>
Public Types | |
enum | QueryItemsOptions |
Options for queryItems. More... | |
Public Methods | |
KURL () | |
Constructs an empty URL. | |
~KURL () | |
Destructs the KURL object. | |
KURL (const QString &url, int encoding_hint=0) | |
Usual constructor, to construct from a string. | |
KURL (const char *url, int encoding_hint=0) | |
Constructor taking a char * url , which is an _encoded_ representation of the URL, exactly like the usual constructor. | |
KURL (const QCString &url, int encoding_hint=0) | |
Constructor taking a QCString url , which is an _encoded_ representation of the URL, exactly like the usual constructor. | |
KURL (const KURL &u) | |
Copy constructor. | |
KURL (const QUrl &u) | |
Converts from a QUrl. | |
KURL (const KURL &_baseurl, const QString &_rel_url, int encoding_hint=0) | |
Constructor allowing relative URLs. | |
QString | protocol () const |
Returns the protocol for the URL (i.e., file, http, etc.). | |
void | setProtocol (const QString &_txt) |
Sets the protocol for the URL (i.e., file, http, etc.). | |
QString | user () const |
Returns the decoded user name (login, user id, ...) included in the URL. | |
void | setUser (const QString &_txt) |
Sets the user name (login, user id, ...) included in the URL. | |
bool | hasUser () const |
Test to see if this URL has a user name included in it. | |
QString | pass () const |
Returns the decoded password (corresponding to user()) included in the URL. | |
void | setPass (const QString &_txt) |
Sets the password (corresponding to user()) included in the URL. | |
bool | hasPass () const |
Test to see if this URL has a password included in it. | |
QString | host () const |
Returns the decoded hostname included in the URL. | |
void | setHost (const QString &_txt) |
Sets the hostname included in the URL. | |
bool | hasHost () const |
Test to see if this URL has a hostname included in it. | |
unsigned short int | port () const |
Returns the port number included in the URL. | |
void | setPort (unsigned short int _p) |
Sets the port number included in the URL. | |
QString | path () const |
Returns the current decoded path. | |
QString | path (int _trailing) const |
void | setPath (const QString &path) |
Sets the path of the URL. | |
bool | hasPath () const |
Test to see if this URL has a path is included in it. | |
void | cleanPath (bool cleanDirSeparator=true) |
Resolves "." and ".." components in path. | |
void | adjustPath (int _trailing) |
Add or remove a trailing slash to/from the path. | |
void | setEncodedPathAndQuery (const QString &_txt, int encoding_hint=0) |
This is useful for HTTP. | |
void | setEncodedPath (const QString &_txt, int encoding_hint=0) |
Sets the (already encoded) path. | |
QString | encodedPathAndQuery (int _trailing=0, bool _no_empty_path=false, int encoding_hint=0) const |
Returns the encoded path and the query. | |
void | setQuery (const QString &_txt, int encoding_hint=0) |
QString | query () const |
Returns the query of the URL. | |
QString | ref () const |
The reference is never decoded automatically. | |
void | setRef (const QString &_txt) |
Sets the reference part (everything after '#'). | |
bool | hasRef () const |
Checks whether the URL has a reference part. | |
QString | htmlRef () const |
Returns the HTML reference (the part of the URL after "#"). | |
QString | encodedHtmlRef () const |
Returns the HTML reference (the part of the URL after "#") in encoded form. | |
void | setHTMLRef (const QString &_ref) |
Sets the HTML-style reference. | |
bool | hasHTMLRef () const |
Checks whether there is a HTML reference. | |
bool | isValid () const |
Checks whether the URL is well formed. | |
bool | isMalformed () const |
bool | isLocalFile () const |
Checks whether the file is local. | |
void | setFileEncoding (const QString &encoding) |
Adds encoding information to url by adding a "charset" parameter. | |
QString | fileEncoding () const |
Returns encoding information from url, the content of the "charset" parameter. | |
bool | hasSubURL () const |
Checks whether the URL has any sub URLs. | |
void | addPath (const QString &_txt) |
Adds to the current path. | |
QString | queryItem (const QString &_item) const |
Returns the value of a certain query item. | |
QMap< QString, QString > | queryItems (int options=0) const |
Returns the list of query items as a map mapping keys to values. | |
void | addQueryItem (const QString &_item, const QString &_value, int encoding_hint=0) |
Add an additional query item. | |
void | removeQueryItem (const QString &_item) |
Remove an item from the query. | |
void | setFileName (const QString &_txt) |
Sets the filename of the path. | |
QString | fileName (bool _ignore_trailing_slash_in_path=true) const |
Returns the filename of the path. | |
QString | directory (bool _strip_trailing_slash_from_result=true, bool _ignore_trailing_slash_in_path=true) const |
Returns the directory of the path. | |
bool | cd (const QString &_dir) |
Changes the directory by descending into the given directory. | |
QString | url (int _trailing=0, int encoding_hint=0) const |
Returns the URL as string. | |
QString | prettyURL (int _trailing=0) const |
Returns the URL as string in human-friendly format. | |
QString | htmlURL () const |
Returns the URL as string, escaped for HTML. | |
QString | prettyURL (int _trailing, AdjustementFlags _flags) const |
Returns the URL as string, escaped for HTML. | |
bool | isEmpty () const |
Test to see if the KURL is empty. | |
KURL | upURL () const |
This function is useful to implement the "Up" button in a file manager for example. | |
bool | cmp (const KURL &u, bool ignore_trailing=false) const |
The same as equals(), just with a less obvious name. | |
bool | equals (const KURL &u, bool ignore_trailing=false) const |
Compares this url with u . | |
bool | isParentOf (const KURL &u) const |
Checks whether the given URL is parent of this URL. | |
Static Public Methods | |
List | split (const QString &_url) |
Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in http://www.kde.org and tar:/kde/README.htmlref1. | |
List | split (const KURL &_url) |
Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in http://www.kde.org and tar:/kde/README.htmlref1. | |
KURL | join (const List &_list) |
Reverses split(). | |
KURL | fromPathOrURL (const QString &text) |
Creates a KURL object from a QString representing either an absolute path or a real URL. | |
QString | encode_string (const QString &str, int encoding_hint=0) |
Convenience function. | |
QString | encode_string_no_slash (const QString &str, int encoding_hint=0) |
Convenience function. | |
QString | decode_string (const QString &str, int encoding_hint=0) |
Convenience function. | |
bool | isRelativeURL (const QString &_url) |
Convenience function. |
Detailed Description
Represents and parses a URL.A prototypical URL looks like:
protocol:/user:password@hostname:port/path/to/file.extreference
KURL has some restrictions regarding the path encoding. KURL works internally with the decoded path and and encoded query. For example,
http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20youwould result in a decoded path "/cgi-bin/test me.pl" and in the encoded query "?cmd=Hello%20you". Since path is internally always encoded you may not use "%00" in the path, although this is OK for the query.
- Author:
- Torben Weis <weis@kde.org>
Definition at line 52 of file kurl.h.
Member Enumeration Documentation
|
Options for queryItems. Currently, only one option is defined:
|
Constructor & Destructor Documentation
|
Constructs an empty URL.
Definition at line 373 of file kurl.cpp. Referenced by fromPathOrURL(), join(), KURL::List::List(), split(), and upURL(). |
|
Destructs the KURL object.
|
|
Usual constructor, to construct from a string.
|
|
Constructor taking a char * This is useful when then URL, in its encoded form, is strictly ascii.
Definition at line 389 of file kurl.cpp. References QString::fromLatin1(), and url(). |
|
Constructor taking a QCString This is useful when then URL, in its encoded form, is strictly ascii.
Definition at line 395 of file kurl.cpp. References QString::fromLatin1(). |
|
Copy constructor.
|
|
Converts from a QUrl.
|
|
Constructor allowing relative URLs.
Definition at line 442 of file kurl.cpp. References cleanPath(), QString::find(), QString::findRev(), QString::isEmpty(), QString::isNull(), isRelativeURL(), QString::length(), m_strHost, m_strProtocol, QString::mid(), ref(), QString::remove(), setHTMLRef(), QString::truncate(), and url(). |
Member Function Documentation
|
Returns the protocol for the URL (i.e., file, http, etc.).
|
|
Sets the protocol for the URL (i.e., file, http, etc.).
|
|
Returns the decoded user name (login, user id, ...) included in the URL.
|
|
Sets the user name (login, user id, ...) included in the URL. Special characters in the user name will appear encoded in the URL.
|
|
Test to see if this URL has a user name included in it.
Definition at line 191 of file kurl.h. References QString::isEmpty(). Referenced by prettyURL(), and url(). |
|
Returns the decoded password (corresponding to user()) included in the URL.
|
|
Sets the password (corresponding to user()) included in the URL. Special characters in the password will appear encoded in the URL. Note that a password can only appear in a URL string if you also set a user.
|
|
Test to see if this URL has a password included in it.
Definition at line 213 of file kurl.h. References QString::isEmpty(). Referenced by url(). |
|
Returns the decoded hostname included in the URL.
|
|
Sets the hostname included in the URL. Special characters in the hostname will appear encoded in the URL.
|
|
Test to see if this URL has a hostname included in it.
Definition at line 231 of file kurl.h. References QString::isEmpty(). Referenced by prettyURL(), and url(). |
|
Returns the port number included in the URL.
|
|
Sets the port number included in the URL.
|
|
Returns the current decoded path. This does not include the query.
Definition at line 250 of file kurl.h. Referenced by cd(), encodedPathAndQuery(), equals(), fileName(), KApplication::invokeMailer(), isParentOf(), path(), setFileName(), and upURL(). |
|
Definition at line 1103 of file kurl.cpp. References path(). |
|
Sets the path of the URL. The query is not changed by this function.
Definition at line 1639 of file kurl.cpp. References QString::isEmpty(), and isEmpty(). Referenced by cd(), fromPathOrURL(), KCmdLineArgs::makeURL(), KConfigINIBackEnd::parseConfigFiles(), KDesktopFile::readURL(), setFileName(), and KConfigINIBackEnd::sync(). |
|
Test to see if this URL has a path is included in it.
Definition at line 281 of file kurl.h. References QString::isEmpty(). |
|
Resolves "." and ".." components in path. Some servers seem not to like the removal of extra '/' even though it is against the specification in RFC 2396.
Definition at line 1004 of file kurl.cpp. Referenced by KURL(), KCmdLineArgs::makeURL(), and setFileName(). |
|
Add or remove a trailing slash to/from the path.
Definition at line 1041 of file kurl.cpp. References QString::isEmpty(). |
|
This is useful for HTTP. It looks first for '?' and decodes then. The encoded path is the concatenation of the current path and the query.
Definition at line 1088 of file kurl.cpp. References QString::find(), QString::left(), QString::length(), QString::right(), setEncodedPath(), and setQuery(). |
|
Sets the (already encoded) path.
Definition at line 1072 of file kurl.cpp. References KGlobal::staticQString(). Referenced by setEncodedPathAndQuery(), and setFileName(). |
|
Returns the encoded path and the query.
Definition at line 1051 of file kurl.cpp. References QString::isEmpty(), QString::isNull(), and path(). Referenced by url(). |
|
Definition at line 1649 of file kurl.cpp. References QString::latin1(), QString::length(), and QString::mid(). Referenced by setEncodedPathAndQuery(), setFileEncoding(), and upURL(). |
|
Returns the query of the URL. The query may contain the 0 character. If a query is present it always starts with a '?'. A single '?' means an empty query. An empty string means no query.
Definition at line 1693 of file kurl.cpp. References QString::isNull(). Referenced by fileEncoding(), KApplication::invokeMailer(), setFileEncoding(), and upURL(). |
|
The reference is never decoded automatically.
Definition at line 366 of file kurl.h. Referenced by encodedHtmlRef(), htmlRef(), KURL(), and split(). |
|
Sets the reference part (everything after '#').
|
|
Checks whether the URL has a reference part.
Definition at line 380 of file kurl.h. References QString::isNull(). Referenced by hasHTMLRef(), prettyURL(), and url(). |
|
Returns the HTML reference (the part of the URL after "#").
Definition at line 1560 of file kurl.cpp. References QValueList< KURL >::begin(), hasSubURL(), ref(), and split(). |
|
Returns the HTML reference (the part of the URL after "#") in encoded form.
Definition at line 1571 of file kurl.cpp. References QValueList< KURL >::begin(), hasSubURL(), ref(), and split(). |
|
Sets the HTML-style reference.
Definition at line 1582 of file kurl.cpp. References QValueList< KURL >::begin(), hasSubURL(), join(), and split(). |
|
Checks whether there is a HTML reference.
Definition at line 1597 of file kurl.cpp. References QValueList< KURL >::begin(), hasRef(), hasSubURL(), and split(). |
|
Checks whether the URL is well formed.
Definition at line 419 of file kurl.h. Referenced by isMalformed(). |
|
Definition at line 423 of file kurl.h. References isValid(). Referenced by equals(), and isParentOf(). |
|
Checks whether the file is local.
Definition at line 1108 of file kurl.cpp. References hasSubURL(), QString::isEmpty(), and KGlobal::staticQString(). Referenced by fileEncoding(), and setFileEncoding(). |
|
Adds encoding information to url by adding a "charset" parameter. If there is already a charset parameter, it will be replaced.
Definition at line 1118 of file kurl.cpp. References decode_string(), encode_string(), QString::isEmpty(), isLocalFile(), QStringList::join(), QString::mid(), query(), setQuery(), QStringList::split(), and QString::startsWith(). |
|
Returns encoding information from url, the content of the "charset" parameter.
Definition at line 1147 of file kurl.cpp. References decode_string(), QString::isEmpty(), isLocalFile(), QString::mid(), query(), QStringList::split(), and QString::startsWith(). |
|
Checks whether the URL has any sub URLs. See split() for examples for sub URLs.
Definition at line 1172 of file kurl.cpp. References QString::isEmpty(), and QString::startsWith(). Referenced by cd(), encodedHtmlRef(), hasHTMLRef(), htmlRef(), isLocalFile(), setHTMLRef(), split(), and upURL(). |
|
Adds to the current path.
Assumes that the current path is a directory.
Definition at line 1412 of file kurl.cpp. References QString::isEmpty(), QString::length(), and QString::mid(). |
|
Returns the value of a certain query item.
Definition at line 1800 of file kurl.cpp. References decode_string(), QString::fromLatin1(), QString::length(), QString::replace(), and QStringList::split(). |
|
Returns the list of query items as a map mapping keys to values.
Definition at line 1769 of file kurl.cpp. References decode_string(), QString::fromLatin1(), QMap< QString, QString >::insert(), QString::isEmpty(), QString::lower(), QString::replace(), and QStringList::split(). |
|
Add an additional query item. To replace an existing query item, the item should first be removed with removeQueryItem()
Definition at line 1849 of file kurl.cpp. References QString::isEmpty(). |
|
Remove an item from the query.
Definition at line 1826 of file kurl.cpp. References QStringList::join(), QString::length(), and QStringList::split(). |
|
Sets the filename of the path. In comparison to addPath() this function does not assume that the current path is a directory. This is only assumed if the current path ends with '/'. Any reference is reset.
Definition at line 965 of file kurl.cpp. References cleanPath(), encode_string(), QString::findRev(), QString::isEmpty(), QString::mid(), path(), QString::right(), setEncodedPath(), setPath(), and QString::truncate(). |
|
Returns the filename of the path.
Definition at line 1358 of file kurl.cpp. References QString::contains(), QString::findRev(), QString::isEmpty(), QString::left(), QString::length(), QString::mid(), and path(). |
|
Returns the directory of the path.
Definition at line 1440 of file kurl.cpp. References QString::findRev(), QString::isEmpty(), and QString::left(). Referenced by KConfigINIBackEnd::parseConfigFiles(), and KConfigINIBackEnd::sync(). |
|
Changes the directory by descending into the given directory.
It is assumed the current URL represents a directory. If
Definition at line 1474 of file kurl.cpp. References hasSubURL(), QDir::homeDirPath(), QString::isEmpty(), join(), QValueList< KURL >::last(), QString::length(), path(), QString::right(), setHTMLRef(), setPath(), and split(). Referenced by upURL(). |
|
Returns the URL as string.
Definition at line 1191 of file kurl.cpp. References encodedPathAndQuery(), QString::find(), hasHost(), hasPass(), hasRef(), hasUser(), QString::isEmpty(), and QString::sprintf(). Referenced by fromPathOrURL(), join(), KURL(), KDesktopFile::readURL(), and split(). |
|
Returns the URL as string in human-friendly format. Example: http://localhost:8080/test.cgi?test=hello world&name=fred
Definition at line 1241 of file kurl.cpp. References QString::find(), hasHost(), hasRef(), hasUser(), QString::isEmpty(), QString::isNull(), and QString::sprintf(). Referenced by htmlURL(), and prettyURL(). |
|
Returns the URL as string, escaped for HTML.
Definition at line 1297 of file kurl.cpp. References QStyleSheet::escape(), and prettyURL(). |
|
Returns the URL as string, escaped for HTML. Example: http://localhost:8080/test.cgi?test=hello world&name=fred
Definition at line 1289 of file kurl.cpp. References prettyURL(), QString::remove(), and QString::startsWith(). |
|
Test to see if the KURL is empty.
Definition at line 527 of file kurl.cpp. References QString::isEmpty(). Referenced by setPath(). |
|
This function is useful to implement the "Up" button in a file manager for example. cd() never strips a sub-protocol. That means that if you are in file:/home/x.tgz#gzip:/#tar:/ and hit the up button you expect to see file:/home. The algorithm tries to go up on the right-most URL. If that is not possible it strips the right most URL. It continues stripping URLs.
Definition at line 1526 of file kurl.cpp. References cd(), QValueList< KURL >::count(), QValueList< KURL >::fromLast(), hasSubURL(), QValueList< KURL >::isEmpty(), QString::isEmpty(), join(), KURL(), QValueList< KURL >::last(), path(), query(), QValueList< KURL >::remove(), setQuery(), and split(). |
|
The same as equals(), just with a less obvious name.
Compares this url with
Definition at line 901 of file kurl.cpp. References equals(). |
|
Compares this url with
Definition at line 906 of file kurl.cpp. References isMalformed(), m_iPort, m_strHost, m_strPass, m_strProtocol, m_strQuery_encoded, m_strRef_encoded, m_strUser, and path(). Referenced by cmp(). |
|
Checks whether the given URL is parent of this URL. For instance, ftp://host/dir/ is a parent of ftp://host/dir/subdir/subsubdir/.
Definition at line 933 of file kurl.cpp. References QString::isEmpty(), isMalformed(), QString::length(), m_iPort, m_strHost, m_strPass, m_strProtocol, m_strQuery_encoded, m_strRef_encoded, m_strUser, path(), and QString::startsWith(). |
|
Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in http://www.kde.org and tar:/kde/README.htmlref1. That means in turn that "ref1" is an HTML-style reference and not a new sub URL. Since HTML-style references mark a certain position in a document this reference is appended to every URL. The idea behind this is that browsers, for example, only look at the first URL while the rest is not of interest to them.
Definition at line 1334 of file kurl.cpp. References KURL(). Referenced by cd(), encodedHtmlRef(), hasHTMLRef(), htmlRef(), setHTMLRef(), and upURL(). |
|
Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in http://www.kde.org and tar:/kde/README.htmlref1. That means in turn that "ref1" is an HTML-style reference and not a new sub URL. Since HTML-style references mark a certain position in a document this reference is appended to every URL. The idea behind this is that browsers, for example, only look at the first URL while the rest is not of interest to them.
Definition at line 1302 of file kurl.cpp. References QValueList< KURL >::append(), QValueList< KURL >::begin(), QValueList< KURL >::end(), hasSubURL(), QValueList< KURL >::Iterator(), KURL(), m_strRef_encoded, ref(), and url(). |
|
Reverses split(). Only the first URL may have a reference. This reference is considered to be HTML-like and is appended at the end of the resulting joined URL.
Definition at line 1339 of file kurl.cpp. References QValueList< KURL >::ConstIterator(), QValueList< KURL >::end(), QValueList< KURL >::fromLast(), QValueList< KURL >::isEmpty(), KURL(), m_strRef_encoded, and url(). Referenced by cd(), setHTMLRef(), and upURL(). |
|
Creates a KURL object from a QString representing either an absolute path or a real URL. Use this method instead of QString someDir = ... KURL url = someDir; Otherwise some characters (e.g. the '#') won't be encoded properly.
Definition at line 1860 of file kurl.cpp. References QString::isEmpty(), KURL(), setPath(), and url(). |
|
Convenience function. Convert unicoded string to local encoding and use %-style encoding for all common delimiters / non-ascii characters.
Definition at line 1705 of file kurl.cpp. Referenced by setFileEncoding(), and setFileName(). |
|
Convenience function. Convert unicoded string to local encoding and use %-style encoding for all common delimiters / non-ascii characters as well as the slash '/'.
|
|
Convenience function. Decode %-style encoding and convert from local encoding to unicode. Reverse of encode_string()
Definition at line 1700 of file kurl.cpp. Referenced by fileEncoding(), KApplication::invokeMailer(), queryItem(), queryItems(), and setFileEncoding(). |
|
Convenience function. Returns whether '_url' is likely to be a "relative" URL instead of an "absolute" URL.
Definition at line 321 of file kurl.cpp. References QChar::latin1(), QString::length(), and QString::unicode(). Referenced by KURL(), and KCmdLineArgs::makeURL(). |
The documentation for this class was generated from the following files: