| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtCore module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QURL_H
|
|---|
| 43 | #define QURL_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qbytearray.h>
|
|---|
| 46 | #include <QtCore/qobjectdefs.h>
|
|---|
| 47 | #include <QtCore/qpair.h>
|
|---|
| 48 | #include <QtCore/qstring.h>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_HEADER
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_NAMESPACE
|
|---|
| 53 |
|
|---|
| 54 | QT_MODULE(Core)
|
|---|
| 55 |
|
|---|
| 56 | class QUrlPrivate;
|
|---|
| 57 | class QDataStream;
|
|---|
| 58 |
|
|---|
| 59 | class Q_CORE_EXPORT QUrl
|
|---|
| 60 | {
|
|---|
| 61 | public:
|
|---|
| 62 | enum ParsingMode {
|
|---|
| 63 | TolerantMode,
|
|---|
| 64 | StrictMode
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | // encoding / toString values
|
|---|
| 68 | enum FormattingOption {
|
|---|
| 69 | None = 0x0,
|
|---|
| 70 | RemoveScheme = 0x1,
|
|---|
| 71 | RemovePassword = 0x2,
|
|---|
| 72 | RemoveUserInfo = RemovePassword | 0x4,
|
|---|
| 73 | RemovePort = 0x8,
|
|---|
| 74 | RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
|
|---|
| 75 | RemovePath = 0x20,
|
|---|
| 76 | RemoveQuery = 0x40,
|
|---|
| 77 | RemoveFragment = 0x80,
|
|---|
| 78 |
|
|---|
| 79 | StripTrailingSlash = 0x10000
|
|---|
| 80 | };
|
|---|
| 81 | Q_DECLARE_FLAGS(FormattingOptions, FormattingOption)
|
|---|
| 82 |
|
|---|
| 83 | QUrl();
|
|---|
| 84 | QUrl(const QString &url);
|
|---|
| 85 | QUrl(const QString &url, ParsingMode mode);
|
|---|
| 86 | // ### Qt 5: merge the two constructors, with mode = TolerantMode
|
|---|
| 87 | QUrl(const QUrl ©);
|
|---|
| 88 | QUrl &operator =(const QUrl ©);
|
|---|
| 89 | QUrl &operator =(const QString &url);
|
|---|
| 90 | ~QUrl();
|
|---|
| 91 |
|
|---|
| 92 | void setUrl(const QString &url);
|
|---|
| 93 | void setUrl(const QString &url, ParsingMode mode);
|
|---|
| 94 | // ### Qt 5: merge the two setUrl() functions, with mode = TolerantMode
|
|---|
| 95 | void setEncodedUrl(const QByteArray &url);
|
|---|
| 96 | void setEncodedUrl(const QByteArray &url, ParsingMode mode);
|
|---|
| 97 | // ### Qt 5: merge the two setEncodedUrl() functions, with mode = TolerantMode
|
|---|
| 98 |
|
|---|
| 99 | bool isValid() const;
|
|---|
| 100 |
|
|---|
| 101 | bool isEmpty() const;
|
|---|
| 102 |
|
|---|
| 103 | void clear();
|
|---|
| 104 |
|
|---|
| 105 | void setScheme(const QString &scheme);
|
|---|
| 106 | QString scheme() const;
|
|---|
| 107 |
|
|---|
| 108 | void setAuthority(const QString &authority);
|
|---|
| 109 | QString authority() const;
|
|---|
| 110 |
|
|---|
| 111 | void setUserInfo(const QString &userInfo);
|
|---|
| 112 | QString userInfo() const;
|
|---|
| 113 |
|
|---|
| 114 | void setUserName(const QString &userName);
|
|---|
| 115 | QString userName() const;
|
|---|
| 116 | void setEncodedUserName(const QByteArray &userName);
|
|---|
| 117 | QByteArray encodedUserName() const;
|
|---|
| 118 |
|
|---|
| 119 | void setPassword(const QString &password);
|
|---|
| 120 | QString password() const;
|
|---|
| 121 | void setEncodedPassword(const QByteArray &password);
|
|---|
| 122 | QByteArray encodedPassword() const;
|
|---|
| 123 |
|
|---|
| 124 | void setHost(const QString &host);
|
|---|
| 125 | QString host() const;
|
|---|
| 126 | void setEncodedHost(const QByteArray &host);
|
|---|
| 127 | QByteArray encodedHost() const;
|
|---|
| 128 |
|
|---|
| 129 | void setPort(int port);
|
|---|
| 130 | int port() const;
|
|---|
| 131 | int port(int defaultPort) const;
|
|---|
| 132 | // ### Qt 5: merge the two port() functions, with defaultPort = -1
|
|---|
| 133 |
|
|---|
| 134 | void setPath(const QString &path);
|
|---|
| 135 | QString path() const;
|
|---|
| 136 | void setEncodedPath(const QByteArray &path);
|
|---|
| 137 | QByteArray encodedPath() const;
|
|---|
| 138 |
|
|---|
| 139 | bool hasQuery() const;
|
|---|
| 140 |
|
|---|
| 141 | void setEncodedQuery(const QByteArray &query);
|
|---|
| 142 | QByteArray encodedQuery() const;
|
|---|
| 143 |
|
|---|
| 144 | void setQueryDelimiters(char valueDelimiter, char pairDelimiter);
|
|---|
| 145 | char queryValueDelimiter() const;
|
|---|
| 146 | char queryPairDelimiter() const;
|
|---|
| 147 |
|
|---|
| 148 | void setQueryItems(const QList<QPair<QString, QString> > &query);
|
|---|
| 149 | void addQueryItem(const QString &key, const QString &value);
|
|---|
| 150 | QList<QPair<QString, QString> > queryItems() const;
|
|---|
| 151 | bool hasQueryItem(const QString &key) const;
|
|---|
| 152 | QString queryItemValue(const QString &key) const;
|
|---|
| 153 | QStringList allQueryItemValues(const QString &key) const;
|
|---|
| 154 | void removeQueryItem(const QString &key);
|
|---|
| 155 | void removeAllQueryItems(const QString &key);
|
|---|
| 156 |
|
|---|
| 157 | void setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &query);
|
|---|
| 158 | void addEncodedQueryItem(const QByteArray &key, const QByteArray &value);
|
|---|
| 159 | QList<QPair<QByteArray, QByteArray> > encodedQueryItems() const;
|
|---|
| 160 | bool hasEncodedQueryItem(const QByteArray &key) const;
|
|---|
| 161 | QByteArray encodedQueryItemValue(const QByteArray &key) const;
|
|---|
| 162 | QList<QByteArray> allEncodedQueryItemValues(const QByteArray &key) const;
|
|---|
| 163 | void removeEncodedQueryItem(const QByteArray &key);
|
|---|
| 164 | void removeAllEncodedQueryItems(const QByteArray &key);
|
|---|
| 165 |
|
|---|
| 166 | void setFragment(const QString &fragment);
|
|---|
| 167 | QString fragment() const;
|
|---|
| 168 | void setEncodedFragment(const QByteArray &fragment);
|
|---|
| 169 | QByteArray encodedFragment() const;
|
|---|
| 170 | bool hasFragment() const;
|
|---|
| 171 |
|
|---|
| 172 | QUrl resolved(const QUrl &relative) const;
|
|---|
| 173 |
|
|---|
| 174 | bool isRelative() const;
|
|---|
| 175 | bool isParentOf(const QUrl &url) const;
|
|---|
| 176 |
|
|---|
| 177 | static QUrl fromLocalFile(const QString &localfile);
|
|---|
| 178 | QString toLocalFile() const;
|
|---|
| 179 |
|
|---|
| 180 | QString toString(FormattingOptions options = None) const;
|
|---|
| 181 |
|
|---|
| 182 | QByteArray toEncoded(FormattingOptions options = None) const;
|
|---|
| 183 | static QUrl fromEncoded(const QByteArray &url);
|
|---|
| 184 | static QUrl fromEncoded(const QByteArray &url, ParsingMode mode);
|
|---|
| 185 | // ### Qt 5: merge the two fromEncoded() functions, with mode = TolerantMode
|
|---|
| 186 |
|
|---|
| 187 | void detach();
|
|---|
| 188 | bool isDetached() const;
|
|---|
| 189 |
|
|---|
| 190 | bool operator <(const QUrl &url) const;
|
|---|
| 191 | bool operator ==(const QUrl &url) const;
|
|---|
| 192 | bool operator !=(const QUrl &url) const;
|
|---|
| 193 |
|
|---|
| 194 | static QString fromPercentEncoding(const QByteArray &);
|
|---|
| 195 | static QByteArray toPercentEncoding(const QString &,
|
|---|
| 196 | const QByteArray &exclude = QByteArray(),
|
|---|
| 197 | const QByteArray &include = QByteArray());
|
|---|
| 198 | static QString fromPunycode(const QByteArray &);
|
|---|
| 199 | static QByteArray toPunycode(const QString &);
|
|---|
| 200 | static QString fromAce(const QByteArray &);
|
|---|
| 201 | static QByteArray toAce(const QString &);
|
|---|
| 202 | static QStringList idnWhitelist();
|
|---|
| 203 | static void setIdnWhitelist(const QStringList &);
|
|---|
| 204 |
|
|---|
| 205 | #if defined QT3_SUPPORT
|
|---|
| 206 | inline QT3_SUPPORT QString protocol() const { return scheme(); }
|
|---|
| 207 | inline QT3_SUPPORT void setProtocol(const QString &s) { setScheme(s); }
|
|---|
| 208 | inline QT3_SUPPORT void setUser(const QString &s) { setUserName(s); }
|
|---|
| 209 | inline QT3_SUPPORT QString user() const { return userName(); }
|
|---|
| 210 | inline QT3_SUPPORT bool hasUser() const { return !userName().isEmpty(); }
|
|---|
| 211 | inline QT3_SUPPORT bool hasPassword() const { return !password().isEmpty(); }
|
|---|
| 212 | inline QT3_SUPPORT bool hasHost() const { return !host().isEmpty(); }
|
|---|
| 213 | inline QT3_SUPPORT bool hasPort() const { return port() != -1; }
|
|---|
| 214 | inline QT3_SUPPORT bool hasPath() const { return !path().isEmpty(); }
|
|---|
| 215 | inline QT3_SUPPORT void setQuery(const QString &txt)
|
|---|
| 216 | {
|
|---|
| 217 | setEncodedQuery(txt.toLatin1());
|
|---|
| 218 | }
|
|---|
| 219 | inline QT3_SUPPORT QString query() const
|
|---|
| 220 | {
|
|---|
| 221 | return QString::fromLatin1(encodedQuery().constData());
|
|---|
| 222 | }
|
|---|
| 223 | inline QT3_SUPPORT QString ref() const { return fragment(); }
|
|---|
| 224 | inline QT3_SUPPORT void setRef(const QString &txt) { setFragment(txt); }
|
|---|
| 225 | inline QT3_SUPPORT bool hasRef() const { return !fragment().isEmpty(); }
|
|---|
| 226 | inline QT3_SUPPORT void addPath(const QString &p) { setPath(path() + QLatin1String("/") + p); }
|
|---|
| 227 | QT3_SUPPORT void setFileName(const QString &txt);
|
|---|
| 228 | QT3_SUPPORT QString fileName() const;
|
|---|
| 229 | QT3_SUPPORT QString dirPath() const;
|
|---|
| 230 | static inline QT3_SUPPORT void decode(QString &url)
|
|---|
| 231 | {
|
|---|
| 232 | url = QUrl::fromPercentEncoding(url.toLatin1());
|
|---|
| 233 | }
|
|---|
| 234 | static inline QT3_SUPPORT void encode(QString &url)
|
|---|
| 235 | {
|
|---|
| 236 | url = QString::fromLatin1(QUrl::toPercentEncoding(url).constData());
|
|---|
| 237 | }
|
|---|
| 238 | inline QT3_SUPPORT operator QString() const { return toString(); }
|
|---|
| 239 | inline QT3_SUPPORT bool cdUp()
|
|---|
| 240 | {
|
|---|
| 241 | *this = resolved(QUrl(QLatin1String("..")));
|
|---|
| 242 | return true;
|
|---|
| 243 | }
|
|---|
| 244 | static inline QT3_SUPPORT bool isRelativeUrl(const QString &url)
|
|---|
| 245 | {
|
|---|
| 246 | return QUrl(url).isRelative();
|
|---|
| 247 | }
|
|---|
| 248 | #endif
|
|---|
| 249 |
|
|---|
| 250 | QString errorString() const;
|
|---|
| 251 |
|
|---|
| 252 | protected:
|
|---|
| 253 | #if defined (QT3_SUPPORT)
|
|---|
| 254 | inline QT3_SUPPORT void reset() { clear(); }
|
|---|
| 255 | #endif
|
|---|
| 256 |
|
|---|
| 257 | private:
|
|---|
| 258 | QUrlPrivate *d;
|
|---|
| 259 | public:
|
|---|
| 260 | typedef QUrlPrivate * DataPtr;
|
|---|
| 261 | inline DataPtr &data_ptr() { return d; }
|
|---|
| 262 | };
|
|---|
| 263 |
|
|---|
| 264 | Q_DECLARE_TYPEINFO(QUrl, Q_MOVABLE_TYPE);
|
|---|
| 265 | Q_DECLARE_SHARED(QUrl)
|
|---|
| 266 | Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions)
|
|---|
| 267 |
|
|---|
| 268 | #ifndef QT_NO_DATASTREAM
|
|---|
| 269 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUrl &);
|
|---|
| 270 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUrl &);
|
|---|
| 271 | #endif
|
|---|
| 272 |
|
|---|
| 273 | #ifndef QT_NO_DEBUG_STREAM
|
|---|
| 274 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QUrl &);
|
|---|
| 275 | #endif
|
|---|
| 276 |
|
|---|
| 277 | QT_END_NAMESPACE
|
|---|
| 278 |
|
|---|
| 279 | QT_END_HEADER
|
|---|
| 280 |
|
|---|
| 281 | #endif // QURL_H
|
|---|