~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/io/qurl.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Copyright (C) 2012 Intel Corporation.
 
5
** Contact: http://www.qt-project.org/legal
 
6
**
 
7
** This file is part of the QtCore module of the Qt Toolkit.
 
8
**
 
9
** $QT_BEGIN_LICENSE:LGPL$
 
10
** Commercial License Usage
 
11
** Licensees holding valid commercial Qt licenses may use this file in
 
12
** accordance with the commercial license agreement provided with the
 
13
** Software or, alternatively, in accordance with the terms contained in
 
14
** a written agreement between you and Digia.  For licensing terms and
 
15
** conditions see http://qt.digia.com/licensing.  For further information
 
16
** use the contact form at http://qt.digia.com/contact-us.
 
17
**
 
18
** GNU Lesser General Public License Usage
 
19
** Alternatively, this file may be used under the terms of the GNU Lesser
 
20
** General Public License version 2.1 as published by the Free Software
 
21
** Foundation and appearing in the file LICENSE.LGPL included in the
 
22
** packaging of this file.  Please review the following information to
 
23
** ensure the GNU Lesser General Public License version 2.1 requirements
 
24
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
25
**
 
26
** In addition, as a special exception, Digia gives you certain additional
 
27
** rights.  These rights are described in the Digia Qt LGPL Exception
 
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
29
**
 
30
** GNU General Public License Usage
 
31
** Alternatively, this file may be used under the terms of the GNU
 
32
** General Public License version 3.0 as published by the Free Software
 
33
** Foundation and appearing in the file LICENSE.GPL included in the
 
34
** packaging of this file.  Please review the following information to
 
35
** ensure the GNU General Public License version 3.0 requirements will be
 
36
** met: http://www.gnu.org/copyleft/gpl.html.
 
37
**
 
38
**
 
39
** $QT_END_LICENSE$
 
40
**
 
41
****************************************************************************/
 
42
 
 
43
#ifndef QURL_H
 
44
#define QURL_H
 
45
 
 
46
#include <QtCore/qbytearray.h>
 
47
#include <QtCore/qobjectdefs.h>
 
48
#include <QtCore/qstring.h>
 
49
#include <QtCore/qlist.h>
 
50
#include <QtCore/qpair.h>
 
51
#include <QtCore/qglobal.h>
 
52
 
 
53
QT_BEGIN_HEADER
 
54
 
 
55
QT_BEGIN_NAMESPACE
 
56
 
 
57
 
 
58
class QUrlQuery;
 
59
class QUrlPrivate;
 
60
class QDataStream;
 
61
 
 
62
template <typename E1, typename E2>
 
63
class QUrlTwoFlags
 
64
{
 
65
    int i;
 
66
    typedef int QUrlTwoFlags:: *Zero;
 
67
public:
 
68
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(E1 f) : i(f) {}
 
69
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(E2 f) : i(f) {}
 
70
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(QFlag f) : i(f) {}
 
71
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(QFlags<E1> f) : i(f.operator int()) {}
 
72
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(QFlags<E2> f) : i(f.operator int()) {}
 
73
    Q_DECL_CONSTEXPR inline QUrlTwoFlags(Zero = 0) : i(0) {}
 
74
 
 
75
    inline QUrlTwoFlags &operator&=(int mask) { i &= mask; return *this; }
 
76
    inline QUrlTwoFlags &operator&=(uint mask) { i &= mask; return *this; }
 
77
    inline QUrlTwoFlags &operator|=(QUrlTwoFlags f) { i |= f.i; return *this; }
 
78
    inline QUrlTwoFlags &operator|=(E1 f) { i |= f; return *this; }
 
79
    inline QUrlTwoFlags &operator|=(E2 f) { i |= f; return *this; }
 
80
    inline QUrlTwoFlags &operator^=(QUrlTwoFlags f) { i ^= f.i; return *this; }
 
81
    inline QUrlTwoFlags &operator^=(E1 f) { i ^= f; return *this; }
 
82
    inline QUrlTwoFlags &operator^=(E2 f) { i ^= f; return *this; }
 
83
 
 
84
    Q_DECL_CONSTEXPR inline operator QFlags<E1>() const { return E1(i); }
 
85
    Q_DECL_CONSTEXPR inline operator QFlags<E2>() const { return E2(i); }
 
86
    Q_DECL_CONSTEXPR inline operator int() const { return i; }
 
87
    Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
 
88
 
 
89
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator|(QUrlTwoFlags f) const
 
90
    { return QUrlTwoFlags(E1(i | f.i)); }
 
91
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator|(E1 f) const
 
92
    { return QUrlTwoFlags(E1(i | f)); }
 
93
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator|(E2 f) const
 
94
    { return QUrlTwoFlags(E2(i | f)); }
 
95
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator^(QUrlTwoFlags f) const
 
96
    { return QUrlTwoFlags(E1(i ^ f.i)); }
 
97
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator^(E1 f) const
 
98
    { return QUrlTwoFlags(E1(i ^ f)); }
 
99
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator^(E2 f) const
 
100
    { return QUrlTwoFlags(E2(i ^ f)); }
 
101
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator&(int mask) const
 
102
    { return QUrlTwoFlags(E1(i & mask)); }
 
103
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator&(uint mask) const
 
104
    { return QUrlTwoFlags(E1(i & mask)); }
 
105
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator&(E1 f) const
 
106
    { return QUrlTwoFlags(E1(i & f)); }
 
107
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator&(E2 f) const
 
108
    { return QUrlTwoFlags(E2(i & f)); }
 
109
    Q_DECL_CONSTEXPR inline QUrlTwoFlags operator~() const
 
110
    { return QUrlTwoFlags(E1(~i)); }
 
111
 
 
112
    inline bool testFlag(E1 f) const { return (i & f) == f && (f != 0 || i == int(f)); }
 
113
    inline bool testFlag(E2 f) const { return (i & f) == f && (f != 0 || i == int(f)); }
 
114
};
 
115
 
 
116
template<typename E1, typename E2>
 
117
class QTypeInfo<QUrlTwoFlags<E1, E2> > : public QTypeInfoMerger<QUrlTwoFlags<E1, E2>, E1, E2> {};
 
118
 
 
119
class Q_CORE_EXPORT QUrl
 
120
{
 
121
public:
 
122
    enum ParsingMode {
 
123
        TolerantMode,
 
124
        StrictMode,
 
125
        DecodedMode
 
126
    };
 
127
 
 
128
    // encoding / toString values
 
129
    enum UrlFormattingOption {
 
130
        None = 0x0,
 
131
        RemoveScheme = 0x1,
 
132
        RemovePassword = 0x2,
 
133
        RemoveUserInfo = RemovePassword | 0x4,
 
134
        RemovePort = 0x8,
 
135
        RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
 
136
        RemovePath = 0x20,
 
137
        RemoveQuery = 0x40,
 
138
        RemoveFragment = 0x80,
 
139
        // 0x100 was a private code in Qt 4, keep unused for a while
 
140
        PreferLocalFile = 0x200,
 
141
        StripTrailingSlash = 0x400
 
142
    };
 
143
 
 
144
    enum ComponentFormattingOption {
 
145
        PrettyDecoded = 0x000000,
 
146
        EncodeSpaces = 0x100000,
 
147
        EncodeUnicode = 0x200000,
 
148
        EncodeDelimiters = 0x400000 | 0x800000,
 
149
        EncodeReserved = 0x1000000,
 
150
        DecodeReserved = 0x2000000,
 
151
        // 0x4000000 used to indicate full-decode mode
 
152
 
 
153
        FullyEncoded = EncodeSpaces | EncodeUnicode | EncodeDelimiters | EncodeReserved,
 
154
        FullyDecoded = FullyEncoded | DecodeReserved | 0x4000000
 
155
    };
 
156
    Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption)
 
157
#ifdef Q_QDOC
 
158
    Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption)
 
159
#else
 
160
    typedef QUrlTwoFlags<UrlFormattingOption, ComponentFormattingOption> FormattingOptions;
 
161
#endif
 
162
 
 
163
    QUrl();
 
164
    QUrl(const QUrl &copy);
 
165
    QUrl &operator =(const QUrl &copy);
 
166
#ifdef QT_NO_URL_CAST_FROM_STRING
 
167
    explicit QUrl(const QString &url, ParsingMode mode = TolerantMode);
 
168
#else
 
169
    QUrl(const QString &url, ParsingMode mode = TolerantMode);
 
170
    QUrl &operator=(const QString &url);
 
171
#endif
 
172
#ifdef Q_COMPILER_RVALUE_REFS
 
173
    QUrl(QUrl &&other) : d(0)
 
174
    { qSwap(d, other.d); }
 
175
    inline QUrl &operator=(QUrl &&other)
 
176
    { qSwap(d, other.d); return *this; }
 
177
#endif
 
178
    ~QUrl();
 
179
 
 
180
    inline void swap(QUrl &other) { qSwap(d, other.d); }
 
181
 
 
182
    void setUrl(const QString &url, ParsingMode mode = TolerantMode);
 
183
    QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
 
184
    QString toString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
 
185
    QString toDisplayString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
 
186
 
 
187
    QByteArray toEncoded(FormattingOptions options = FullyEncoded) const;
 
188
    static QUrl fromEncoded(const QByteArray &url, ParsingMode mode = TolerantMode);
 
189
 
 
190
    static QUrl fromUserInput(const QString &userInput);
 
191
 
 
192
    bool isValid() const;
 
193
    QString errorString() const;
 
194
 
 
195
    bool isEmpty() const;
 
196
    void clear();
 
197
 
 
198
    void setScheme(const QString &scheme);
 
199
    QString scheme() const;
 
200
 
 
201
    void setAuthority(const QString &authority, ParsingMode mode = TolerantMode);
 
202
    QString authority(ComponentFormattingOptions options = PrettyDecoded) const;
 
203
 
 
204
    void setUserInfo(const QString &userInfo, ParsingMode mode = TolerantMode);
 
205
    QString userInfo(ComponentFormattingOptions options = PrettyDecoded) const;
 
206
 
 
207
    void setUserName(const QString &userName, ParsingMode mode = TolerantMode);
 
208
    QString userName(ComponentFormattingOptions options = PrettyDecoded) const;
 
209
 
 
210
    void setPassword(const QString &password, ParsingMode mode = TolerantMode);
 
211
    QString password(ComponentFormattingOptions = PrettyDecoded) const;
 
212
 
 
213
    void setHost(const QString &host, ParsingMode mode = TolerantMode);
 
214
    QString host(ComponentFormattingOptions = PrettyDecoded) const;
 
215
    QString topLevelDomain(ComponentFormattingOptions options = PrettyDecoded) const;
 
216
 
 
217
    void setPort(int port);
 
218
    int port(int defaultPort = -1) const;
 
219
 
 
220
    void setPath(const QString &path, ParsingMode mode = TolerantMode);
 
221
    QString path(ComponentFormattingOptions options = PrettyDecoded) const;
 
222
 
 
223
    bool hasQuery() const;
 
224
    void setQuery(const QString &query, ParsingMode mode = TolerantMode);
 
225
    void setQuery(const QUrlQuery &query);
 
226
    QString query(ComponentFormattingOptions = PrettyDecoded) const;
 
227
 
 
228
    bool hasFragment() const;
 
229
    QString fragment(ComponentFormattingOptions options = PrettyDecoded) const;
 
230
    void setFragment(const QString &fragment, ParsingMode mode = TolerantMode);
 
231
 
 
232
    QUrl resolved(const QUrl &relative) const;
 
233
 
 
234
    bool isRelative() const;
 
235
    bool isParentOf(const QUrl &url) const;
 
236
 
 
237
    bool isLocalFile() const;
 
238
    static QUrl fromLocalFile(const QString &localfile);
 
239
    QString toLocalFile() const;
 
240
 
 
241
    void detach();
 
242
    bool isDetached() const;
 
243
 
 
244
    bool operator <(const QUrl &url) const;
 
245
    bool operator ==(const QUrl &url) const;
 
246
    bool operator !=(const QUrl &url) const;
 
247
 
 
248
    static QString fromPercentEncoding(const QByteArray &);
 
249
    static QByteArray toPercentEncoding(const QString &,
 
250
                                        const QByteArray &exclude = QByteArray(),
 
251
                                        const QByteArray &include = QByteArray());
 
252
#if QT_DEPRECATED_SINCE(5,0)
 
253
    QT_DEPRECATED static QString fromPunycode(const QByteArray &punycode)
 
254
    { return fromAce(punycode); }
 
255
    QT_DEPRECATED static QByteArray toPunycode(const QString &string)
 
256
    { return toAce(string); }
 
257
 
 
258
    QT_DEPRECATED inline void setQueryItems(const QList<QPair<QString, QString> > &qry);
 
259
    QT_DEPRECATED inline void addQueryItem(const QString &key, const QString &value);
 
260
    QT_DEPRECATED inline QList<QPair<QString, QString> > queryItems() const;
 
261
    QT_DEPRECATED inline bool hasQueryItem(const QString &key) const;
 
262
    QT_DEPRECATED inline QString queryItemValue(const QString &key) const;
 
263
    QT_DEPRECATED inline QStringList allQueryItemValues(const QString &key) const;
 
264
    QT_DEPRECATED inline void removeQueryItem(const QString &key);
 
265
    QT_DEPRECATED inline void removeAllQueryItems(const QString &key);
 
266
 
 
267
    QT_DEPRECATED inline void setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &query);
 
268
    QT_DEPRECATED inline void addEncodedQueryItem(const QByteArray &key, const QByteArray &value);
 
269
    QT_DEPRECATED inline QList<QPair<QByteArray, QByteArray> > encodedQueryItems() const;
 
270
    QT_DEPRECATED inline bool hasEncodedQueryItem(const QByteArray &key) const;
 
271
    QT_DEPRECATED inline QByteArray encodedQueryItemValue(const QByteArray &key) const;
 
272
    QT_DEPRECATED inline QList<QByteArray> allEncodedQueryItemValues(const QByteArray &key) const;
 
273
    QT_DEPRECATED inline void removeEncodedQueryItem(const QByteArray &key);
 
274
    QT_DEPRECATED inline void removeAllEncodedQueryItems(const QByteArray &key);
 
275
 
 
276
    QT_DEPRECATED void setEncodedUrl(const QByteArray &u, ParsingMode mode = TolerantMode)
 
277
    { setUrl(fromEncodedComponent_helper(u), mode); }
 
278
 
 
279
    QT_DEPRECATED QByteArray encodedUserName() const
 
280
    { return userName(FullyEncoded).toLatin1(); }
 
281
    QT_DEPRECATED void setEncodedUserName(const QByteArray &value)
 
282
    { setUserName(fromEncodedComponent_helper(value)); }
 
283
 
 
284
    QT_DEPRECATED QByteArray encodedPassword() const
 
285
    { return password(FullyEncoded).toLatin1(); }
 
286
    QT_DEPRECATED void setEncodedPassword(const QByteArray &value)
 
287
    { setPassword(fromEncodedComponent_helper(value)); }
 
288
 
 
289
    QT_DEPRECATED QByteArray encodedHost() const
 
290
    { return host(FullyEncoded).toLatin1(); }
 
291
    QT_DEPRECATED void setEncodedHost(const QByteArray &value)
 
292
    { setHost(fromEncodedComponent_helper(value)); }
 
293
 
 
294
    QT_DEPRECATED QByteArray encodedPath() const
 
295
    { return path(FullyEncoded).toLatin1(); }
 
296
    QT_DEPRECATED void setEncodedPath(const QByteArray &value)
 
297
    { setPath(fromEncodedComponent_helper(value)); }
 
298
 
 
299
    QT_DEPRECATED QByteArray encodedQuery() const
 
300
    { return toLatin1_helper(query(FullyEncoded)); }
 
301
    QT_DEPRECATED void setEncodedQuery(const QByteArray &value)
 
302
    { setQuery(fromEncodedComponent_helper(value)); }
 
303
 
 
304
    QT_DEPRECATED QByteArray encodedFragment() const
 
305
    { return toLatin1_helper(fragment(FullyEncoded)); }
 
306
    QT_DEPRECATED void setEncodedFragment(const QByteArray &value)
 
307
    { setFragment(fromEncodedComponent_helper(value)); }
 
308
 
 
309
private:
 
310
    // helper function for the encodedQuery and encodedFragment functions
 
311
    static QByteArray toLatin1_helper(const QString &string)
 
312
    {
 
313
        if (string.isEmpty())
 
314
            return string.isNull() ? QByteArray() : QByteArray("");
 
315
        return string.toLatin1();
 
316
    }
 
317
#endif
 
318
private:
 
319
    static QString fromEncodedComponent_helper(const QByteArray &ba);
 
320
 
 
321
public:
 
322
    static QString fromAce(const QByteArray &);
 
323
    static QByteArray toAce(const QString &);
 
324
    static QStringList idnWhitelist();
 
325
    static void setIdnWhitelist(const QStringList &);
 
326
    friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) Q_DECL_NOTHROW;
 
327
 
 
328
private:
 
329
    QUrlPrivate *d;
 
330
    friend class QUrlQuery;
 
331
 
 
332
public:
 
333
    typedef QUrlPrivate * DataPtr;
 
334
    inline DataPtr &data_ptr() { return d; }
 
335
};
 
336
 
 
337
Q_DECLARE_SHARED(QUrl)
 
338
Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::ComponentFormattingOptions)
 
339
//Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions)
 
340
 
 
341
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption f1, QUrl::UrlFormattingOption f2)
 
342
{ return QUrl::FormattingOptions(f1) | f2; }
 
343
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption f1, QUrl::FormattingOptions f2)
 
344
{ return f2 | f1; }
 
345
Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(QUrl::UrlFormattingOption f1, int f2)
 
346
{ return QIncompatibleFlag(int(f1) | f2); }
 
347
 
 
348
// add operators for OR'ing the two types of flags
 
349
inline QUrl::FormattingOptions &operator|=(QUrl::FormattingOptions &i, QUrl::ComponentFormattingOptions f)
 
350
{ i |= QUrl::UrlFormattingOption(int(f)); return i; }
 
351
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption i, QUrl::ComponentFormattingOption f)
 
352
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
353
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::UrlFormattingOption i, QUrl::ComponentFormattingOptions f)
 
354
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
355
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOption f, QUrl::UrlFormattingOption i)
 
356
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
357
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOptions f, QUrl::UrlFormattingOption i)
 
358
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
359
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::FormattingOptions i, QUrl::ComponentFormattingOptions f)
 
360
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
361
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOption f, QUrl::FormattingOptions i)
 
362
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
363
Q_DECL_CONSTEXPR inline QUrl::FormattingOptions operator|(QUrl::ComponentFormattingOptions f, QUrl::FormattingOptions i)
 
364
{ return i | QUrl::UrlFormattingOption(int(f)); }
 
365
 
 
366
//inline QUrl::UrlFormattingOption &operator=(const QUrl::UrlFormattingOption &i, QUrl::ComponentFormattingOptions f)
 
367
//{ i = int(f); f; }
 
368
 
 
369
#ifndef QT_NO_DATASTREAM
 
370
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUrl &);
 
371
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUrl &);
 
372
#endif
 
373
 
 
374
#ifndef QT_NO_DEBUG_STREAM
 
375
Q_CORE_EXPORT QDebug operator<<(QDebug, const QUrl &);
 
376
#endif
 
377
 
 
378
QT_END_NAMESPACE
 
379
 
 
380
#if QT_DEPRECATED_SINCE(5,0)
 
381
# include <QtCore/qurlquery.h>
 
382
#endif
 
383
 
 
384
QT_END_HEADER
 
385
 
 
386
#endif // QURL_H