1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes 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
****************************************************************************/
33
#include "q3cstring.h"
38
// used by q3filedialog.cpp
39
bool qt_resolve_symlinks = true;
48
QString path, cleanPath;
57
Replaces backslashes with slashes and removes multiple occurrences
58
of slashes or backslashes if \c allowMultiple is false.
61
static void slashify( QString& s, bool allowMultiple = true )
63
bool justHadSlash = false;
64
for ( int i = 0; i < (int)s.length(); i++ ) {
65
if ( !allowMultiple && justHadSlash &&
66
( s[ i ] == '/' || s[ i ] == '\\' ) ) {
73
#if defined (Q_WS_MAC9)
74
if ( s[ i ] == ':' && (i == (int)s.length()-1 || s[ i + 1 ] != '/' ) ) //mac colon's go away, unless after a protocol
88
\brief The Q3Url class provides a URL parser and simplifies working with URLs.
92
The Q3Url class is provided for simple work with URLs. It can
93
parse, decode, encode, etc.
95
Q3Url works with the decoded path and encoded query in turn.
99
<tt>http://www.trolltech.com:80/cgi-bin/test%20me.pl?cmd=Hello%20you</tt>
102
\header \i Function \i Returns
103
\row \i \l protocol() \i "http"
104
\row \i \l host() \i "www.trolltech.com"
105
\row \i \l port() \i 80
106
\row \i \l path() \i "/cgi-bin/test me.pl"
107
\row \i \l fileName() \i "test me.pl"
108
\row \i \l query() \i "cmd=Hello%20you"
113
<tt>http://doc.trolltech.com/qdockarea.html#lines</tt>
116
\header \i Function \i Returns
117
\row \i \l protocol() \i "http"
118
\row \i \l host() \i "doc.trolltech.com"
119
\row \i \l fileName() \i "qdockarea.html"
120
\row \i \l ref() \i "lines"
123
The individual parts of a URL can be set with setProtocol(),
124
setHost(), setPort(), setPath(), setFileName(), setRef() and
125
setQuery(). A URL could contain, for example, an ftp address which
126
requires a user name and password; these can be set with setUser()
129
Because path is always encoded internally you must not use "%00"
130
in the path, although this is okay (but not recommended) for the
133
Q3Url is normally used like this:
136
Q3Url url( "http://www.trolltech.com" );
138
Q3Url url( "file:/home/myself/Mail", "Inbox" );
141
You can then access and manipulate the various parts of the URL.
143
To make it easy to work with Q3Urls and QStrings, Q3Url implements
144
the necessary cast and assignment operators so you can do
148
Q3Url url( "http://www.trolltech.com" );
151
QString s( "http://www.trolltech.com" );
155
Use the static functions, encode() and decode() to encode or
156
decode a URL in a string. (They operate on the string in-place.)
157
The isRelativeUrl() static function returns true if the given
158
string is a relative URL.
160
If you want to use a URL to work on a hierarchical structure (e.g.
161
a local or remote filesystem), you might want to use the subclass
169
Constructs an empty URL that is invalid.
174
d = new Q3UrlPrivate;
177
d->cleanPathDirty = true;
181
Constructs a URL by parsing the string \a url.
183
If you pass a string like "/home/qt", the "file" protocol is
187
Q3Url::Q3Url( const QString& url )
189
d = new Q3UrlPrivate;
190
d->protocol = "file";
196
Copy constructor. Copies the data of \a url.
199
Q3Url::Q3Url( const Q3Url& url )
201
d = new Q3UrlPrivate;
206
Returns true if \a url is relative; otherwise returns false.
209
bool Q3Url::isRelativeUrl( const QString &url )
211
int colon = url.find( ":" );
212
int slash = url.find( "/" );
214
return ( slash != 0 && ( colon == -1 || ( slash != -1 && colon > slash ) ) );
218
Constructs an URL taking \a url as the base (context) and
219
\a relUrl as a relative URL to \a url. If \a relUrl is not relative,
220
\a relUrl is taken as the new URL.
222
For example, the path of
224
Q3Url url( "ftp://ftp.trolltech.com/qt/source", "qt-2.1.0.tar.gz" );
226
will be "/qt/srource/qt-2.1.0.tar.gz".
230
Q3Url url( "ftp://ftp.trolltech.com/qt/source", "/usr/local" );
232
will result in a new URL, "ftp://ftp.trolltech.com/usr/local",
233
because "/usr/local" isn't relative.
237
Q3Url url( "ftp://ftp.trolltech.com/qt/source", "file:/usr/local" );
239
will result in a new URL, with "/usr/local" as the path
240
and "file" as the protocol.
242
Normally it is expected that the path of \a url points to a
243
directory, even if the path has no slash at the end. But if you
244
want the constructor to handle the last part of the path as a file
245
name if there is no slash at the end, and to let it be replaced by
246
the file name of \a relUrl (if it contains one), set \a checkSlash
250
Q3Url::Q3Url( const Q3Url& url, const QString& relUrl, bool checkSlash )
252
d = new Q3UrlPrivate;
253
QString rel = relUrl;
257
if ( !urlTmp.isValid() ) {
260
if ( isRelativeUrl( rel ) ) {
261
if ( rel[ 0 ] == '#' ) {
263
rel.remove( (uint)0, 1 );
266
} else if ( rel[ 0 ] == '?' ) {
268
rel.remove( (uint)0, 1 );
274
if ( checkSlash && d->cleanPath[(int)path().length()-1] != '/' ) {
275
if ( isRelativeUrl( path() ) )
276
setEncodedPathAndQuery( rel );
280
QString p = urlTmp.path();
282
// allow URLs like "file:foo"
283
if ( !d->host.isEmpty() && !d->user.isEmpty() && !d->pass.isEmpty() )
286
if ( !p.isEmpty() && p.right(1)!="/" )
290
d->cleanPathDirty = true;
294
if ( rel[ 0 ] == QChar( '/' ) ) {
296
setEncodedPathAndQuery( rel );
314
Returns the protocol of the URL. Typically, "file", "http", "ftp",
320
QString Q3Url::protocol() const
326
Sets the protocol of the URL to \a protocol. Typically, "file",
332
void Q3Url::setProtocol( const QString& protocol )
334
d->protocol = protocol;
340
Returns the username of the URL.
342
\sa setUser() setPassword()
345
QString Q3Url::user() const
351
Sets the username of the URL to \a user.
353
\sa user() setPassword()
356
void Q3Url::setUser( const QString& user )
362
Returns true if the URL contains a username; otherwise returns
365
\sa setUser() setPassword()
368
bool Q3Url::hasUser() const
370
return !d->user.isEmpty();
374
Returns the password of the URL.
376
\warning Passwords passed in URLs are normally \e insecure; this
377
is due to the mechanism, not because of Qt.
379
\sa setPassword() setUser()
382
QString Q3Url::password() const
388
Sets the password of the URL to \a pass.
390
\warning Passwords passed in URLs are normally \e insecure; this
391
is due to the mechanism, not because of Qt.
393
\sa password() setUser()
396
void Q3Url::setPassword( const QString& pass )
402
Returns true if the URL contains a password; otherwise returns
405
\warning Passwords passed in URLs are normally \e insecure; this
406
is due to the mechanism, not because of Qt.
408
\sa setPassword() setUser()
411
bool Q3Url::hasPassword() const
413
return !d->pass.isEmpty();
417
Returns the hostname of the URL.
419
\sa setHost() hasHost()
422
QString Q3Url::host() const
428
Sets the hostname of the URL to \a host.
433
void Q3Url::setHost( const QString& host )
436
if ( !d->protocol.isNull() && d->protocol != "file" )
441
Returns true if the URL contains a hostname; otherwise returns
447
bool Q3Url::hasHost() const
449
return !d->host.isEmpty();
453
Returns the port of the URL or -1 if no port has been set.
458
int Q3Url::port() const
464
Sets the port of the URL to \a port.
469
void Q3Url::setPort( int port )
475
Returns true if the URL contains a port; otherwise returns false.
480
bool Q3Url::hasPort() const
486
Sets the path of the URL to \a path.
491
void Q3Url::setPath( const QString& path )
495
d->cleanPathDirty = true;
500
Returns true if the URL contains a path; otherwise returns false.
505
bool Q3Url::hasPath() const
507
return !d->path.isEmpty();
511
Sets the query of the URL to \a txt. \a txt must be encoded.
516
void Q3Url::setQuery( const QString& txt )
518
d->queryEncoded = txt;
522
Returns the (encoded) query of the URL.
524
\sa setQuery() decode()
527
QString Q3Url::query() const
529
return d->queryEncoded;
533
Returns the (encoded) reference of the URL.
535
\sa setRef() hasRef() decode()
538
QString Q3Url::ref() const
540
return d->refEncoded;
544
Sets the reference of the URL to \a txt. \a txt must be encoded.
546
\sa ref() hasRef() encode()
549
void Q3Url::setRef( const QString& txt )
555
Returns true if the URL has a reference; otherwise returns false.
560
bool Q3Url::hasRef() const
562
return !d->refEncoded.isEmpty();
566
Returns true if the URL is valid; otherwise returns false. A URL
567
is invalid if it cannot be parsed, for example.
570
bool Q3Url::isValid() const
576
Resets all parts of the URL to their default values and
582
d->protocol = "file";
587
d->queryEncoded = "";
591
d->cleanPathDirty = true;
598
bool Q3Url::parse( const QString& url )
603
if ( url_.isEmpty() ) {
608
d->cleanPathDirty = true;
610
QString oldProtocol = d->protocol;
614
const int Protocol = 1;
615
const int Separator1= 2; // :
616
const int Separator2= 3; // :/
617
const int Separator3= 4; // :// or more slashes
623
const int Query = 10;
627
const int InputAlpha= 1;
628
const int InputDigit= 2;
629
const int InputSlash= 3;
630
const int InputColon= 4;
631
const int InputAt = 5;
632
const int InputHash = 6;
633
const int InputQuery= 7;
635
static uchar table[ 12 ][ 8 ] = {
636
/* None InputAlpha InputDigit InputSlash InputColon InputAt InputHash InputQuery */
637
{ 0, Protocol, 0, Path, 0, 0, 0, 0, }, // Init
638
{ 0, Protocol, Protocol, 0, Separator1, 0, 0, 0, }, // Protocol
639
{ 0, Path, Path, Separator2, 0, 0, 0, 0, }, // Separator1
640
{ 0, Path, Path, Separator3, 0, 0, 0, 0, }, // Separator2
641
{ 0, User, User, Separator3, Pass, Host, 0, 0, }, // Separator3
642
{ 0, User, User, User, Pass, Host, User, User, }, // User
643
{ 0, Pass, Pass, Pass, Pass, Host, Pass, Pass, }, // Pass
644
{ 0, Host, Host, Path, Port, Host, Ref, Query, }, // Host
645
{ 0, Path, Path, Path, Path, Path, Ref, Query, }, // Path
646
{ 0, Ref, Ref, Ref, Ref, Ref, Ref, Query, }, // Ref
647
{ 0, Query, Query, Query, Query, Query, Query, Query, }, // Query
648
{ 0, 0, Port, Path, 0, 0, 0, 0, } // Port
651
bool relPath = false;
654
bool forceRel = false;
656
// If ':' is at pos 1, we have only one letter
657
// before that separator => that's a drive letter!
658
if ( url_.length() >= 2 && url_[1] == ':' )
659
relPath = forceRel = true;
662
int cs = url_.find( ":/" );
663
if ( cs != -1 ) // if a protocol is there, find out if there is a host or directly the path after it
664
hasNoHost = url_.find( "///", cs );
665
table[ 4 ][ 1 ] = User;
666
table[ 4 ][ 2 ] = User;
667
if ( cs == -1 || forceRel ) { // we have a relative file
668
if ( url.find( ':' ) == -1 || forceRel ) {
669
table[ 0 ][ 1 ] = Path;
670
// Filenames may also begin with a digit
671
table[ 0 ][ 2 ] = Path;
673
table[ 0 ][ 1 ] = Protocol;
676
} else { // some checking
677
table[ 0 ][ 1 ] = Protocol;
679
// find the part between the protocol and the path as the meaning
680
// of that part is dependend on some chars
682
while ( url_[ cs ] == '/' )
684
int slash = url_.find( "/", cs );
686
slash = url_.length() - 1;
687
QString tmp = url_.mid( cs, slash - cs + 1 );
689
if ( !tmp.isEmpty() ) { // if this part exists
691
// look for the @ in this part
692
int at = tmp.find( "@" );
695
// we have no @, which means host[:port], so directly
696
// after the protocol the host starts, or if the protocol
697
// is file or there were more than 2 slashes, itļæ½ļæ½s the
700
if ( url_.left( 4 ) == "file" || hasNoHost != -1 )
701
table[ 4 ][ 1 ] = Path;
703
table[ 4 ][ 1 ] = Host;
704
table[ 4 ][ 2 ] = table[ 4 ][ 1 ];
709
int state = Init; // parse state
710
int input; // input token
717
switch ( c.latin1() ) {
733
case '1': case '2': case '3': case '4': case '5':
734
case '6': case '7': case '8': case '9': case '0':
741
state = table[ state ][ input ];
763
d->queryEncoded += c;
773
if ( i > (int)url_.length() - 1 || state == Done || state == 0 )
779
if ( !port.isEmpty() ) {
780
port.remove( (uint)0, 1 );
781
d->port = atoi( port.latin1() );
785
if ( i < (int)url_.length() - 1 ) {
791
if ( d->protocol.isEmpty() )
792
d->protocol = oldProtocol;
794
if ( d->path.isEmpty() )
798
if ( d->path.length() == 2 && d->path[ 1 ] == ':' )
801
// #### do some corrections, should be done nicer too
802
if ( !d->pass.isEmpty() ) {
803
if ( d->pass[ 0 ] == ':' )
804
d->pass.remove( (uint)0, 1 );
807
if ( !d->user.isEmpty() ) {
810
if ( !d->path.isEmpty() ) {
811
if ( d->path[ 0 ] == '@' || d->path[ 0 ] == ':' )
812
d->path.remove( (uint)0, 1 );
813
if ( d->path[ 0 ] != '/' && !relPath && d->path[ 1 ] != ':' )
814
d->path.prepend( "/" );
816
if ( !d->refEncoded.isEmpty() && d->refEncoded[ 0 ] == '#' )
817
d->refEncoded.remove( (uint)0, 1 );
818
if ( !d->queryEncoded.isEmpty() && d->queryEncoded[ 0 ] == '?' )
819
d->queryEncoded.remove( (uint)0, 1 );
820
if ( !d->host.isEmpty() && d->host[ 0 ] == '@' )
821
d->host.remove( (uint)0, 1 );
823
#if defined(Q_OS_WIN32)
824
// hack for windows file://machine/path syntax
825
if ( d->protocol == "file" ) {
826
if ( url.left( 7 ) == "file://" &&
827
d->path.length() > 1 && d->path[ 1 ] != ':' )
828
d->path.prepend( "/" );
833
d->cleanPathDirty = true;
836
qDebug( "URL: %s", url.latin1() );
837
qDebug( "protocol: %s", d->protocol.latin1() );
838
qDebug( "user: %s", d->user.latin1() );
839
qDebug( "pass: %s", d->pass.latin1() );
840
qDebug( "host: %s", d->host.latin1() );
841
qDebug( "path: %s", path().latin1() );
842
qDebug( "ref: %s", d->refEncoded.latin1() );
843
qDebug( "query: %s", d->queryEncoded.latin1() );
844
qDebug( "port: %d\n\n----------------------------\n\n", d->port );
853
Parses \a url and assigns the resulting data to this class.
855
If you pass a string like "/home/qt" the "file" protocol will be
859
Q3Url& Q3Url::operator=( const QString& url )
868
Assigns the data of \a url to this class.
871
Q3Url& Q3Url::operator=( const Q3Url& url )
878
Compares this URL with \a url and returns true if they are equal;
879
otherwise returns false.
882
bool Q3Url::operator==( const Q3Url& url ) const
884
if ( !isValid() || !url.isValid() )
887
if ( d->protocol == url.d->protocol &&
888
d->user == url.d->user &&
889
d->pass == url.d->pass &&
890
d->host == url.d->host &&
891
d->path == url.d->path &&
892
d->queryEncoded == url.d->queryEncoded &&
893
d->refEncoded == url.d->refEncoded &&
894
d->isValid == url.d->isValid &&
895
d->port == url.d->port )
904
Compares this URL with \a url. \a url is parsed first. Returns
905
true if \a url is equal to this url; otherwise returns false.
908
bool Q3Url::operator==( const QString& url ) const
911
return ( *this == u );
915
Sets the file name of the URL to \a name. If this URL contains a
916
fileName(), the original file name is replaced by \a name.
918
See the documentation of fileName() for a more detailed discussion
919
of what is handled as file name and what is handled as a directory
925
void Q3Url::setFileName( const QString& name )
930
while ( fn[ 0 ] == '/' )
931
fn.remove( (uint)0, 1 );
934
if ( path().isEmpty() ) {
938
int slash = p.findRev( QChar( '/' ) );
941
} else if ( p[ (int)p.length() - 1 ] != '/' ) {
942
p.truncate( slash + 1 );
947
if ( !d->queryEncoded.isEmpty() )
948
p += "?" + d->queryEncoded;
949
setEncodedPathAndQuery( p );
953
Returns the encoded path and query.
958
QString Q3Url::encodedPathAndQuery()
966
if ( !d->queryEncoded.isEmpty() ) {
968
p += d->queryEncoded;
975
Parses \a pathAndQuery for a path and query and sets those values.
976
The whole string must be encoded.
981
void Q3Url::setEncodedPathAndQuery( const QString& pathAndQuery )
983
d->cleanPathDirty = true;
984
int pos = pathAndQuery.find( '?' );
986
d->path = pathAndQuery;
987
d->queryEncoded = "";
989
d->path = pathAndQuery.left( pos );
990
d->queryEncoded = pathAndQuery.mid( pos + 1 );
994
d->cleanPathDirty = true;
998
Returns the path of the URL. If \a correct is true, the path is
999
cleaned (deals with too many or too few slashes, cleans things
1000
like "/../..", etc). Otherwise path() returns exactly the path
1001
that was parsed or set.
1003
\sa setPath() hasPath()
1005
QString Q3Url::path( bool correct ) const
1010
if ( d->cleanPathDirty ) {
1012
if ( QDir::isRelativePath( d->path ) ) {
1013
d->cleanPath = d->path;
1014
} else if ( isLocalFile() ) {
1015
#if defined(Q_OS_WIN32)
1016
// hack for stuff like \\machine\path and //machine/path on windows
1017
if ( ( d->path.left( 1 ) == "/" || d->path.left( 1 ) == "\\" ) &&
1018
d->path.length() > 1 ) {
1019
d->cleanPath = d->path;
1020
bool share = (d->cleanPath[0] == '\\' && d->cleanPath[1] == '\\') ||
1021
(d->cleanPath[0] == '/' && d->cleanPath[1] == '/');
1022
slashify( d->cleanPath, false );
1023
d->cleanPath = QDir::cleanDirPath( d->cleanPath );
1026
while (d->cleanPath.at(0) != '/' || d->cleanPath.at(1) != '/')
1027
d->cleanPath.prepend("/");
1032
QFileInfo fi( d->path );
1034
d->cleanPath = d->path;
1035
else if ( fi.isDir() ) {
1036
QString canPath = QDir( d->path ).canonicalPath();
1038
if ( qt_resolve_symlinks && !canPath.isNull() )
1039
dir = QDir::cleanDirPath( canPath );
1041
dir = QDir::cleanDirPath( QDir( d->path ).absPath() );
1049
QDir::cleanDirPath( (qt_resolve_symlinks ?
1050
fi.dir().canonicalPath() :
1051
fi.dir().absPath()) );
1052
d->cleanPath = p + "/" + fi.fileName();
1056
if ( d->path != "/" && d->path[ (int)d->path.length() - 1 ] == '/' )
1057
d->cleanPath = QDir::cleanDirPath( d->path ) + "/";
1059
d->cleanPath = QDir::cleanDirPath( d->path );
1063
slashify( d->cleanPath, false );
1064
d->cleanPathDirty = false;
1067
return d->cleanPath;
1071
Returns true if the URL is a local file; otherwise returns false.
1074
bool Q3Url::isLocalFile() const
1076
return d->protocol == "file";
1080
Returns the file name of the URL. If the path of the URL doesn't
1081
have a slash at the end, the part between the last slash and the
1082
end of the path string is considered to be the file name. If the
1083
path has a slash at the end, an empty string is returned here.
1088
QString Q3Url::fileName() const
1090
if ( d->path.isEmpty() || d->path.endsWith( "/" )
1092
|| d->path.endsWith( "\\" )
1097
return QFileInfo( d->path ).fileName();
1101
Adds the path \a pa to the path of the URL.
1103
\sa setPath() hasPath()
1106
void Q3Url::addPath( const QString& pa )
1114
if ( path().isEmpty() ) {
1115
if ( p[ 0 ] != QChar( '/' ) )
1120
if ( p[ 0 ] != QChar( '/' ) && d->path[ (int)d->path.length() - 1 ] != '/' )
1125
d->cleanPathDirty = true;
1129
Returns the directory path of the URL. This is the part of the
1130
path of the URL without the fileName(). See the documentation of
1131
fileName() for a discussion of what is handled as file name and
1132
what is handled as directory path.
1134
\sa setPath() hasPath()
1137
QString Q3Url::dirPath() const
1139
if ( path().isEmpty() )
1143
int pos = s.findRev( '/' );
1145
return QString::fromLatin1(".");
1148
return QString::fromLatin1( "/" );
1149
return s.left( pos );
1154
Encodes the \a url in-place into UTF-8. For example
1157
QString url = http://www.trolltech.com
1158
Q3Url::encode( url );
1159
// url is now "http%3A//www%20trolltech%20com"
1165
void Q3Url::encode( QString& url )
1167
if ( url.isEmpty() )
1170
Q3CString curl = url.utf8();
1171
int oldlen = curl.length();
1173
const Q3CString special( "+<>#@\"&%$:,;?={}|^~[]\'`\\ \n\t\r" );
1177
for ( int i = 0; i < oldlen ;++i ) {
1178
uchar inCh = (uchar)curl[ i ];
1180
if ( inCh >= 128 || special.contains(inCh) ) {
1181
newUrl[ newlen++ ] = QChar( '%' );
1183
ushort c = inCh / 16;
1184
c += c > 9 ? 'A' - 10 : '0';
1185
newUrl[ newlen++ ] = c;
1188
c += c > 9 ? 'A' - 10 : '0';
1189
newUrl[ newlen++ ] = c;
1191
newUrl[ newlen++ ] = inCh;
1198
static uchar hex_to_int( uchar c )
1200
if ( c >= 'A' && c <= 'F' )
1201
return c - 'A' + 10;
1202
if ( c >= 'a' && c <= 'f')
1203
return c - 'a' + 10;
1204
if ( c >= '0' && c <= '9')
1210
Decodes the \a url in-place into UTF-8. For example
1213
QString url = "http%3A//www%20trolltech%20com"
1214
Q3Url::decode( url );
1215
// url is now "http://www.trolltech.com"
1221
void Q3Url::decode( QString& url )
1223
if ( url.isEmpty() )
1227
Q3CString curl = url.utf8();
1228
int oldlen = curl.length();
1230
Q3CString newUrl(oldlen);
1233
while ( i < oldlen ) {
1234
uchar c = (uchar)curl[ i++ ];
1235
if ( c == '%' && i <= oldlen - 2 ) {
1236
c = hex_to_int( (uchar)curl[ i ] ) * 16 + hex_to_int( (uchar)curl[ i + 1 ] );
1239
newUrl [ newlen++ ] = c;
1241
newUrl.truncate( newlen );
1243
url = QString::fromUtf8(newUrl.data());
1248
Composes a string version of the URL and returns it. If \a
1249
encodedPath is true the path in the returned string is encoded. If
1250
\a forcePrependProtocol is true and \a encodedPath looks like a
1251
local filename, the "file:/" protocol is also prepended.
1253
\sa encode() decode()
1256
QString Q3Url::toString( bool encodedPath, bool forcePrependProtocol ) const
1258
QString res, p = path();
1262
if ( isLocalFile() ) {
1263
if ( forcePrependProtocol )
1264
res = d->protocol + ":" + p;
1267
} else if ( d->protocol == "mailto" ) {
1268
res = d->protocol + ":" + p;
1270
res = d->protocol + "://";
1271
if ( !d->user.isEmpty() || !d->pass.isEmpty() ) {
1273
if ( !d->user.isEmpty() ) {
1278
if ( !d->pass.isEmpty() ) {
1286
if ( d->port != -1 )
1287
res += ":" + QString( "%1" ).arg( d->port );
1288
if ( !p.isEmpty() ) {
1289
if ( !d->host.isEmpty() && p[0]!='/' )
1295
if ( !d->refEncoded.isEmpty() )
1296
res += "#" + d->refEncoded;
1297
if ( !d->queryEncoded.isEmpty() )
1298
res += "?" + d->queryEncoded;
1304
Composes a string version of the URL and returns it.
1306
\sa Q3Url::toString()
1309
Q3Url::operator QString() const
1315
Changes the directory to one directory up.
1323
d->cleanPathDirty = true;