summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@nokia.com>2010-05-10 14:12:52 +0200
committerMorten Johan Sørvig <morten.sorvig@nokia.com>2010-05-10 14:27:46 +0200
commit98e935eed5549e479f6666680aed1711dc42111c (patch)
treecc6a47cfd58d225d98a8377f2b84636010028f61 /src/corelib/io/qurl.cpp
parentcc422e939d671bba8d70a5d02abfb893627303cc (diff)
Revert "Improve QUrl handling of local file paths"
This reverts commit a2f797b52c4274a62a7cf1f0939aca1429afe211.
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp73
1 files changed, 22 insertions, 51 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 7e5c622d00..d4b8b5febb 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -5976,22 +5976,19 @@ bool QUrl::isDetached() const
/*!
- Returns a QUrl representation of \a localFile, interpreted as a local
- file. This function accepts paths separated by slashes as well as the
- native separator for this platform.
+ Returns a QUrl representation of \a localFile, interpreted as a
+ local file.
- This function also accepts paths with a doubled leading slash (or
- backslash) to indicate a remote file, as in
- "//servername/path/to/file.txt". Note that only certain platforms can
- actually open this file using QFile::open().
-
- \sa toLocalFile(), isLocalFile(), QDir::toNativeSeparators
+ \sa toLocalFile()
*/
QUrl QUrl::fromLocalFile(const QString &localFile)
{
QUrl url;
url.setScheme(QLatin1String("file"));
- QString deslashified = QDir::toNativeSeparators(localFile);
+ QString deslashified = localFile;
+ deslashified.replace(QLatin1Char('\\'), QLatin1Char('/'));
+
+
// magic for drives on windows
if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
@@ -6010,61 +6007,35 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
}
/*!
- Returns the path of this URL formatted as a local file path. The path
- returned will use forward slashes, even if it was originally created
- from one with backslashes.
+ Returns the path of this URL formatted as a local file path.
- If this URL contains a non-empty hostname, it will be encoded in the
- returned value in the form found on SMB networks (for example,
- "//servername/path/to/file.txt").
-
- \sa fromLocalFile(), isLocalFile()
+ \sa fromLocalFile()
*/
QString QUrl::toLocalFile() const
{
- // the call to isLocalFile() also ensures that we're parsed
- if (!isLocalFile())
- return QString();
+ if (!d) return QString();
+ if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QString tmp;
QString ourPath = path();
+ if (d->scheme.isEmpty() || QString::compare(d->scheme, QLatin1String("file"), Qt::CaseInsensitive) == 0) {
- // magic for shared drive on windows
- if (!d->host.isEmpty()) {
- tmp = QLatin1String("//") + d->host + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/')
- ? QLatin1Char('/') + ourPath : ourPath);
- } else {
- tmp = ourPath;
- // magic for drives on windows
- if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
- tmp.remove(0, 1);
+ // magic for shared drive on windows
+ if (!d->host.isEmpty()) {
+ tmp = QLatin1String("//") + d->host + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/')
+ ? QLatin1Char('/') + ourPath : ourPath);
+ } else {
+ tmp = ourPath;
+ // magic for drives on windows
+ if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
+ tmp.remove(0, 1);
+ }
}
return tmp;
}
/*!
- \since 4.7
- Returns true if this URL is pointing to a local file path. A URL is a
- local file path if the scheme is "file".
-
- Note that this function considers URLs with hostnames to be local file
- paths, even if the eventual file path cannot be opened with
- QFile::open().
-
- \sa fromLocalFile(), toLocalFile()
-*/
-bool QUrl::isLocalFile() const
-{
- if (!d) return false;
- if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
-
- if (d->scheme.compare(QLatin1String("file"), Qt::CaseInsensitive) != 0)
- return false; // not file
- return true;
-}
-
-/*!
Returns true if this URL is a parent of \a childUrl. \a childUrl is a child
of this URL if the two URLs share the same scheme and authority,
and this URL's path is a parent of the path of \a childUrl.