-rw-r--r-- | microkde/kurl.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/microkde/kurl.h b/microkde/kurl.h index cd65a1c..016eb24 100644 --- a/microkde/kurl.h +++ b/microkde/kurl.h | |||
@@ -1,853 +1,855 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | * Copyright (C) 1999 Torben Weis <weis@kde.org> | 2 | * Copyright (C) 1999 Torben Weis <weis@kde.org> |
3 | * | 3 | * |
4 | * This library is free software; you can redistribute it and/or | 4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. | 7 | * version 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * This library is distributed in the hope that it will be useful, | 9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. | 12 | * Library General Public License for more details. |
13 | * | 13 | * |
14 | * You should have received a copy of the GNU Library General Public License | 14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to | 15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | * Boston, MA 02111-1307, USA. | 17 | * Boston, MA 02111-1307, USA. |
18 | **/ | 18 | **/ |
19 | 19 | ||
20 | #ifndef __kurl_h__ | 20 | #ifndef __kurl_h__ |
21 | #define __kurl_h__ "$Id$" | 21 | #define __kurl_h__ "$Id$" |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qvaluelist.h> | 24 | #include <q3valuelist.h> |
25 | //Added by qt3to4: | ||
26 | #include <Q3CString> | ||
25 | 27 | ||
26 | class QUrl; | 28 | class Q3Url; |
27 | class QStringList; | 29 | class QStringList; |
28 | template <typename K, typename V> class QMap; | 30 | template <typename K, typename V> class QMap; |
29 | 31 | ||
30 | class KURLPrivate; | 32 | class KURLPrivate; |
31 | /** | 33 | /** |
32 | * Represents and parses a URL. | 34 | * Represents and parses a URL. |
33 | * | 35 | * |
34 | * A prototypical URL looks like: | 36 | * A prototypical URL looks like: |
35 | * <pre> | 37 | * <pre> |
36 | * protocol:/user:password\@hostname:port/path/to/file.ext#reference | 38 | * protocol:/user:password\@hostname:port/path/to/file.ext#reference |
37 | * </pre> | 39 | * </pre> |
38 | * | 40 | * |
39 | * KURL has some restrictions regarding the path | 41 | * KURL has some restrictions regarding the path |
40 | * encoding. KURL works internally with the decoded path and | 42 | * encoding. KURL works internally with the decoded path and |
41 | * and encoded query. For example, | 43 | * and encoded query. For example, |
42 | * <pre> | 44 | * <pre> |
43 | * http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you | 45 | * http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you |
44 | * </pre> | 46 | * </pre> |
45 | * would result in a decoded path "/cgi-bin/test me.pl" | 47 | * would result in a decoded path "/cgi-bin/test me.pl" |
46 | * and in the encoded query "?cmd=Hello%20you". | 48 | * and in the encoded query "?cmd=Hello%20you". |
47 | * Since path is internally always encoded you may @em not use | 49 | * Since path is internally always encoded you may @em not use |
48 | * "%00" in the path, although this is OK for the query. | 50 | * "%00" in the path, although this is OK for the query. |
49 | * | 51 | * |
50 | * @author Torben Weis <weis@kde.org> | 52 | * @author Torben Weis <weis@kde.org> |
51 | */ | 53 | */ |
52 | class KURL | 54 | class KURL |
53 | { | 55 | { |
54 | public: | 56 | public: |
55 | enum AdjustementFlags | 57 | enum AdjustementFlags |
56 | { | 58 | { |
57 | NoAdjustements = 0, | 59 | NoAdjustements = 0, |
58 | StripFileProtocol = 1 | 60 | StripFileProtocol = 1 |
59 | }; | 61 | }; |
60 | 62 | ||
61 | /** | 63 | /** |
62 | * KURL::List is a QValueList that contains KURLs with a few | 64 | * KURL::List is a QValueList that contains KURLs with a few |
63 | * convenience methods. | 65 | * convenience methods. |
64 | * @see KURL | 66 | * @see KURL |
65 | * @see QValueList | 67 | * @see QValueList |
66 | */ | 68 | */ |
67 | class List : public QValueList<KURL> | 69 | class List : public Q3ValueList<KURL> |
68 | { | 70 | { |
69 | public: | 71 | public: |
70 | /** | 72 | /** |
71 | * Creates an empty List. | 73 | * Creates an empty List. |
72 | */ | 74 | */ |
73 | List() { } | 75 | List() { } |
74 | /** | 76 | /** |
75 | * Creates a list that contains the given URL as only | 77 | * Creates a list that contains the given URL as only |
76 | * item. | 78 | * item. |
77 | * @param url the url to add. | 79 | * @param url the url to add. |
78 | */ | 80 | */ |
79 | List(const KURL &url); | 81 | List(const KURL &url); |
80 | /** | 82 | /** |
81 | * Creates a list that contains the URLs from the given | 83 | * Creates a list that contains the URLs from the given |
82 | * list. | 84 | * list. |
83 | * @param list the list containing the URLs as strings | 85 | * @param list the list containing the URLs as strings |
84 | */ | 86 | */ |
85 | List(const QStringList &list); | 87 | List(const QStringList &list); |
86 | /** | 88 | /** |
87 | * Converts the URLs of this list to a list of strings. | 89 | * Converts the URLs of this list to a list of strings. |
88 | * @return the list of strings | 90 | * @return the list of strings |
89 | */ | 91 | */ |
90 | QStringList toStringList() const; | 92 | QStringList toStringList() const; |
91 | }; | 93 | }; |
92 | /** | 94 | /** |
93 | * Constructs an empty URL. | 95 | * Constructs an empty URL. |
94 | */ | 96 | */ |
95 | KURL(); | 97 | KURL(); |
96 | 98 | ||
97 | /** | 99 | /** |
98 | * Destructs the KURL object. | 100 | * Destructs the KURL object. |
99 | */ | 101 | */ |
100 | ~KURL(); | 102 | ~KURL(); |
101 | 103 | ||
102 | /** | 104 | /** |
103 | * Usual constructor, to construct from a string. | 105 | * Usual constructor, to construct from a string. |
104 | * @param url A URL, not a filename. If the URL does not have a protocol | 106 | * @param url A URL, not a filename. If the URL does not have a protocol |
105 | * part, "file:" is assumed. | 107 | * part, "file:" is assumed. |
106 | * It is dangerous to feed unix filenames into this function, | 108 | * It is dangerous to feed unix filenames into this function, |
107 | * this will work most of the time but not always. | 109 | * this will work most of the time but not always. |
108 | * For example "/home/Torben%20Weis" will be considered a URL | 110 | * For example "/home/Torben%20Weis" will be considered a URL |
109 | * pointing to the file "/home/Torben Weis" instead of to the | 111 | * pointing to the file "/home/Torben Weis" instead of to the |
110 | * file "/home/Torben%20Weis". | 112 | * file "/home/Torben%20Weis". |
111 | * This means that if you have a usual UNIX like path you | 113 | * This means that if you have a usual UNIX like path you |
112 | * should not use this constructor. | 114 | * should not use this constructor. |
113 | * Instead create an empty url and set the path by using | 115 | * Instead create an empty url and set the path by using |
114 | * @ref setPath(). | 116 | * @ref setPath(). |
115 | * @param encoding_hint MIB of original encoding of URL. | 117 | * @param encoding_hint MIB of original encoding of URL. |
116 | * @see QTextCodec::mibEnum() | 118 | * @see QTextCodec::mibEnum() |
117 | */ | 119 | */ |
118 | KURL( const QString& url, int encoding_hint = 0 ); | 120 | KURL( const QString& url, int encoding_hint = 0 ); |
119 | /** | 121 | /** |
120 | * Constructor taking a char * @p url, which is an _encoded_ representation | 122 | * Constructor taking a char * @p url, which is an _encoded_ representation |
121 | * of the URL, exactly like the usual constructor. This is useful when | 123 | * of the URL, exactly like the usual constructor. This is useful when |
122 | * then URL, in its encoded form, is strictly ascii. | 124 | * then URL, in its encoded form, is strictly ascii. |
123 | * @param url A encoded URL. If the URL does not have a protocol part, | 125 | * @param url A encoded URL. If the URL does not have a protocol part, |
124 | * "file:" is assumed. | 126 | * "file:" is assumed. |
125 | * @param encoding_hint MIB of original encoding of URL. | 127 | * @param encoding_hint MIB of original encoding of URL. |
126 | * @see QTextCodec::mibEnum() | 128 | * @see QTextCodec::mibEnum() |
127 | */ | 129 | */ |
128 | KURL( const char * url, int encoding_hint = 0 ); | 130 | KURL( const char * url, int encoding_hint = 0 ); |
129 | /** | 131 | /** |
130 | * Constructor taking a QCString @p url, which is an _encoded_ representation | 132 | * Constructor taking a QCString @p url, which is an _encoded_ representation |
131 | * of the URL, exactly like the usual constructor. This is useful when | 133 | * of the URL, exactly like the usual constructor. This is useful when |
132 | * then URL, in its encoded form, is strictly ascii. | 134 | * then URL, in its encoded form, is strictly ascii. |
133 | * @param url A encoded URL. If the URL does not have a protocol part, | 135 | * @param url A encoded URL. If the URL does not have a protocol part, |
134 | * "file:" is assumed. | 136 | * "file:" is assumed. |
135 | * @param encoding_hint MIB of original encoding of URL. | 137 | * @param encoding_hint MIB of original encoding of URL. |
136 | * @see QTextCodec::mibEnum() | 138 | * @see QTextCodec::mibEnum() |
137 | */ | 139 | */ |
138 | KURL( const QCString& url, int encoding_hint = 0 ); | 140 | KURL( const Q3CString& url, int encoding_hint = 0 ); |
139 | /** | 141 | /** |
140 | * Copy constructor. | 142 | * Copy constructor. |
141 | * @param u the KURL to copy | 143 | * @param u the KURL to copy |
142 | */ | 144 | */ |
143 | KURL( const KURL& u ); | 145 | KURL( const KURL& u ); |
144 | /** | 146 | /** |
145 | * Converts from a @ref QUrl. | 147 | * Converts from a @ref QUrl. |
146 | * @param u the QUrl | 148 | * @param u the QUrl |
147 | */ | 149 | */ |
148 | KURL( const QUrl &u ); | 150 | KURL( const Q3Url &u ); |
149 | /** | 151 | /** |
150 | * Constructor allowing relative URLs. | 152 | * Constructor allowing relative URLs. |
151 | * | 153 | * |
152 | * @param _baseurl The base url. | 154 | * @param _baseurl The base url. |
153 | * @param _rel_url A relative or absolute URL. | 155 | * @param _rel_url A relative or absolute URL. |
154 | * If this is an absolute URL then @p _baseurl will be ignored. | 156 | * If this is an absolute URL then @p _baseurl will be ignored. |
155 | * If this is a relative URL it will be combined with @p _baseurl. | 157 | * If this is a relative URL it will be combined with @p _baseurl. |
156 | * Note that _rel_url should be encoded too, in any case. | 158 | * Note that _rel_url should be encoded too, in any case. |
157 | * So do NOT pass a path here (use setPath or addPath instead). | 159 | * So do NOT pass a path here (use setPath or addPath instead). |
158 | * @param encoding_hint MIB of original encoding of URL. | 160 | * @param encoding_hint MIB of original encoding of URL. |
159 | * @see QTextCodec::mibEnum() | 161 | * @see QTextCodec::mibEnum() |
160 | */ | 162 | */ |
161 | KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 ); | 163 | KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 ); |
162 | 164 | ||
163 | /** | 165 | /** |
164 | * Returns the protocol for the URL (i.e., file, http, etc.). | 166 | * Returns the protocol for the URL (i.e., file, http, etc.). |
165 | * @return the protocol of the URL, does not include the colon. If the | 167 | * @return the protocol of the URL, does not include the colon. If the |
166 | * URL is malformed, QString::null will be returned. | 168 | * URL is malformed, QString::null will be returned. |
167 | **/ | 169 | **/ |
168 | QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; } | 170 | QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; } |
169 | /** | 171 | /** |
170 | * Sets the protocol for the URL (i.e., file, http, etc.) | 172 | * Sets the protocol for the URL (i.e., file, http, etc.) |
171 | * @param _txt the new protocol of the URL (without colon) | 173 | * @param _txt the new protocol of the URL (without colon) |
172 | **/ | 174 | **/ |
173 | void setProtocol( const QString& _txt ); | 175 | void setProtocol( const QString& _txt ); |
174 | 176 | ||
175 | /** | 177 | /** |
176 | * Returns the decoded user name (login, user id, ...) included in the URL. | 178 | * Returns the decoded user name (login, user id, ...) included in the URL. |
177 | * @return the user name or QString::null if there is no user name | 179 | * @return the user name or QString::null if there is no user name |
178 | **/ | 180 | **/ |
179 | QString user() const { return m_strUser; } | 181 | QString user() const { return m_strUser; } |
180 | /** | 182 | /** |
181 | * Sets the user name (login, user id, ...) included in the URL. | 183 | * Sets the user name (login, user id, ...) included in the URL. |
182 | * | 184 | * |
183 | * Special characters in the user name will appear encoded in the URL. | 185 | * Special characters in the user name will appear encoded in the URL. |
184 | * @param _txt the name of the user or QString::null to remove the user | 186 | * @param _txt the name of the user or QString::null to remove the user |
185 | **/ | 187 | **/ |
186 | void setUser( const QString& _txt ); | 188 | void setUser( const QString& _txt ); |
187 | /** | 189 | /** |
188 | * Test to see if this URL has a user name included in it. | 190 | * Test to see if this URL has a user name included in it. |
189 | * @return true if the URL has an non-empty user name | 191 | * @return true if the URL has an non-empty user name |
190 | **/ | 192 | **/ |
191 | bool hasUser() const { return !m_strUser.isEmpty(); } | 193 | bool hasUser() const { return !m_strUser.isEmpty(); } |
192 | 194 | ||
193 | /** | 195 | /** |
194 | * Returns the decoded password (corresponding to \ref user()) included in the URL. | 196 | * Returns the decoded password (corresponding to \ref user()) included in the URL. |
195 | * @return the password or QString::null if it does not exist | 197 | * @return the password or QString::null if it does not exist |
196 | **/ | 198 | **/ |
197 | QString pass() const { return m_strPass; } | 199 | QString pass() const { return m_strPass; } |
198 | /** | 200 | /** |
199 | * Sets the password (corresponding to @ref user()) included in the URL. | 201 | * Sets the password (corresponding to @ref user()) included in the URL. |
200 | * | 202 | * |
201 | * Special characters in the password will appear encoded in the URL. | 203 | * Special characters in the password will appear encoded in the URL. |
202 | * Note that a password can only appear in a URL string if you also set | 204 | * Note that a password can only appear in a URL string if you also set |
203 | * a user. | 205 | * a user. |
204 | * @param _txt the password to set or QString::null to remove the password | 206 | * @param _txt the password to set or QString::null to remove the password |
205 | * @see #setUser | 207 | * @see #setUser |
206 | * @see #hasUser | 208 | * @see #hasUser |
207 | **/ | 209 | **/ |
208 | void setPass( const QString& _txt ); | 210 | void setPass( const QString& _txt ); |
209 | /** | 211 | /** |
210 | * Test to see if this URL has a password included in it. | 212 | * Test to see if this URL has a password included in it. |
211 | * @return true if there is a non-empty password set | 213 | * @return true if there is a non-empty password set |
212 | **/ | 214 | **/ |
213 | bool hasPass() const { return !m_strPass.isEmpty(); } | 215 | bool hasPass() const { return !m_strPass.isEmpty(); } |
214 | 216 | ||
215 | /** | 217 | /** |
216 | * Returns the decoded hostname included in the URL. | 218 | * Returns the decoded hostname included in the URL. |
217 | * @return the name of the host or QString::null if no host is set | 219 | * @return the name of the host or QString::null if no host is set |
218 | **/ | 220 | **/ |
219 | QString host() const { return m_strHost; } | 221 | QString host() const { return m_strHost; } |
220 | 222 | ||
221 | /** | 223 | /** |
222 | * Sets the hostname included in the URL. | 224 | * Sets the hostname included in the URL. |
223 | * | 225 | * |
224 | * Special characters in the hostname will appear encoded in the URL. | 226 | * Special characters in the hostname will appear encoded in the URL. |
225 | * @param _txt the new name of the host or QString::null to remove the host | 227 | * @param _txt the new name of the host or QString::null to remove the host |
226 | **/ | 228 | **/ |
227 | void setHost( const QString& _txt ); | 229 | void setHost( const QString& _txt ); |
228 | /** | 230 | /** |
229 | * Test to see if this URL has a hostname included in it. | 231 | * Test to see if this URL has a hostname included in it. |
230 | * @return true if the URL has a host | 232 | * @return true if the URL has a host |
231 | **/ | 233 | **/ |
232 | bool hasHost() const { return !m_strHost.isEmpty(); } | 234 | bool hasHost() const { return !m_strHost.isEmpty(); } |
233 | 235 | ||
234 | /** | 236 | /** |
235 | * Returns the port number included in the URL. | 237 | * Returns the port number included in the URL. |
236 | * @return the port number. If there is no port number specified in the | 238 | * @return the port number. If there is no port number specified in the |
237 | * URL, returns 0. | 239 | * URL, returns 0. |
238 | **/ | 240 | **/ |
239 | unsigned short int port() const { return m_iPort; } | 241 | unsigned short int port() const { return m_iPort; } |
240 | /** | 242 | /** |
241 | * Sets the port number included in the URL. | 243 | * Sets the port number included in the URL. |
242 | * @param _p the new port number or 0 to have no port number | 244 | * @param _p the new port number or 0 to have no port number |
243 | **/ | 245 | **/ |
244 | void setPort( unsigned short int _p ); | 246 | void setPort( unsigned short int _p ); |
245 | 247 | ||
246 | /** | 248 | /** |
247 | * Returns the current decoded path. This does @em not include the query. | 249 | * Returns the current decoded path. This does @em not include the query. |
248 | * @return the path of the URL (without query), or QString::null if no | 250 | * @return the path of the URL (without query), or QString::null if no |
249 | * path set. | 251 | * path set. |
250 | */ | 252 | */ |
251 | QString path() const { return m_strPath; } | 253 | QString path() const { return m_strPath; } |
252 | 254 | ||
253 | /** | 255 | /** |
254 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds | 256 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds |
255 | * a trailing '/' if there is none yet and 0 returns the | 257 | * a trailing '/' if there is none yet and 0 returns the |
256 | * path unchanged. If the URL has no path, then no '/' is added | 258 | * path unchanged. If the URL has no path, then no '/' is added |
257 | * anyway. And on the other side: If the path is "/", then this | 259 | * anyway. And on the other side: If the path is "/", then this |
258 | * character won't be stripped. Reason: "ftp://weis\@host" means something | 260 | * character won't be stripped. Reason: "ftp://weis\@host" means something |
259 | * completely different than "ftp://weis\@host/". So adding or stripping | 261 | * completely different than "ftp://weis\@host/". So adding or stripping |
260 | * the '/' would really alter the URL, while "ftp://host/path" and | 262 | * the '/' would really alter the URL, while "ftp://host/path" and |
261 | * "ftp://host/path/" mean the same directory. | 263 | * "ftp://host/path/" mean the same directory. |
262 | * | 264 | * |
263 | * @return The current decoded path. This does not include the query. Can | 265 | * @return The current decoded path. This does not include the query. Can |
264 | * be QString::null if no path is set. | 266 | * be QString::null if no path is set. |
265 | */ | 267 | */ |
266 | QString path( int _trailing ) const; | 268 | QString path( int _trailing ) const; |
267 | 269 | ||
268 | /** | 270 | /** |
269 | * Sets the path of the URL. The query is not changed by this function. | 271 | * Sets the path of the URL. The query is not changed by this function. |
270 | * | 272 | * |
271 | * @param path The new path. This is considered to be decoded. This | 273 | * @param path The new path. This is considered to be decoded. This |
272 | * means: %3f does not become decoded | 274 | * means: %3f does not become decoded |
273 | * and the ? does not indicate the start of the query part. | 275 | * and the ? does not indicate the start of the query part. |
274 | * Can be QString::null to delete the path. | 276 | * Can be QString::null to delete the path. |
275 | */ | 277 | */ |
276 | void setPath( const QString& path ); | 278 | void setPath( const QString& path ); |
277 | 279 | ||
278 | /** | 280 | /** |
279 | * Test to see if this URL has a path is included in it. | 281 | * Test to see if this URL has a path is included in it. |
280 | * @return true if there is a path | 282 | * @return true if there is a path |
281 | **/ | 283 | **/ |
282 | bool hasPath() const { return !m_strPath.isEmpty(); } | 284 | bool hasPath() const { return !m_strPath.isEmpty(); } |
283 | 285 | ||
284 | /** | 286 | /** |
285 | * Resolves "." and ".." components in path. | 287 | * Resolves "." and ".." components in path. |
286 | * Some servers seem not to like the removal of extra '/' | 288 | * Some servers seem not to like the removal of extra '/' |
287 | * even though it is against the specification in RFC 2396. | 289 | * even though it is against the specification in RFC 2396. |
288 | * | 290 | * |
289 | * @param cleanDirSeparator if true, occurrances of consecutive | 291 | * @param cleanDirSeparator if true, occurrances of consecutive |
290 | * directory separators (e.g. /foo//bar) are cleaned up as well. | 292 | * directory separators (e.g. /foo//bar) are cleaned up as well. |
291 | */ | 293 | */ |
292 | void cleanPath(bool cleanDirSeparator = true); | 294 | void cleanPath(bool cleanDirSeparator = true); |
293 | 295 | ||
294 | /** | 296 | /** |
295 | * Add or remove a trailing slash to/from the path. | 297 | * Add or remove a trailing slash to/from the path. |
296 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds | 298 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds |
297 | * a trailing '/' if there is none yet and 0 returns the | 299 | * a trailing '/' if there is none yet and 0 returns the |
298 | * path unchanged. If the URL has no path, then no '/' is added | 300 | * path unchanged. If the URL has no path, then no '/' is added |
299 | * anyway. And on the other side: If the path is "/", then this | 301 | * anyway. And on the other side: If the path is "/", then this |
300 | * character won't be stripped. Reason: "ftp://weis\@host" means something | 302 | * character won't be stripped. Reason: "ftp://weis\@host" means something |
301 | * completely different than "ftp://weis\@host/". So adding or stripping | 303 | * completely different than "ftp://weis\@host/". So adding or stripping |
302 | * the '/' would really alter the URL, while "ftp://host/path" and | 304 | * the '/' would really alter the URL, while "ftp://host/path" and |
303 | * "ftp://host/path/" mean the same directory. | 305 | * "ftp://host/path/" mean the same directory. |
304 | */ | 306 | */ |
305 | void adjustPath(int _trailing); | 307 | void adjustPath(int _trailing); |
306 | 308 | ||
307 | /** | 309 | /** |
308 | * This is useful for HTTP. It looks first for '?' and decodes then. | 310 | * This is useful for HTTP. It looks first for '?' and decodes then. |
309 | * The encoded path is the concatenation of the current path and the query. | 311 | * The encoded path is the concatenation of the current path and the query. |
310 | * @param _txt the new path and query. | 312 | * @param _txt the new path and query. |
311 | * @param encoding_hint MIB of original encoding of @p _txt . | 313 | * @param encoding_hint MIB of original encoding of @p _txt . |
312 | * @see QTextCodec::mibEnum() | 314 | * @see QTextCodec::mibEnum() |
313 | */ | 315 | */ |
314 | void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 ); | 316 | void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 ); |
315 | 317 | ||
316 | /** | 318 | /** |
317 | * Sets the (already encoded) path | 319 | * Sets the (already encoded) path |
318 | * @param _txt the new path | 320 | * @param _txt the new path |
319 | * @param encoding_hint MIB of original encoding of @p _txt . | 321 | * @param encoding_hint MIB of original encoding of @p _txt . |
320 | * @see QTextCodec::mibEnum() | 322 | * @see QTextCodec::mibEnum() |
321 | */ | 323 | */ |
322 | void setEncodedPath(const QString& _txt, int encoding_hint = 0 ); | 324 | void setEncodedPath(const QString& _txt, int encoding_hint = 0 ); |
323 | 325 | ||
324 | /** | 326 | /** |
325 | * Returns the encoded path and the query. | 327 | * Returns the encoded path and the query. |
326 | * | 328 | * |
327 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds | 329 | * @param _trailing May be ( -1, 0 +1 ). -1 strips a trailing '/', +1 adds |
328 | * a trailing '/' if there is none yet and 0 returns the | 330 | * a trailing '/' if there is none yet and 0 returns the |
329 | * path unchanged. If the URL has no path, then no '/' is added | 331 | * path unchanged. If the URL has no path, then no '/' is added |
330 | * anyway. And on the other side: If the path is "/", then this | 332 | * anyway. And on the other side: If the path is "/", then this |
331 | * character won't be stripped. Reason: "ftp://weis\@host" means something | 333 | * character won't be stripped. Reason: "ftp://weis\@host" means something |
332 | * completely different than "ftp://weis\@host/". So adding or stripping | 334 | * completely different than "ftp://weis\@host/". So adding or stripping |
333 | * the '/' would really alter the URL, while "ftp://host/path" and | 335 | * the '/' would really alter the URL, while "ftp://host/path" and |
334 | * "ftp://host/path/" mean the same directory. | 336 | * "ftp://host/path/" mean the same directory. |
335 | * @param _no_empty_path If set to true then an empty path is substituted by "/". | 337 | * @param _no_empty_path If set to true then an empty path is substituted by "/". |
336 | * @param encoding_hint MIB of desired encoding of URL. | 338 | * @param encoding_hint MIB of desired encoding of URL. |
337 | * @see QTextCodec::mibEnum() | 339 | * @see QTextCodec::mibEnum() |
338 | * @return The concatenation if the encoded path , '?' and the encoded query. | 340 | * @return The concatenation if the encoded path , '?' and the encoded query. |
339 | * | 341 | * |
340 | */ | 342 | */ |
341 | QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const; | 343 | QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const; |
342 | 344 | ||
343 | /** | 345 | /** |
344 | * @param _txt This is considered to be encoded. This has a good reason: | 346 | * @param _txt This is considered to be encoded. This has a good reason: |
345 | * The query may contain the 0 character. | 347 | * The query may contain the 0 character. |
346 | * | 348 | * |
347 | * The query should start with a '?'. If it doesn't '?' is prepended. | 349 | * The query should start with a '?'. If it doesn't '?' is prepended. |
348 | * @param encoding_hint Reserved, should be 0. | 350 | * @param encoding_hint Reserved, should be 0. |
349 | * @see QTextCodec::mibEnum() | 351 | * @see QTextCodec::mibEnum() |
350 | */ | 352 | */ |
351 | void setQuery( const QString& _txt, int encoding_hint = 0); | 353 | void setQuery( const QString& _txt, int encoding_hint = 0); |
352 | 354 | ||
353 | /** | 355 | /** |
354 | * Returns the query of the URL. | 356 | * Returns the query of the URL. |
355 | * The query may contain the 0 character. | 357 | * The query may contain the 0 character. |
356 | * If a query is present it always starts with a '?'. | 358 | * If a query is present it always starts with a '?'. |
357 | * A single '?' means an empty query. | 359 | * A single '?' means an empty query. |
358 | * An empty string means no query. | 360 | * An empty string means no query. |
359 | * @return The encoded query, or QString::null if there is none. | 361 | * @return The encoded query, or QString::null if there is none. |
360 | */ | 362 | */ |
361 | QString query() const; | 363 | QString query() const; |
362 | 364 | ||
363 | /** | 365 | /** |
364 | * The reference is @em never decoded automatically. | 366 | * The reference is @em never decoded automatically. |
365 | * @return the undecoded reference, or QString::null if there is none | 367 | * @return the undecoded reference, or QString::null if there is none |
366 | */ | 368 | */ |
367 | QString ref() const { return m_strRef_encoded; } | 369 | QString ref() const { return m_strRef_encoded; } |
368 | 370 | ||
369 | /** | 371 | /** |
370 | * Sets the reference part (everything after '#'). | 372 | * Sets the reference part (everything after '#'). |
371 | * @param _txt The encoded reference (or QString::null to remove it). | 373 | * @param _txt The encoded reference (or QString::null to remove it). |
372 | */ | 374 | */ |
373 | void setRef( const QString& _txt ) { m_strRef_encoded = _txt; } | 375 | void setRef( const QString& _txt ) { m_strRef_encoded = _txt; } |
374 | 376 | ||
375 | /** | 377 | /** |
376 | * Checks whether the URL has a reference part. | 378 | * Checks whether the URL has a reference part. |
377 | * @return true if the URL has a reference part. In a URL like | 379 | * @return true if the URL has a reference part. In a URL like |
378 | * http://www.kde.org/kdebase.tar#tar:/README it would | 380 | * http://www.kde.org/kdebase.tar#tar:/README it would |
379 | * return true, too. | 381 | * return true, too. |
380 | */ | 382 | */ |
381 | bool hasRef() const { return !m_strRef_encoded.isNull(); } | 383 | bool hasRef() const { return !m_strRef_encoded.isNull(); } |
382 | 384 | ||
383 | /** | 385 | /** |
384 | * Returns the HTML reference (the part of the URL after "#"). | 386 | * Returns the HTML reference (the part of the URL after "#"). |
385 | * @return The HTML-style reference. | 387 | * @return The HTML-style reference. |
386 | * @see #split | 388 | * @see #split |
387 | * @see #hasSubURL | 389 | * @see #hasSubURL |
388 | * @see #encodedHtmlRef | 390 | * @see #encodedHtmlRef |
389 | */ | 391 | */ |
390 | QString htmlRef() const; | 392 | QString htmlRef() const; |
391 | 393 | ||
392 | /** | 394 | /** |
393 | * Returns the HTML reference (the part of the URL after "#") in | 395 | * Returns the HTML reference (the part of the URL after "#") in |
394 | * encoded form. | 396 | * encoded form. |
395 | * @return The HTML-style reference in its original form. | 397 | * @return The HTML-style reference in its original form. |
396 | */ | 398 | */ |
397 | QString encodedHtmlRef() const; | 399 | QString encodedHtmlRef() const; |
398 | 400 | ||
399 | /** | 401 | /** |
400 | * Sets the HTML-style reference. | 402 | * Sets the HTML-style reference. |
401 | * | 403 | * |
402 | * @param _ref The new reference. This is considered to be @em not encoded in | 404 | * @param _ref The new reference. This is considered to be @em not encoded in |
403 | * contrast to @ref setRef(). Use QString::null to remove it. | 405 | * contrast to @ref setRef(). Use QString::null to remove it. |
404 | * @see htmlRef() | 406 | * @see htmlRef() |
405 | */ | 407 | */ |
406 | void setHTMLRef( const QString& _ref ); | 408 | void setHTMLRef( const QString& _ref ); |
407 | 409 | ||
408 | /** | 410 | /** |
409 | * Checks whether there is a HTML reference. | 411 | * Checks whether there is a HTML reference. |
410 | * @return true if the URL has an HTML-style reference. | 412 | * @return true if the URL has an HTML-style reference. |
411 | * @see htmlRef() | 413 | * @see htmlRef() |
412 | */ | 414 | */ |
413 | bool hasHTMLRef() const; | 415 | bool hasHTMLRef() const; |
414 | 416 | ||
415 | /** | 417 | /** |
416 | * Checks whether the URL is well formed. | 418 | * Checks whether the URL is well formed. |
417 | * @return false if the URL is malformed. This function does @em not test | 419 | * @return false if the URL is malformed. This function does @em not test |
418 | * whether sub URLs are well-formed, too. | 420 | * whether sub URLs are well-formed, too. |
419 | */ | 421 | */ |
420 | bool isValid() const { return !m_bIsMalformed; } | 422 | bool isValid() const { return !m_bIsMalformed; } |
421 | /** | 423 | /** |
422 | * @deprecated | 424 | * @deprecated |
423 | */ | 425 | */ |
424 | bool isMalformed() const { return !isValid(); } | 426 | bool isMalformed() const { return !isValid(); } |
425 | 427 | ||
426 | /** | 428 | /** |
427 | * Checks whether the file is local. | 429 | * Checks whether the file is local. |
428 | * @return true if the file is a plain local file and has no filter protocols | 430 | * @return true if the file is a plain local file and has no filter protocols |
429 | * attached to it. | 431 | * attached to it. |
430 | */ | 432 | */ |
431 | bool isLocalFile() const; | 433 | bool isLocalFile() const; |
432 | 434 | ||
433 | /** | 435 | /** |
434 | * Adds encoding information to url by adding a "charset" parameter. If there | 436 | * Adds encoding information to url by adding a "charset" parameter. If there |
435 | * is already a charset parameter, it will be replaced. | 437 | * is already a charset parameter, it will be replaced. |
436 | * @param encoding the encoding to add or QString::null to remove the | 438 | * @param encoding the encoding to add or QString::null to remove the |
437 | * encoding. | 439 | * encoding. |
438 | */ | 440 | */ |
439 | void setFileEncoding(const QString &encoding); | 441 | void setFileEncoding(const QString &encoding); |
440 | 442 | ||
441 | /** | 443 | /** |
442 | * Returns encoding information from url, the content of the "charset" | 444 | * Returns encoding information from url, the content of the "charset" |
443 | * parameter. | 445 | * parameter. |
444 | * @return An encoding suitable for QTextCodec::codecForName() | 446 | * @return An encoding suitable for QTextCodec::codecForName() |
445 | * or QString::null if not encoding was specified. | 447 | * or QString::null if not encoding was specified. |
446 | */ | 448 | */ |
447 | QString fileEncoding() const; | 449 | QString fileEncoding() const; |
448 | 450 | ||
449 | /** | 451 | /** |
450 | * Checks whether the URL has any sub URLs. See @ref #split() | 452 | * Checks whether the URL has any sub URLs. See @ref #split() |
451 | * for examples for sub URLs. | 453 | * for examples for sub URLs. |
452 | * @return true if the file has at least one sub URL. | 454 | * @return true if the file has at least one sub URL. |
453 | * @see #split | 455 | * @see #split |
454 | */ | 456 | */ |
455 | bool hasSubURL() const; | 457 | bool hasSubURL() const; |
456 | 458 | ||
457 | /** | 459 | /** |
458 | * Adds to the current path. | 460 | * Adds to the current path. |
459 | * Assumes that the current path is a directory. @p _txt is appended to the | 461 | * Assumes that the current path is a directory. @p _txt is appended to the |
460 | * current path. The function adds '/' if needed while concatenating. | 462 | * current path. The function adds '/' if needed while concatenating. |
461 | * This means it does not matter whether the current path has a trailing | 463 | * This means it does not matter whether the current path has a trailing |
462 | * '/' or not. If there is none, it becomes appended. If @p _txt | 464 | * '/' or not. If there is none, it becomes appended. If @p _txt |
463 | * has a leading '/' then this one is stripped. | 465 | * has a leading '/' then this one is stripped. |
464 | * | 466 | * |
465 | * @param _txt The text to add. It is considered to be decoded. | 467 | * @param _txt The text to add. It is considered to be decoded. |
466 | */ | 468 | */ |
467 | void addPath( const QString& _txt ); | 469 | void addPath( const QString& _txt ); |
468 | 470 | ||
469 | /** | 471 | /** |
470 | * Returns the value of a certain query item. | 472 | * Returns the value of a certain query item. |
471 | * | 473 | * |
472 | * @param _item Item whose value we want | 474 | * @param _item Item whose value we want |
473 | * @param encoding_hint MIB of encoding of query. | 475 | * @param encoding_hint MIB of encoding of query. |
474 | * | 476 | * |
475 | * @return the value of the given query item name or QString::null if the | 477 | * @return the value of the given query item name or QString::null if the |
476 | * specified item does not exist. | 478 | * specified item does not exist. |
477 | */ | 479 | */ |
478 | /*US we do not need this functions | 480 | /*US we do not need this functions |
479 | QString queryItem( const QString& _item ) const; | 481 | QString queryItem( const QString& _item ) const; |
480 | QString queryItem( const QString& _item, int encoding_hint ) const; | 482 | QString queryItem( const QString& _item, int encoding_hint ) const; |
481 | */ | 483 | */ |
482 | /** | 484 | /** |
483 | * Options for @ref #queryItems. Currently, only one option is | 485 | * Options for @ref #queryItems. Currently, only one option is |
484 | * defined: | 486 | * defined: |
485 | * | 487 | * |
486 | * @param CaseInsensitiveKeys normalize query keys to lowercase. | 488 | * @param CaseInsensitiveKeys normalize query keys to lowercase. |
487 | * | 489 | * |
488 | * @since 3.1 | 490 | * @since 3.1 |
489 | **/ | 491 | **/ |
490 | enum QueryItemsOptions { CaseInsensitiveKeys = 1 }; | 492 | enum QueryItemsOptions { CaseInsensitiveKeys = 1 }; |
491 | 493 | ||
492 | /** | 494 | /** |
493 | * Returns the list of query items as a map mapping keys to values. | 495 | * Returns the list of query items as a map mapping keys to values. |
494 | * | 496 | * |
495 | * @param options any of @ref QueryItemsOptions <em>or</or>ed together. | 497 | * @param options any of @ref QueryItemsOptions <em>or</or>ed together. |
496 | * @param encoding_hint MIB of encoding of query. | 498 | * @param encoding_hint MIB of encoding of query. |
497 | * | 499 | * |
498 | * @return the map of query items or the empty map if the url has no | 500 | * @return the map of query items or the empty map if the url has no |
499 | * query items. | 501 | * query items. |
500 | * | 502 | * |
501 | * @since 3.1 | 503 | * @since 3.1 |
502 | */ | 504 | */ |
503 | QMap< QString, QString > queryItems( int options=0 ) const; | 505 | QMap< QString, QString > queryItems( int options=0 ) const; |
504 | QMap< QString, QString > queryItems( int options, int encoding_hint ) const; | 506 | QMap< QString, QString > queryItems( int options, int encoding_hint ) const; |
505 | 507 | ||
506 | /** | 508 | /** |
507 | * Add an additional query item. | 509 | * Add an additional query item. |
508 | * To replace an existing query item, the item should first be | 510 | * To replace an existing query item, the item should first be |
509 | * removed with @ref removeQueryItem() | 511 | * removed with @ref removeQueryItem() |
510 | * | 512 | * |
511 | * @param _item Name of item to add | 513 | * @param _item Name of item to add |
512 | * @param _value Value of item to add | 514 | * @param _value Value of item to add |
513 | * @param encoding_hint MIB of encoding to use for _value. | 515 | * @param encoding_hint MIB of encoding to use for _value. |
514 | * @see QTextCodec::mibEnum() | 516 | * @see QTextCodec::mibEnum() |
515 | */ | 517 | */ |
516 | void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 ); | 518 | void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 ); |
517 | 519 | ||
518 | /** | 520 | /** |
519 | * Remove an item from the query. | 521 | * Remove an item from the query. |
520 | * | 522 | * |
521 | * @param _item Item to be removed | 523 | * @param _item Item to be removed |
522 | */ | 524 | */ |
523 | void removeQueryItem( const QString& _item ); | 525 | void removeQueryItem( const QString& _item ); |
524 | 526 | ||
525 | /** | 527 | /** |
526 | * Sets the filename of the path. | 528 | * Sets the filename of the path. |
527 | * In comparison to @ref addPath() this function does not assume that the current | 529 | * In comparison to @ref addPath() this function does not assume that the current |
528 | * path is a directory. This is only assumed if the current path ends with '/'. | 530 | * path is a directory. This is only assumed if the current path ends with '/'. |
529 | * | 531 | * |
530 | * Any reference is reset. | 532 | * Any reference is reset. |
531 | * | 533 | * |
532 | * @param _txt The filename to be set. It is considered to be decoded. If the | 534 | * @param _txt The filename to be set. It is considered to be decoded. If the |
533 | * current path ends with '/' then @p _txt int just appended, otherwise | 535 | * current path ends with '/' then @p _txt int just appended, otherwise |
534 | * all text behind the last '/' in the current path is erased and | 536 | * all text behind the last '/' in the current path is erased and |
535 | * @p _txt is appended then. It does not matter whether @p _txt starts | 537 | * @p _txt is appended then. It does not matter whether @p _txt starts |
536 | * with '/' or not. | 538 | * with '/' or not. |
537 | */ | 539 | */ |
538 | void setFileName( const QString&_txt ); | 540 | void setFileName( const QString&_txt ); |
539 | 541 | ||
540 | /** | 542 | /** |
541 | * Returns the filename of the path. | 543 | * Returns the filename of the path. |
542 | * @param _ignore_trailing_slash_in_path This tells whether a trailing '/' should | 544 | * @param _ignore_trailing_slash_in_path This tells whether a trailing '/' should |
543 | * be ignored. This means that the function would return "torben" for | 545 | * be ignored. This means that the function would return "torben" for |
544 | * <tt>file:/hallo/torben/</tt> and <tt>file:/hallo/torben</tt>. | 546 | * <tt>file:/hallo/torben/</tt> and <tt>file:/hallo/torben</tt>. |
545 | * If the flag is set to false, then everything behind the last '/' | 547 | * If the flag is set to false, then everything behind the last '/' |
546 | * is considered to be the filename. | 548 | * is considered to be the filename. |
547 | * @return The filename of the current path. The returned string is decoded. Null | 549 | * @return The filename of the current path. The returned string is decoded. Null |
548 | * if there is no file (and thus no path). | 550 | * if there is no file (and thus no path). |
549 | */ | 551 | */ |
550 | QString fileName( bool _ignore_trailing_slash_in_path = true ) const; | 552 | QString fileName( bool _ignore_trailing_slash_in_path = true ) const; |
551 | 553 | ||
552 | /** | 554 | /** |
553 | * Returns the directory of the path. | 555 | * Returns the directory of the path. |
554 | * @param _strip_trailing_slash_from_result tells whether the returned result should end with '/' or not. | 556 | * @param _strip_trailing_slash_from_result tells whether the returned result should end with '/' or not. |
555 | * If the path is empty or just "/" then this flag has no effect. | 557 | * If the path is empty or just "/" then this flag has no effect. |
556 | * @param _ignore_trailing_slash_in_path means that <tt>file:/hallo/torben</tt> and | 558 | * @param _ignore_trailing_slash_in_path means that <tt>file:/hallo/torben</tt> and |
557 | * <tt>file:/hallo/torben/"</tt> would both return <tt>/hallo/</tt> | 559 | * <tt>file:/hallo/torben/"</tt> would both return <tt>/hallo/</tt> |
558 | * or <tt>/hallo</tt> depending on the other flag | 560 | * or <tt>/hallo</tt> depending on the other flag |
559 | * @return The directory part of the current path. Everything between the last and the second last '/' | 561 | * @return The directory part of the current path. Everything between the last and the second last '/' |
560 | * is returned. For example <tt>file:/hallo/torben/</tt> would return "/hallo/torben/" while | 562 | * is returned. For example <tt>file:/hallo/torben/</tt> would return "/hallo/torben/" while |
561 | * <tt>file:/hallo/torben</tt> would return "hallo/". The returned string is decoded. QString::null is returned when there is no path. | 563 | * <tt>file:/hallo/torben</tt> would return "hallo/". The returned string is decoded. QString::null is returned when there is no path. |
562 | */ | 564 | */ |
563 | QString directory( bool _strip_trailing_slash_from_result = true, | 565 | QString directory( bool _strip_trailing_slash_from_result = true, |
564 | bool _ignore_trailing_slash_in_path = true ) const; | 566 | bool _ignore_trailing_slash_in_path = true ) const; |
565 | 567 | ||
566 | /** | 568 | /** |
567 | * Set the directory to @p dir, leaving the filename empty. | 569 | * Set the directory to @p dir, leaving the filename empty. |
568 | */ | 570 | */ |
569 | void setDirectory(const QString &dir); | 571 | void setDirectory(const QString &dir); |
570 | 572 | ||
571 | /** | 573 | /** |
572 | * Changes the directory by descending into the given directory. | 574 | * Changes the directory by descending into the given directory. |
573 | * It is assumed the current URL represents a directory. | 575 | * It is assumed the current URL represents a directory. |
574 | * If @p dir starts with a "/" the | 576 | * If @p dir starts with a "/" the |
575 | * current URL will be "protocol://host/dir" otherwise @p _dir will | 577 | * current URL will be "protocol://host/dir" otherwise @p _dir will |
576 | * be appended to the path. @p _dir can be ".." | 578 | * be appended to the path. @p _dir can be ".." |
577 | * This function won't strip protocols. That means that when you are in | 579 | * This function won't strip protocols. That means that when you are in |
578 | * file:/dir/dir2/my.tgz#tar:/ and you do cd("..") you will | 580 | * file:/dir/dir2/my.tgz#tar:/ and you do cd("..") you will |
579 | * still be in file:/dir/dir2/my.tgz#tar:/ | 581 | * still be in file:/dir/dir2/my.tgz#tar:/ |
580 | * | 582 | * |
581 | * @param _dir the directory to change to | 583 | * @param _dir the directory to change to |
582 | * @return true if successful | 584 | * @return true if successful |
583 | */ | 585 | */ |
584 | bool cd( const QString& _dir ); | 586 | bool cd( const QString& _dir ); |
585 | 587 | ||
586 | /** | 588 | /** |
587 | * Returns the URL as string, with all escape sequences intact, | 589 | * Returns the URL as string, with all escape sequences intact, |
588 | * encoded in a given charset. | 590 | * encoded in a given charset. |
589 | * This is used in particular for encoding URLs in UTF-8 before using them | 591 | * This is used in particular for encoding URLs in UTF-8 before using them |
590 | * in a drag and drop operation. | 592 | * in a drag and drop operation. |
591 | * Please note that the string returned by @ref url() will include | 593 | * Please note that the string returned by @ref url() will include |
592 | * the password of the URL. If you want to show the URL to the | 594 | * the password of the URL. If you want to show the URL to the |
593 | * user, use @ref prettyURL(). | 595 | * user, use @ref prettyURL(). |
594 | * | 596 | * |
595 | * @param _trailing This may be ( -1, 0 +1 ). -1 strips a trailing '/' from the path, +1 adds | 597 | * @param _trailing This may be ( -1, 0 +1 ). -1 strips a trailing '/' from the path, +1 adds |
596 | * a trailing '/' if there is none yet and 0 returns the | 598 | * a trailing '/' if there is none yet and 0 returns the |
597 | * path unchanged. | 599 | * path unchanged. |
598 | * @param encoding_hint MIB of encoding to use. | 600 | * @param encoding_hint MIB of encoding to use. |
599 | * @return The complete URL, with all escape sequences intact, encoded | 601 | * @return The complete URL, with all escape sequences intact, encoded |
600 | * in a given charset. | 602 | * in a given charset. |
601 | * @see QTextCodec::mibEnum() | 603 | * @see QTextCodec::mibEnum() |
602 | * @see prettyURL() | 604 | * @see prettyURL() |
603 | */ | 605 | */ |
604 | QString url( int _trailing = 0, int encoding_hint = 0) const; | 606 | QString url( int _trailing = 0, int encoding_hint = 0) const; |
605 | 607 | ||
606 | /** | 608 | /** |
607 | * Returns the URL as string in human-friendly format. | 609 | * Returns the URL as string in human-friendly format. |
608 | * Example: | 610 | * Example: |
609 | * <pre> | 611 | * <pre> |
610 | * http://localhost:8080/test.cgi?test=hello world&name=fred | 612 | * http://localhost:8080/test.cgi?test=hello world&name=fred |
611 | * </pre> | 613 | * </pre> |
612 | * @param _trailing -1 to strip a trailing '/' from the path, +1 adds | 614 | * @param _trailing -1 to strip a trailing '/' from the path, +1 adds |
613 | * a trailing '/' if there is none yet and 0 returns the | 615 | * a trailing '/' if there is none yet and 0 returns the |
614 | * path unchanged. | 616 | * path unchanged. |
615 | * @return A human readable URL, with no non-necessary encodings/escaped | 617 | * @return A human readable URL, with no non-necessary encodings/escaped |
616 | * characters. Password will not be shown. | 618 | * characters. Password will not be shown. |
617 | * @see url() | 619 | * @see url() |
618 | */ | 620 | */ |
619 | QString prettyURL( int _trailing = 0) const; | 621 | QString prettyURL( int _trailing = 0) const; |
620 | 622 | ||
621 | 623 | ||
622 | /** | 624 | /** |
623 | * Returns the URL as string, escaped for HTML. | 625 | * Returns the URL as string, escaped for HTML. |
624 | * @return A human readable URL, with no non-necessary encodings/escaped | 626 | * @return A human readable URL, with no non-necessary encodings/escaped |
625 | * characters which is html encoded for safe inclusion in html or | 627 | * characters which is html encoded for safe inclusion in html or |
626 | * rich text. Password will not be shown. | 628 | * rich text. Password will not be shown. |
627 | */ | 629 | */ |
628 | QString htmlURL() const; | 630 | QString htmlURL() const; |
629 | 631 | ||
630 | /** | 632 | /** |
631 | * Returns the URL as string, escaped for HTML. | 633 | * Returns the URL as string, escaped for HTML. |
632 | * Example: | 634 | * Example: |
633 | * <pre> | 635 | * <pre> |
634 | * http://localhost:8080/test.cgi?test=hello world&name=fred | 636 | * http://localhost:8080/test.cgi?test=hello world&name=fred |
635 | * </pre> | 637 | * </pre> |
636 | * @return A human readable URL, with no non-necessary encodings/escaped | 638 | * @return A human readable URL, with no non-necessary encodings/escaped |
637 | * characters. Password will not be shown. | 639 | * characters. Password will not be shown. |
638 | */ | 640 | */ |
639 | QString prettyURL( int _trailing, AdjustementFlags _flags) const; | 641 | QString prettyURL( int _trailing, AdjustementFlags _flags) const; |
640 | // ### BIC: Merge the two above | 642 | // ### BIC: Merge the two above |
641 | 643 | ||
642 | /** | 644 | /** |
643 | * Test to see if the KURL is empty. | 645 | * Test to see if the KURL is empty. |
644 | * @return true if the URL is empty | 646 | * @return true if the URL is empty |
645 | **/ | 647 | **/ |
646 | bool isEmpty() const; | 648 | bool isEmpty() const; |
647 | 649 | ||
648 | /** | 650 | /** |
649 | * This function is useful to implement the "Up" button in a file manager for example. | 651 | * This function is useful to implement the "Up" button in a file manager for example. |
650 | * @ref cd() never strips a sub-protocol. That means that if you are in | 652 | * @ref cd() never strips a sub-protocol. That means that if you are in |
651 | * file:/home/x.tgz#gzip:/#tar:/ and hit the up button you expect to see | 653 | * file:/home/x.tgz#gzip:/#tar:/ and hit the up button you expect to see |
652 | * file:/home. The algorithm tries to go up on the right-most URL. If that is not | 654 | * file:/home. The algorithm tries to go up on the right-most URL. If that is not |
653 | * possible it strips the right most URL. It continues stripping URLs. | 655 | * possible it strips the right most URL. It continues stripping URLs. |
654 | * @return a URL that is a level higher | 656 | * @return a URL that is a level higher |
655 | */ | 657 | */ |
656 | KURL upURL( ) const; | 658 | KURL upURL( ) const; |
657 | 659 | ||
658 | KURL& operator=( const KURL& _u ); | 660 | KURL& operator=( const KURL& _u ); |
659 | KURL& operator=( const QString& _url ); | 661 | KURL& operator=( const QString& _url ); |
660 | KURL& operator=( const char * _url ); | 662 | KURL& operator=( const char * _url ); |
661 | KURL& operator=( const QUrl & u ); | 663 | KURL& operator=( const Q3Url & u ); |
662 | 664 | ||
663 | bool operator==( const KURL& _u ) const; | 665 | bool operator==( const KURL& _u ) const; |
664 | bool operator==( const QString& _u ) const; | 666 | bool operator==( const QString& _u ) const; |
665 | bool operator!=( const KURL& _u ) const { return !( *this == _u ); } | 667 | bool operator!=( const KURL& _u ) const { return !( *this == _u ); } |
666 | bool operator!=( const QString& _u ) const { return !( *this == _u ); } | 668 | bool operator!=( const QString& _u ) const { return !( *this == _u ); } |
667 | 669 | ||
668 | /** | 670 | /** |
669 | * The same as equals(), just with a less obvious name. | 671 | * The same as equals(), just with a less obvious name. |
670 | * Compares this url with @p u. | 672 | * Compares this url with @p u. |
671 | * @param ignore_trailing set to true to ignore trailing '/' characters. | 673 | * @param ignore_trailing set to true to ignore trailing '/' characters. |
672 | * @return true if both urls are the same | 674 | * @return true if both urls are the same |
673 | * @see operator==. This function should be used if you want to | 675 | * @see operator==. This function should be used if you want to |
674 | * ignore trailing '/' characters. | 676 | * ignore trailing '/' characters. |
675 | * @deprecated | 677 | * @deprecated |
676 | */ | 678 | */ |
677 | bool cmp( const KURL &u, bool ignore_trailing = false ) const; | 679 | bool cmp( const KURL &u, bool ignore_trailing = false ) const; |
678 | 680 | ||
679 | /** | 681 | /** |
680 | * Compares this url with @p u. | 682 | * Compares this url with @p u. |
681 | * @param ignore_trailing set to true to ignore trailing '/' characters. | 683 | * @param ignore_trailing set to true to ignore trailing '/' characters. |
682 | * @return true if both urls are the same | 684 | * @return true if both urls are the same |
683 | * @see operator==. This function should be used if you want to | 685 | * @see operator==. This function should be used if you want to |
684 | * ignore trailing '/' characters. | 686 | * ignore trailing '/' characters. |
685 | * @since 3.1 | 687 | * @since 3.1 |
686 | */ | 688 | */ |
687 | bool equals( const KURL &u, bool ignore_trailing = false ) const; | 689 | bool equals( const KURL &u, bool ignore_trailing = false ) const; |
688 | 690 | ||
689 | /** | 691 | /** |
690 | * Checks whether the given URL is parent of this URL. | 692 | * Checks whether the given URL is parent of this URL. |
691 | * For instance, ftp://host/dir/ is a parent of ftp://host/dir/subdir/subsubdir/. | 693 | * For instance, ftp://host/dir/ is a parent of ftp://host/dir/subdir/subsubdir/. |
692 | * @return true if this url is a parent of @p u (or the same URL as @p u) | 694 | * @return true if this url is a parent of @p u (or the same URL as @p u) |
693 | */ | 695 | */ |
694 | bool isParentOf( const KURL& u ) const; | 696 | bool isParentOf( const KURL& u ) const; |
695 | 697 | ||
696 | /** | 698 | /** |
697 | * Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase | 699 | * Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase |
698 | * A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in | 700 | * A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in |
699 | * http://www.kde.org and tar:/kde/README.html#ref1. | 701 | * http://www.kde.org and tar:/kde/README.html#ref1. |
700 | * That means in turn that "#ref1" is an HTML-style reference and not a new sub URL. | 702 | * That means in turn that "#ref1" is an HTML-style reference and not a new sub URL. |
701 | * Since HTML-style references mark | 703 | * Since HTML-style references mark |
702 | * a certain position in a document this reference is appended to every URL. | 704 | * a certain position in a document this reference is appended to every URL. |
703 | * The idea behind this is that browsers, for example, only look at the first URL while | 705 | * The idea behind this is that browsers, for example, only look at the first URL while |
704 | * the rest is not of interest to them. | 706 | * the rest is not of interest to them. |
705 | * | 707 | * |
706 | * | 708 | * |
707 | * @param _url The URL that has to be split. | 709 | * @param _url The URL that has to be split. |
708 | * @return An empty list on error or the list of split URLs. | 710 | * @return An empty list on error or the list of split URLs. |
709 | * @see #hasSubURL | 711 | * @see #hasSubURL |
710 | */ | 712 | */ |
711 | static List split( const QString& _url ); | 713 | static List split( const QString& _url ); |
712 | 714 | ||
713 | /** | 715 | /** |
714 | * Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase | 716 | * Splits nested URLs like file:/home/weis/kde.tgz#gzip:/#tar:/kdebase |
715 | * A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in | 717 | * A URL like http://www.kde.org#tar:/kde/README.hml#ref1 will be split in |
716 | * http://www.kde.org and tar:/kde/README.html#ref1. | 718 | * http://www.kde.org and tar:/kde/README.html#ref1. |
717 | * That means in turn that "#ref1" is an HTML-style reference and not a new sub URL. | 719 | * That means in turn that "#ref1" is an HTML-style reference and not a new sub URL. |
718 | * Since HTML-style references mark | 720 | * Since HTML-style references mark |
719 | * a certain position in a document this reference is appended to every URL. | 721 | * a certain position in a document this reference is appended to every URL. |
720 | * The idea behind this is that browsers, for example, only look at the first URL while | 722 | * The idea behind this is that browsers, for example, only look at the first URL while |
721 | * the rest is not of interest to them. | 723 | * the rest is not of interest to them. |
722 | * | 724 | * |
723 | * @return An empty list on error or the list of split URLs. | 725 | * @return An empty list on error or the list of split URLs. |
724 | * | 726 | * |
725 | * @param _url The URL that has to be split. | 727 | * @param _url The URL that has to be split. |
726 | * @see #hasSubURL | 728 | * @see #hasSubURL |
727 | */ | 729 | */ |
728 | static List split( const KURL& _url ); | 730 | static List split( const KURL& _url ); |
729 | 731 | ||
730 | /** | 732 | /** |
731 | * Reverses @ref #split(). Only the first URL may have a reference. This reference | 733 | * Reverses @ref #split(). Only the first URL may have a reference. This reference |
732 | * is considered to be HTML-like and is appended at the end of the resulting | 734 | * is considered to be HTML-like and is appended at the end of the resulting |
733 | * joined URL. | 735 | * joined URL. |
734 | * @param _list the list to join | 736 | * @param _list the list to join |
735 | * @return the joined URL | 737 | * @return the joined URL |
736 | */ | 738 | */ |
737 | static KURL join( const List& _list ); | 739 | static KURL join( const List& _list ); |
738 | 740 | ||
739 | /** | 741 | /** |
740 | * Creates a KURL object from a QString representing either an absolute path | 742 | * Creates a KURL object from a QString representing either an absolute path |
741 | * or a real URL. Use this method instead of | 743 | * or a real URL. Use this method instead of |
742 | * <pre> | 744 | * <pre> |
743 | * QString someDir = ... | 745 | * QString someDir = ... |
744 | * KURL url = someDir; | 746 | * KURL url = someDir; |
745 | * </pre> | 747 | * </pre> |
746 | * | 748 | * |
747 | * Otherwise some characters (e.g. the '#') won't be encoded properly. | 749 | * Otherwise some characters (e.g. the '#') won't be encoded properly. |
748 | * @param text the string representation of the URL to convert | 750 | * @param text the string representation of the URL to convert |
749 | * @return the new KURL | 751 | * @return the new KURL |
750 | * @since 3.1 | 752 | * @since 3.1 |
751 | */ | 753 | */ |
752 | static KURL fromPathOrURL( const QString& text ); | 754 | static KURL fromPathOrURL( const QString& text ); |
753 | 755 | ||
754 | /** | 756 | /** |
755 | * Convenience function. | 757 | * Convenience function. |
756 | * | 758 | * |
757 | * Convert unicoded string to local encoding and use %-style | 759 | * Convert unicoded string to local encoding and use %-style |
758 | * encoding for all common delimiters / non-ascii characters. | 760 | * encoding for all common delimiters / non-ascii characters. |
759 | * @param str String to encode (can be QString::null). | 761 | * @param str String to encode (can be QString::null). |
760 | * @param encoding_hint MIB of encoding to use. | 762 | * @param encoding_hint MIB of encoding to use. |
761 | * @see QTextCodec::mibEnum() | 763 | * @see QTextCodec::mibEnum() |
762 | * @return the encoded string | 764 | * @return the encoded string |
763 | **/ | 765 | **/ |
764 | static QString encode_string(const QString &str, int encoding_hint = 0); | 766 | static QString encode_string(const QString &str, int encoding_hint = 0); |
765 | 767 | ||
766 | /** | 768 | /** |
767 | * Convenience function. | 769 | * Convenience function. |
768 | * | 770 | * |
769 | * Convert unicoded string to local encoding and use %-style | 771 | * Convert unicoded string to local encoding and use %-style |
770 | * encoding for all common delimiters / non-ascii characters | 772 | * encoding for all common delimiters / non-ascii characters |
771 | * as well as the slash '/'. | 773 | * as well as the slash '/'. |
772 | * @param str String to encode | 774 | * @param str String to encode |
773 | * @param encoding_hint MIB of encoding to use. | 775 | * @param encoding_hint MIB of encoding to use. |
774 | * @see QTextCodec::mibEnum() | 776 | * @see QTextCodec::mibEnum() |
775 | **/ | 777 | **/ |
776 | static QString encode_string_no_slash(const QString &str, int encoding_hint = 0); | 778 | static QString encode_string_no_slash(const QString &str, int encoding_hint = 0); |
777 | 779 | ||
778 | /** | 780 | /** |
779 | * Convenience function. | 781 | * Convenience function. |
780 | * | 782 | * |
781 | * Decode %-style encoding and convert from local encoding to unicode. | 783 | * Decode %-style encoding and convert from local encoding to unicode. |
782 | * | 784 | * |
783 | * Reverse of encode_string() | 785 | * Reverse of encode_string() |
784 | * @param str String to decode (can be QString::null). | 786 | * @param str String to decode (can be QString::null). |
785 | * @param encoding_hint MIB of original encoding of @p str . | 787 | * @param encoding_hint MIB of original encoding of @p str . |
786 | * @see QTextCodec::mibEnum() | 788 | * @see QTextCodec::mibEnum() |
787 | **/ | 789 | **/ |
788 | static QString decode_string(const QString &str, int encoding_hint = 0); | 790 | static QString decode_string(const QString &str, int encoding_hint = 0); |
789 | 791 | ||
790 | /** | 792 | /** |
791 | * Convenience function. | 793 | * Convenience function. |
792 | * | 794 | * |
793 | * Returns whether '_url' is likely to be a "relative" URL instead of | 795 | * Returns whether '_url' is likely to be a "relative" URL instead of |
794 | * an "absolute" URL. | 796 | * an "absolute" URL. |
795 | * @param _url URL to examine | 797 | * @param _url URL to examine |
796 | * @return true when the URL is likely to be "relative", false otherwise. | 798 | * @return true when the URL is likely to be "relative", false otherwise. |
797 | */ | 799 | */ |
798 | static bool isRelativeURL(const QString &_url); | 800 | static bool isRelativeURL(const QString &_url); |
799 | 801 | ||
800 | #ifdef KDE_NO_COMPAT | 802 | #ifdef KDE_NO_COMPAT |
801 | private: | 803 | private: |
802 | #endif | 804 | #endif |
803 | QString filename( bool _ignore_trailing_slash_in_path = true ) const | 805 | QString filename( bool _ignore_trailing_slash_in_path = true ) const |
804 | { | 806 | { |
805 | return fileName(_ignore_trailing_slash_in_path); | 807 | return fileName(_ignore_trailing_slash_in_path); |
806 | } | 808 | } |
807 | 809 | ||
808 | protected: | 810 | protected: |
809 | void reset(); | 811 | void reset(); |
810 | void parse( const QString& _url, int encoding_hint = 0); | 812 | void parse( const QString& _url, int encoding_hint = 0); |
811 | 813 | ||
812 | private: | 814 | private: |
813 | QString m_strProtocol; | 815 | QString m_strProtocol; |
814 | QString m_strUser; | 816 | QString m_strUser; |
815 | QString m_strPass; | 817 | QString m_strPass; |
816 | QString m_strHost; | 818 | QString m_strHost; |
817 | QString m_strPath; | 819 | QString m_strPath; |
818 | QString m_strRef_encoded; | 820 | QString m_strRef_encoded; |
819 | QString m_strQuery_encoded; | 821 | QString m_strQuery_encoded; |
820 | bool m_bIsMalformed : 1; | 822 | bool m_bIsMalformed : 1; |
821 | int freeForUse : 7; | 823 | int freeForUse : 7; |
822 | unsigned short int m_iPort; | 824 | unsigned short int m_iPort; |
823 | QString m_strPath_encoded; | 825 | QString m_strPath_encoded; |
824 | 826 | ||
825 | friend QDataStream & operator<< (QDataStream & s, const KURL & a); | 827 | friend QDataStream & operator<< (QDataStream & s, const KURL & a); |
826 | friend QDataStream & operator>> (QDataStream & s, KURL & a); | 828 | friend QDataStream & operator>> (QDataStream & s, KURL & a); |
827 | private: | 829 | private: |
828 | KURLPrivate* d; | 830 | KURLPrivate* d; |
829 | }; | 831 | }; |
830 | 832 | ||
831 | /** | 833 | /** |
832 | * Compares URLs. They are parsed, split and compared. | 834 | * Compares URLs. They are parsed, split and compared. |
833 | * Two malformed URLs with the same string representation | 835 | * Two malformed URLs with the same string representation |
834 | * are nevertheless considered to be unequal. | 836 | * are nevertheless considered to be unequal. |
835 | * That means no malformed URL equals anything else. | 837 | * That means no malformed URL equals anything else. |
836 | */ | 838 | */ |
837 | bool urlcmp( const QString& _url1, const QString& _url2 ); | 839 | bool urlcmp( const QString& _url1, const QString& _url2 ); |
838 | 840 | ||
839 | /** | 841 | /** |
840 | * Compares URLs. They are parsed, split and compared. | 842 | * Compares URLs. They are parsed, split and compared. |
841 | * Two malformed URLs with the same string representation | 843 | * Two malformed URLs with the same string representation |
842 | * are nevertheless considered to be unequal. | 844 | * are nevertheless considered to be unequal. |
843 | * That means no malformed URL equals anything else. | 845 | * That means no malformed URL equals anything else. |
844 | * | 846 | * |
845 | * @param _ignore_trailing Described in @ref KURL::cmp | 847 | * @param _ignore_trailing Described in @ref KURL::cmp |
846 | * @param _ignore_ref If true, disables comparison of HTML-style references. | 848 | * @param _ignore_ref If true, disables comparison of HTML-style references. |
847 | */ | 849 | */ |
848 | bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref ); | 850 | bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref ); |
849 | 851 | ||
850 | QDataStream & operator<< (QDataStream & s, const KURL & a); | 852 | QDataStream & operator<< (QDataStream & s, const KURL & a); |
851 | QDataStream & operator>> (QDataStream & s, KURL & a); | 853 | QDataStream & operator>> (QDataStream & s, KURL & a); |
852 | 854 | ||
853 | #endif | 855 | #endif |