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