1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include <QtCore/qobjectdefs.h>
33
#include <QtCore/qpair.h>
34
#include <QtCore/qstring.h>
40
class Q_CORE_EXPORT QUrl
44
QUrl(const QString &url);
45
QUrl(const QUrl ©);
48
// encoding / toString values
49
enum FormattingOption {
53
RemoveUserInfo = RemovePassword | 0x4,
55
RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
58
RemoveFragment = 0x80,
60
StripTrailingSlash = 0x10000
62
Q_DECLARE_FLAGS(FormattingOptions, FormattingOption)
64
void setUrl(const QString &url);
65
void setEncodedUrl(const QByteArray &url);
73
void setScheme(const QString &scheme);
74
QString scheme() const;
76
void setAuthority(const QString &authority);
77
QString authority() const;
79
void setUserInfo(const QString &userInfo);
80
QString userInfo() const;
82
void setUserName(const QString &userName);
83
QString userName() const;
85
void setPassword(const QString &password);
86
QString password() const;
88
void setHost(const QString &host);
91
void setPort(int port);
94
void setPath(const QString &path);
97
void setEncodedQuery(const QByteArray &query);
98
QByteArray encodedQuery() const;
100
void setQueryDelimiters(char valueDelimiter, char pairDelimiter);
101
char queryValueDelimiter() const;
102
char queryPairDelimiter() const;
104
void setQueryItems(const QList<QPair<QString, QString> > &query);
105
void addQueryItem(const QString &key, const QString &value);
106
QList<QPair<QString, QString> > queryItems() const;
107
bool hasQueryItem(const QString &key) const;
108
QString queryItemValue(const QString &key) const;
109
QStringList allQueryItemValues(const QString &key) const;
110
void removeQueryItem(const QString &key);
111
void removeAllQueryItems(const QString &key);
114
void setFragment(const QString &fragment);
115
QString fragment() const;
117
QUrl resolved(const QUrl &relative) const;
119
bool isRelative() const;
120
bool isParentOf(const QUrl &url) const;
122
static QUrl fromLocalFile(const QString &localfile);
123
QString toLocalFile() const;
125
QString toString(FormattingOptions options = None) const;
127
QByteArray toEncoded(FormattingOptions options = None) const;
128
static QUrl fromEncoded(const QByteArray &url);
131
bool isDetached() const;
133
bool operator <(const QUrl &url) const;
134
bool operator ==(const QUrl &url) const;
135
bool operator !=(const QUrl &url) const;
136
QUrl &operator =(const QUrl ©);
138
static QString fromPercentEncoding(const QByteArray &);
139
static QByteArray toPercentEncoding(const QString &,
140
const QByteArray &exclude = QByteArray(),
141
const QByteArray &include = QByteArray());
142
static QString fromPunycode(const QByteArray &);
143
static QByteArray toPunycode(const QString &);
145
#if defined QT3_SUPPORT
146
inline QT3_SUPPORT QString protocol() const { return scheme(); }
147
inline QT3_SUPPORT void setProtocol(const QString &s) { setScheme(s); }
148
inline QT3_SUPPORT void setUser(const QString &s) { setUserName(s); }
149
inline QT3_SUPPORT QString user() const { return userName(); }
150
inline QT3_SUPPORT bool hasUser() const { return !userName().isEmpty(); }
151
inline QT3_SUPPORT bool hasPassword() const { return !password().isEmpty(); }
152
inline QT3_SUPPORT bool hasHost() const { return !host().isEmpty(); }
153
inline QT3_SUPPORT bool hasPort() const { return port() != -1; }
154
inline QT3_SUPPORT bool hasPath() const { return !path().isEmpty(); }
155
inline QT3_SUPPORT void setQuery(const QString &txt)
157
setEncodedQuery(txt.toLatin1());
159
inline QT3_SUPPORT QString query() const
161
return QString::fromLatin1(encodedQuery());
163
inline QT3_SUPPORT QString ref() const { return fragment(); }
164
inline QT3_SUPPORT void setRef(const QString &txt) { setFragment(txt); }
165
inline QT3_SUPPORT bool hasRef() const { return !fragment().isEmpty(); }
166
inline QT3_SUPPORT void addPath(const QString &p) { setPath(path() + QLatin1String("/") + p); }
167
QT3_SUPPORT void setFileName(const QString &txt);
168
QT3_SUPPORT QString fileName() const;
169
QT3_SUPPORT QString dirPath() const;
170
static inline QT3_SUPPORT void decode(QString &url)
172
url = QUrl::fromPercentEncoding(url.toLatin1());
174
static inline QT3_SUPPORT void encode(QString &url)
176
url = QString::fromLatin1(QUrl::toPercentEncoding(url));
178
inline QT3_SUPPORT operator QString() const { return toString(); }
179
inline QT3_SUPPORT bool cdUp()
181
*this = resolved(QUrl(QLatin1String("..")));
184
static inline QT3_SUPPORT bool isRelativeUrl(const QString &url)
186
return QUrl(url).isRelative();
191
#if defined (QT3_SUPPORT)
192
inline QT3_SUPPORT void reset() { clear(); }
195
QUrl(QUrlPrivate &d);
201
Q_DECLARE_TYPEINFO(QUrl, Q_MOVABLE_TYPE);
202
Q_DECLARE_SHARED(QUrl)
203
Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions)
205
#ifndef QT_NO_DATASTREAM
206
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUrl &);
207
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUrl &);
210
#ifndef QT_NO_DEBUG_STREAM
211
Q_CORE_EXPORT QDebug operator<<(QDebug, const QUrl &);