diff options
author | Andy <qt-info@nokia.com> | 2009-05-14 13:37:00 (GMT) |
---|---|---|
committer | Andy <qt-info@nokia.com> | 2009-05-14 13:37:00 (GMT) |
commit | d755bb5e8cfd88d0cd909f32d240d18e856bbd36 (patch) | |
tree | 3a990f376a999f271154da17ad745dd1c1aed5eb | |
parent | d6e87c332c721bbcb86bebc6f4daa8a3125e80c6 (diff) | |
download | Qt-d755bb5e8cfd88d0cd909f32d240d18e856bbd36.zip Qt-d755bb5e8cfd88d0cd909f32d240d18e856bbd36.tar.gz Qt-d755bb5e8cfd88d0cd909f32d240d18e856bbd36.tar.bz2 |
Prevent duplicate entries in the sidebar when the paths are the same
If two urls were added to the sidebar that only differed in how they
referenced the added url (i.e. /foo/bar/. and /foo/bar) then only one
entry should appear.
Task-number: 253532
Reviewed-by: Alexis
-rw-r--r-- | src/gui/dialogs/qsidebar.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qsidebar/tst_qsidebar.cpp | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/gui/dialogs/qsidebar.cpp b/src/gui/dialogs/qsidebar.cpp index 26108d7..9abefdf 100644 --- a/src/gui/dialogs/qsidebar.cpp +++ b/src/gui/dialogs/qsidebar.cpp @@ -249,9 +249,9 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) continue; for (int j = 0; move && j < rowCount(); ++j) { #if defined(Q_OS_WIN) - if (index(j, 0).data(UrlRole).toUrl().toLocalFile().toLower() == url.toLocalFile().toLower()) { + if (QDir::cleanPath(index(j, 0).data(UrlRole).toUrl().toLocalFile()).toLower() == QDir::cleanPath(url.toLocalFile()).toLower()) { #else - if (index(j, 0).data(UrlRole) == url) { + if (QDir::cleanPath(index(j, 0).data(UrlRole)) == QDir::cleanPath(url)) { #endif removeRow(j); if (j <= row) diff --git a/tests/auto/qsidebar/tst_qsidebar.cpp b/tests/auto/qsidebar/tst_qsidebar.cpp index 705e222..1384391 100644 --- a/tests/auto/qsidebar/tst_qsidebar.cpp +++ b/tests/auto/qsidebar/tst_qsidebar.cpp @@ -185,6 +185,13 @@ void tst_QSidebar::addUrls() qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 1); + // Two paths that are effectively pointing to the same location + doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); + doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath() + "/."); + qsidebar.setUrls(emptyUrls); + qsidebar.addUrls(doubleUrls, 1); + QCOMPARE(qsidebar.urls().size(), 1); + #if defined(Q_OS_WIN) //Windows is case insensitive so no duplicate entries in that case doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); @@ -200,8 +207,6 @@ void tst_QSidebar::addUrls() qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 2); #endif - - } void tst_QSidebar::goToUrl() |