diff --git a/libkdeqt5staging/autotests/tst_qurlpathinfo.cpp b/libkdeqt5staging/autotests/tst_qurlpathinfo.cpp index d40ab64b88..62a478d03e 100644 --- a/libkdeqt5staging/autotests/tst_qurlpathinfo.cpp +++ b/libkdeqt5staging/autotests/tst_qurlpathinfo.cpp @@ -1,258 +1,264 @@ /**************************************************************************** ** ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/ ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General ** Public License version 3.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of this ** file. Please review the following information to ensure the GNU General ** Public License version 3.0 requirements will be met: ** http://www.gnu.org/copyleft/gpl.html. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include Q_DECLARE_METATYPE(QUrlPathInfo::EqualsOptions) class tst_QUrlPathInfo : public QObject { Q_OBJECT private Q_SLOTS: void directoryAndFileName_data(); void directoryAndFileName(); void setFileName_data(); void setFileName(); void path_data(); void path(); void addPath_data(); void addPath(); void adjustPath_data(); void adjustPath(); void equals_data(); void equals(); }; void tst_QUrlPathInfo::directoryAndFileName_data() { QTest::addColumn("urlStr"); QTest::addColumn("expectedDirectory"); QTest::addColumn("expectedDirectoryTrailingSlash"); QTest::addColumn("expectedFileName"); QTest::addColumn("expectedDirectoryUrl"); QTest::newRow("absoluteFile") << "file:///temp/tmp.txt" << "/temp" << "/temp/" << "tmp.txt" << "file:///temp"; QTest::newRow("absoluteDir") << "file:///temp/" << "/temp" << "/temp/" << QString() << "file:///temp"; QTest::newRow("absoluteInRoot") << "file:///temp" << "/" << "/" << "temp" << "file:///"; QTest::newRow("relative") << "temp/tmp.txt" << "temp" << "temp/" << "tmp.txt" << "temp"; QTest::newRow("relativeNoSlash") << "tmp.txt" << QString() << QString() << "tmp.txt" << QString(); QTest::newRow("encoded") << "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)" << "/specials" << "/specials/" << "Print To File (PDF%2FAcrobat)" << "print:/specials"; } void tst_QUrlPathInfo::directoryAndFileName() { QFETCH(QString, urlStr); QFETCH(QString, expectedDirectory); QFETCH(QString, expectedDirectoryTrailingSlash); QFETCH(QString, expectedFileName); QFETCH(QString, expectedDirectoryUrl); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) const QUrl url(urlStr); #else const QUrl url = QUrl::fromEncoded(urlStr.toUtf8()); #endif QVERIFY(url.isValid()); const QUrlPathInfo info(url); QCOMPARE(info.directory(), expectedDirectory); QCOMPARE(info.directory(QUrlPathInfo::AppendTrailingSlash), expectedDirectoryTrailingSlash); QCOMPARE(info.fileName(), expectedFileName); QCOMPARE(info.directoryUrl().toString(), expectedDirectoryUrl); } void tst_QUrlPathInfo::setFileName_data() { QTest::addColumn("urlStr"); QTest::addColumn("fileName"); QTest::addColumn("expectedUrl"); QTest::newRow("simple") << "foo://host/bar" << "blah" << "foo://host/blah"; QTest::newRow("empty") << "foo://host/bar" << "" << "foo://host/"; } void tst_QUrlPathInfo::setFileName() { QFETCH(QString, urlStr); QFETCH(QString, fileName); QFETCH(QString, expectedUrl); const QUrl url(urlStr); QVERIFY(url.isValid()); QUrlPathInfo info(url); info.setFileName(fileName); QCOMPARE(info.url().toString(), expectedUrl); } void tst_QUrlPathInfo::path_data() { QTest::addColumn("urlStr"); QTest::addColumn("expectedPath"); QTest::addColumn("expectedPathNoSlash"); QTest::addColumn("expectedPathWithSlash"); QTest::newRow("absoluteFile") << "file:///temp/tmp.txt" << "/temp/tmp.txt" << "/temp/tmp.txt" << "/temp/tmp.txt/"; QTest::newRow("absoluteDir") << "file:///temp/" << "/temp/" << "/temp" << "/temp/"; QTest::newRow("absoluteInRoot") << "file:///temp" << "/temp" << "/temp" << "/temp/"; QTest::newRow("relative") << "temp/" << "temp/" << "temp" << "temp/"; QTest::newRow("relativeNoSlash") << "tmp.txt" << "tmp.txt" << "tmp.txt" << "tmp.txt/"; QTest::newRow("encoded") << "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)" << "/specials/Print To File (PDF%2FAcrobat)" << "/specials/Print To File (PDF%2FAcrobat)" << "/specials/Print To File (PDF%2FAcrobat)/"; } void tst_QUrlPathInfo::path() { QFETCH(QString, urlStr); QFETCH(QString, expectedPath); QFETCH(QString, expectedPathNoSlash); QFETCH(QString, expectedPathWithSlash); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) const QUrl url(urlStr); #else const QUrl url = QUrl::fromEncoded(urlStr.toUtf8()); #endif const QUrlPathInfo info(url); QCOMPARE(info.path(), expectedPath); QCOMPARE(info.path(QUrlPathInfo::StripTrailingSlash), expectedPathNoSlash); QCOMPARE(info.path(QUrlPathInfo::AppendTrailingSlash), expectedPathWithSlash); } void tst_QUrlPathInfo::addPath_data() { QTest::addColumn("initialUrl"); QTest::addColumn("toAdd"); QTest::addColumn("expectedUrl"); QTest::newRow("absoluteDir+fileName") << "file:///temp" << "tmp.txt" << "file:///temp/tmp.txt"; QTest::newRow("absoluteDir+/fileName") << "file:///temp" << "/tmp.txt" << "file:///temp/tmp.txt"; QTest::newRow("absoluteDir/+fileName") << "file:///temp/" << "tmp.txt" << "file:///temp/tmp.txt"; QTest::newRow("absoluteDir/+/fileName") << "file:///temp/" << "/tmp.txt" << "file:///temp/tmp.txt"; QTest::newRow("absoluteDir+subdir/fileName") << "file:///temp/" << "/temp/tmp.txt" << "file:///temp/temp/tmp.txt"; QTest::newRow("absoluteInRoot+/") << "file:///" << "/" << "file:///"; QTest::newRow("relative") << "temp" << "foo" << "temp/foo"; } void tst_QUrlPathInfo::addPath() { QFETCH(QString, initialUrl); QFETCH(QString, toAdd); QFETCH(QString, expectedUrl); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) const QUrl url(initialUrl); #else const QUrl url = QUrl::fromEncoded(initialUrl.toUtf8()); #endif QUrlPathInfo info(url); info.addPath(toAdd); QCOMPARE(info.url().toString(), expectedUrl); } void tst_QUrlPathInfo::adjustPath_data() { path_data(); } void tst_QUrlPathInfo::adjustPath() { QFETCH(QString, urlStr); QFETCH(QString, expectedPath); QFETCH(QString, expectedPathNoSlash); QFETCH(QString, expectedPathWithSlash); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) const QUrl url(urlStr); #else const QUrl url = QUrl::fromEncoded(urlStr.toUtf8()); #endif QUrlPathInfo info(url); // Go via QUrlPathInfo::path in order to get decoded paths QCOMPARE(QUrlPathInfo(info.url()).path(), expectedPath); QCOMPARE(QUrlPathInfo(info.url(QUrlPathInfo::StripTrailingSlash)).path(), expectedPathNoSlash); QCOMPARE(QUrlPathInfo(info.url(QUrlPathInfo::AppendTrailingSlash)).path(), expectedPathWithSlash); info.adjustPath(QUrlPathInfo::StripTrailingSlash); QCOMPARE(info.path(), expectedPathNoSlash); info.adjustPath(QUrlPathInfo::AppendTrailingSlash); QCOMPARE(info.path(), expectedPathWithSlash); } void tst_QUrlPathInfo::equals_data() { QTest::addColumn("urlStr1"); QTest::addColumn("urlStr2"); QTest::addColumn("options"); QTest::addColumn("expectedResult"); const QUrlPathInfo::EqualsOptions strict(QUrlPathInfo::StrictComparison); const QUrlPathInfo::EqualsOptions noTrailing(QUrlPathInfo::CompareWithoutTrailingSlash); const QUrlPathInfo::EqualsOptions allowEmpty(QUrlPathInfo::CompareWithoutTrailingSlash | QUrlPathInfo::AllowEmptyPath); + const QUrlPathInfo::EqualsOptions caseInsensitive(QUrlPathInfo::ComparePathsCaseInsensitively); + const QUrlPathInfo::EqualsOptions caseInsensitiveNoTrailing(QUrlPathInfo::CompareWithoutTrailingSlash | QUrlPathInfo::ComparePathsCaseInsensitively); QTest::newRow("slash_diff") << "ftp://ftp.kde.org/dir" << "ftp://ftp.kde.org/dir/" << strict << false; QTest::newRow("slash_diff_ignore_slash") << "ftp://ftp.kde.org/dir" << "ftp://ftp.kde.org/dir/" << noTrailing << true; QTest::newRow("slash_diff_allow_empty") << "ftp://ftp.kde.org/dir" << "ftp://ftp.kde.org/dir/" << allowEmpty << true; QTest::newRow("slash_vs_empty") << "ftp://ftp.kde.org/" << "ftp://ftp.kde.org" << strict << false; QTest::newRow("slash_vs_empty_ignore_slash") << "ftp://ftp.kde.org/" << "ftp://ftp.kde.org" << noTrailing << false; QTest::newRow("slash_vs_empty_allow_empty") << "ftp://ftp.kde.org/" << "ftp://ftp.kde.org" << allowEmpty << true; + QTest::newRow("same_case") << "ftp://ftp.kde.org/dir" << "ftp://ftp.kde.org/dir" << caseInsensitive << true; + QTest::newRow("case_insensitive") << "ftp://ftp.kde.org/dir" << "ftp://ftp.kde.org/DIR" << caseInsensitive << true; + QTest::newRow("case_insensitive_different") << "ftp://ftp.kde.org/dir/" << "ftp://ftp.kde.org/DIR" << caseInsensitive << false; + QTest::newRow("case_insensitive_ignore_slash") << "ftp://ftp.kde.org/dir/" << "ftp://ftp.kde.org/DIR" << caseInsensitiveNoTrailing << true; } void tst_QUrlPathInfo::equals() { QFETCH(QString, urlStr1); QFETCH(QString, urlStr2); QFETCH(QUrlPathInfo::EqualsOptions, options); QFETCH(bool, expectedResult); QUrl url1(urlStr1); QUrl url2(urlStr2); QCOMPARE(QUrlPathInfo(url1).equals(url2, options), expectedResult); QCOMPARE(QUrlPathInfo(url2).equals(url1, options), expectedResult); } QTEST_MAIN(tst_QUrlPathInfo) #include "tst_qurlpathinfo.moc" diff --git a/libkdeqt5staging/src/qurlpathinfo.cpp b/libkdeqt5staging/src/qurlpathinfo.cpp index 748bbebcd9..32e1df0dcf 100644 --- a/libkdeqt5staging/src/qurlpathinfo.cpp +++ b/libkdeqt5staging/src/qurlpathinfo.cpp @@ -1,459 +1,464 @@ /**************************************************************************** ** ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General ** Public License version 3.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of this ** file. Please review the following information to ensure the GNU General ** Public License version 3.0 requirements will be met: ** http://www.gnu.org/copyleft/gpl.html. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qurlpathinfo.h" /*! \class QUrlPathInfo \since 5.0 \brief The QUrlPathInfo class provides a convenient interface for working with URL paths. \reentrant \ingroup io \ingroup network \ingroup shared QUrlPathInfo allows to manipulate URLs which represent a file or a directory in a local or remote filesystem. It offers similar path-manipulation methods as QFileInfo, but for paths in URLs. The most common way to use QUrlPathInfo is to initialize it via the constructor by passing a QUrl. Otherwise, setUrl() can also be used. QUrl defaults to encoded paths, so a '%' in a filename becomes a %25 in the url, and therefore in QUrl::path(). However for file management on local or remote filesystems, decoded paths are wanted, to display '%' to the user when the filename contains '%'. For this reason, QUrlPathInfo works with decoded paths. \sa QUrl */ /*! \enum QUrlPathInfo::PathFormattingOption The path formatting options define transformations for the path. \value None The path is unchanged. \value StripTrailingSlash The trailing slash is removed if one is present. \value AppendTrailingSlash A trailing slash is added at the end of the path, if necessary. Note that a path of "/" will always remain unchanged. */ /*! \enum QUrlPathInfo::EqualsOption Options for the equals() method. \value CompareWithoutTrailingSlash Ignore trailing '/' in paths. The paths "dir" and "dir/" are treated the same. Note however, that by default, the paths "" and "/" are not the same (For instance ftp://user@host redirects to ftp://user@host/home/user (on a linux server), while ftp://user@host/ is the root dir). This is also why path(StripTrailingSlash) for "/" returns "/" and not "". When dealing with web pages however, you should also set AllowEmptyPath so that no path and "/" are considered equal. \value CompareWithoutFragment Disables comparison of HTML-style references (fragments). \value AllowEmptyPath Treat a URL with no path as equal to a URL with a path of "/", when CompareWithoutTrailingSlash is set. Example: QUrlPathInfo("http://www.kde.org").equals("http://www.kde.org/", QUrlPathInfo::CompareWithoutTrailingSlash | QUrlPathInfo::AllowEmptyPath) returns true. This option is ignored if CompareWithoutTrailingSlash isn't set. */ QT_BEGIN_NAMESPACE class QUrlPathInfoPrivate : public QSharedData { public: QUrlPathInfoPrivate() {} QUrl url; }; /*! Constructs an empty QUrlPathInfo object. */ QUrlPathInfo::QUrlPathInfo() : d(new QUrlPathInfoPrivate) { } /*! Constructs a QUrlPathInfo object from a \a url. */ QUrlPathInfo::QUrlPathInfo(const QUrl &url) : d(new QUrlPathInfoPrivate) { d->url = url; } /*! Constructs a copy of \a other. */ QUrlPathInfo::QUrlPathInfo(const QUrlPathInfo &other) : d(other.d) { } /*! Destructor; called immediately before the object is deleted. */ QUrlPathInfo::~QUrlPathInfo() { } /*! Returns the full URL, with the path modifications taken into account, if any. \sa setUrl() */ QUrl QUrlPathInfo::url(PathFormattingOption options) const { if (options == None) { return d->url; } else { QUrl url(d->url); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) url.setPath(path(options), QUrl::DecodedMode); #else url.setPath(path(options)); #endif return url; } } /*! Sets the URL to manipulate. \sa url() */ void QUrlPathInfo::setUrl(const QUrl &u) { d->url = u; } /*! Returns the path of the URL, formatted using \a options Unlike QUrl, QUrlPathInfo works with decoded paths. Do not use this as a local path, this is not portable. Use toLocalPath(options) or url().toLocalFile() instead. \sa setPath(), toLocalPath(), url() */ QString QUrlPathInfo::path(PathFormattingOptions options) const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QString path = d->url.path(QUrl::FullyDecoded); #else QString path = d->url.path(); #endif while ((options & StripTrailingSlash) && path.endsWith(QLatin1Char('/')) && path.length() > 1) path.chop(1); if ((options & AppendTrailingSlash) && !path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); return path; } /*! Sets the path of the URL. Unlike QUrl, QUrlPathInfo works with decoded paths. The other components of the URL (scheme, host, query, fragment...) remain unchanged. \sa path(), addPath() */ void QUrlPathInfo::setPath(const QString &path) { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d->url.setPath(path, QUrl::DecodedMode); #else d->url.setPath(path); #endif } /*! Returns the path for this URL, formatted as a local file path, using \a options This method only makes sense for local urls. The path returned will use forward slashes, even if it was originally created from one with backslashes. \sa setPath(), url(), QUrl::toLocalFile() */ QString QUrlPathInfo::localPath(PathFormattingOptions options) const { QString path = d->url.toLocalFile(); while ((options & StripTrailingSlash) && path.endsWith(QLatin1Char('/')) && path.length() > 1) path.chop(1); if ((options & AppendTrailingSlash) && !path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); return path; } /*! Returns true if the path is empty \sa path() */ bool QUrlPathInfo::isEmpty() const { return d->url.path().isEmpty(); } /*! Sets the path to be empty \sa path(), setPath() */ void QUrlPathInfo::clear() { d->url.setPath(QString()); } /*! Returns the name of the file, excluding the directory. Note that, if this QUrl object is given a path ending in a slash, the name of the file is considered empty. If the path doesn't contain any slash, it is fully returned as part of fileName, and directory() will be empty. \sa path(), setPath() */ QString QUrlPathInfo::fileName() const { const QString ourPath = path(); const int slash = ourPath.lastIndexOf(QLatin1Char('/')); if (slash == -1) return ourPath; return ourPath.mid(slash + 1); } /*! Sets the name of the file, keeping the directory unchanged. \sa path(), fileName(), directory() */ void QUrlPathInfo::setFileName(const QString &fileName) { const QString ourPath = path(); const int slash = ourPath.lastIndexOf(QLatin1Char('/')); if (slash == -1) setPath(fileName); else if (slash == 0) setPath(QLatin1Char('/') + fileName); else setPath(ourPath.left(slash + 1) + fileName); } /*! Returns the directory path, excluding the file name returned by fileName(). Example: \snippet doc/src/snippets/code/src_corelib_io_qurl.cpp 7 If \a options is None (the default) or StripTrailingSlash, the directory is returned without a trailing slash. Otherwise, if \a options if AppendTrailingSlash, a slash is appended. The root directory ("/") is always returned as "/". If the path doesn't contain any slash, it is fully returned as part of fileName, and directoryPath will be empty. \sa path(), fileName(), setFileName(), directoryUrl() */ QString QUrlPathInfo::directory(QUrlPathInfo::PathFormattingOptions options) const { const QString ourPath = path(); const int slash = ourPath.lastIndexOf(QLatin1Char('/')); if (slash == -1) return QString(); else if (slash == 0) return QString(QLatin1Char('/')); return options == AppendTrailingSlash ? ourPath.left(slash+1) : ourPath.left(slash); } /*! Returns a URL for the parent directory of this URL. \sa directory() */ QUrl QUrlPathInfo::directoryUrl() const { QUrl url = d->url; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) url.setPath(directory(), QUrl::DecodedMode); #else url.setPath(directory()); #endif return url; } /*! Adds to the current path. Assumes that the current path is a directory. \a relativePath is appended to the current path. This method adds '/' if needed while concatenating. This means it does not matter whether the current path has a trailing '/' or not. If there is none, it becomes appended. If \a relativePath has a leading '/' then this one is stripped. \param relativePath The relative path to add to the current directory path. Usually this is simply a file name. \sa path(), setPath() */ void QUrlPathInfo::addPath(const QString &relativePath) { if (relativePath.isEmpty()) return; QString p = path(); // "The function adds '/' if needed while concatenating." if (!p.endsWith(QLatin1Char('/'))) p += QLatin1Char('/'); // If relativePath has a leading '/' then this one is stripped. int i = 0; if (relativePath.startsWith(QLatin1Char('/'))) ++i; setPath(p + relativePath.mid(i)); } /*! Convenience method, for adding a relative path to a url. \param url the initial URL \param relativePath the relative path to add (often just a file name) \return the modified URL */ QUrl QUrlPathInfo::addPathToUrl(const QUrl &url, const QString& relativePath) { QUrlPathInfo info(url); info.addPath(relativePath); return info.url(); } /*! Adjust the trailing slash in the path of the URL. The other components of the URL (scheme, host, query, fragment...) remain unchanged. \sa path(), addPath() */ void QUrlPathInfo::adjustPath(PathFormattingOptions options) { setPath(path(options)); } /*! Return true if this URL is a parent of \a child, or if they are equal. Trailing slashes are ignored. */ bool QUrlPathInfo::isParentOfOrEqual(const QUrl &child) const { return d->url.isParentOf(child) || equals(child, CompareWithoutTrailingSlash); } /*! Compares this url with \a u. \param u the URL to compare this one with. \param options a set of EqualsOption flags \return True if both urls are the same. If at least one of the urls is invalid, false is returned. \see operator==. This function should be used if you want to set additional options, like ignoring trailing '/' characters. */ bool QUrlPathInfo::equals(const QUrl& u, EqualsOptions options) const { if (!d->url.isValid() || !u.isValid()) return false; - if (options & CompareWithoutTrailingSlash || options & CompareWithoutFragment) { + if (options != StrictComparison) { QString path1 = path((options & CompareWithoutTrailingSlash) ? StripTrailingSlash : None); QString path2 = QUrlPathInfo(u).path((options & CompareWithoutTrailingSlash) ? StripTrailingSlash : None); if (options & AllowEmptyPath) { if (path1 == QLatin1String("/")) path1.clear(); if (path2 == QLatin1String("/")) path2.clear(); } #ifdef Q_OS_WIN const bool bLocal1 = isLocalFile(); const bool bLocal2 = u.isLocalFile(); if (!bLocal1 && bLocal2 || bLocal1 && !bLocal2) return false; // local files are case insensitive - if (bLocal1 && bLocal2 && 0 != QString::compare(path1, path2, Qt::CaseInsensitive)) - return false; + if (bLocal1 && bLocal2) + options |= ComparePathsCaseInsensitively; #endif - if (path1 != path2) - return false; + if (options & ComparePathsCaseInsensitively) { + if (QString::compare(path1, path2, Qt::CaseInsensitive) != 0) + return false; + } else { + if (path1 != path2) + return false; + } if (d->url.scheme() == u.scheme() && d->url.authority() == u.authority() && // user+pass+host+port #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) d->url.query() == u.query() && #else d->url.encodedQuery() == u.encodedQuery() && #endif (d->url.fragment() == u.fragment() || options & CompareWithoutFragment) ) return true; return false; } return d->url == u; } diff --git a/libkdeqt5staging/src/qurlpathinfo.h b/libkdeqt5staging/src/qurlpathinfo.h index 31c1575fc7..e2d64dd041 100644 --- a/libkdeqt5staging/src/qurlpathinfo.h +++ b/libkdeqt5staging/src/qurlpathinfo.h @@ -1,128 +1,130 @@ /**************************************************************************** ** ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General ** Public License version 3.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of this ** file. Please review the following information to ensure the GNU General ** Public License version 3.0 requirements will be met: ** http://www.gnu.org/copyleft/gpl.html. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QURLPATHINFO_H #define QURLPATHINFO_H #include "kdeqt5staging_export.h" #include #include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QUrlPathInfoPrivate; class KDEQT5STAGING_EXPORT QUrlPathInfo { public: enum PathFormattingOption { None = 0x0, StripTrailingSlash = 0x200, // compatible with QUrl AppendTrailingSlash = 0x400 }; Q_DECLARE_FLAGS(PathFormattingOptions, PathFormattingOption) /*! * Flags to be used in URL comparison functions like equals, or urlcmp */ enum EqualsOption { StrictComparison = 0x00, CompareWithoutTrailingSlash = 0x01, CompareWithoutFragment = 0x02, - AllowEmptyPath = 0x04 + AllowEmptyPath = 0x04, + ComparePathsCaseInsensitively = 0x08 }; Q_DECLARE_FLAGS(EqualsOptions, EqualsOption) QUrlPathInfo(); explicit QUrlPathInfo(const QUrl &url); QUrlPathInfo(const QUrlPathInfo &other); QUrlPathInfo &operator =(const QUrlPathInfo &other); #ifdef Q_COMPILER_RVALUE_REFS inline QUrlPathInfo &operator=(QUrlPathInfo &&other) { qSwap(d, other.d); return *this; } #endif ~QUrlPathInfo(); inline void swap(QUrlPathInfo &other) { qSwap(d, other.d); } QUrl url(PathFormattingOption options = None) const; void setUrl(const QUrl &u); QString path(PathFormattingOptions options = None) const; void setPath(const QString &path); void addPath(const QString &relativePath); void adjustPath(PathFormattingOptions options); static QUrl addPathToUrl(const QUrl &url, const QString& relativePath) Q_REQUIRED_RESULT; QString localPath(PathFormattingOptions options = None) const; bool isEmpty() const; bool equals(const QUrl& u, EqualsOptions options = StrictComparison) const; bool isParentOfOrEqual(const QUrl &child) const; void clear(); QString fileName() const; void setFileName(const QString &name); QString directory(PathFormattingOptions options = None) const; QUrl directoryUrl() const; private: QSharedDataPointer d; //public: //typedef QUrlPathInfoPrivate * DataPtr; //inline DataPtr &data_ptr() { return d; } }; Q_DECLARE_TYPEINFO(QUrlPathInfo, Q_MOVABLE_TYPE); // Q_DECLARE_SHARED(QUrlPathInfo) Q_DECLARE_OPERATORS_FOR_FLAGS(QUrlPathInfo::PathFormattingOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(QUrlPathInfo::EqualsOptions) QT_END_NAMESPACE QT_END_HEADER #endif // QURLPATHINFO_H