summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Rosenkraenzer <br@blankpage.ch>2010-03-23 15:27:42 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-03-23 15:27:42 (GMT)
commitc6ef7c0cbd2ad7ac486cd6bcabaac4d090df0c03 (patch)
treea01625662210a0d2ce629463bb52be5e164d9852
parentb4996ab8e3a26d45ee55593da281e4b798c04dd2 (diff)
downloadQt-c6ef7c0cbd2ad7ac486cd6bcabaac4d090df0c03.zip
Qt-c6ef7c0cbd2ad7ac486cd6bcabaac4d090df0c03.tar.gz
Qt-c6ef7c0cbd2ad7ac486cd6bcabaac4d090df0c03.tar.bz2
Split QDir::NoDotAndDotDot into QDir::NoDot and QDir::NoDotDot
This creates QDir::NoDot and QDir::NoDotDot filters -- in many cases, one may want the .. entry (e.g. to navigate to the parent directory) but not the . entry (useless for navigation). Reviewed-by: Benjamin Poulain <benjamin.poulain@nokia.com>
-rw-r--r--src/corelib/io/qdir.cpp6
-rw-r--r--src/corelib/io/qdir.h4
-rw-r--r--src/corelib/io/qdiriterator.cpp6
-rw-r--r--tests/auto/qdiriterator/tst_qdiriterator.cpp48
4 files changed, 61 insertions, 3 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 505889e..1b60936 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -1079,6 +1079,8 @@ QDir::Filters QDir::filter() const
\value NoSymLinks Do not list symbolic links (ignored by operating
systems that don't support symbolic links).
\value NoDotAndDotDot Do not list the special entries "." and "..".
+ \value NoDot Do not list the special entry ".".
+ \value NoDotDot Do not list the special entry "..".
\value AllEntries List directories, files, drives and symlinks (this does not list
broken symlinks unless you specify System).
\value Readable List files for which the application has read
@@ -2367,7 +2369,9 @@ QDebug operator<<(QDebug debug, QDir::Filters filters)
if (filters & QDir::Files) flags << QLatin1String("Files");
if (filters & QDir::Drives) flags << QLatin1String("Drives");
if (filters & QDir::NoSymLinks) flags << QLatin1String("NoSymLinks");
- if (filters & QDir::NoDotAndDotDot) flags << QLatin1String("NoDotAndDotDot");
+ if (filters & QDir::NoDotAndDotDot) flags << QLatin1String("NoDotAndDotDot"); // ### Qt5: remove (because NoDotAndDotDot=NoDot|NoDotDot)
+ if (filters & QDir::NoDot) flags << QLatin1String("NoDot");
+ if (filters & QDir::NoDotDot) flags << QLatin1String("NoDotDot");
if ((filters & QDir::AllEntries) == QDir::AllEntries) flags << QLatin1String("AllEntries");
if (filters & QDir::Readable) flags << QLatin1String("Readable");
if (filters & QDir::Writable) flags << QLatin1String("Writable");
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h
index 186dd2f..28da271 100644
--- a/src/corelib/io/qdir.h
+++ b/src/corelib/io/qdir.h
@@ -88,7 +88,9 @@ public:
AllDirs = 0x400,
CaseSensitive = 0x800,
- NoDotAndDotDot = 0x1000,
+ NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
+ NoDot = 0x2000,
+ NoDotDot = 0x4000,
NoFilter = -1
#ifdef QT3_SUPPORT
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index 860fb63..fd4b9c1 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -287,7 +287,11 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
&& ((fileNameSize == 1)
||(fileNameSize == 2 && fileName[1] == QLatin1Char('.')));
- if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot)
+ if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
+ return false;
+ if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
+ return false;
+ if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot) // ### Qt5 remove (NoDotAndDotDot == NoDot|NoDotDot)
return false;
// name filter
diff --git a/tests/auto/qdiriterator/tst_qdiriterator.cpp b/tests/auto/qdiriterator/tst_qdiriterator.cpp
index f6fce32..5dc17f3 100644
--- a/tests/auto/qdiriterator/tst_qdiriterator.cpp
+++ b/tests/auto/qdiriterator/tst_qdiriterator.cpp
@@ -198,6 +198,54 @@ void tst_QDirIterator::iterateRelativeDirectory_data()
#endif
"entrylist/writable").split(',');
+ QTest::newRow("NoDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::NoDot) << QStringList("*")
+ << QString(
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+ "entrylist/..,"
+#endif
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
+ QTest::newRow("NoDotDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::NoDotDot) << QStringList("*")
+ << QString(
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+ "entrylist/.,"
+#endif
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
+ QTest::newRow("NoDotAndDotDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::NoDotAndDotDot) << QStringList("*")
+ << QString(
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
QTest::newRow("QDir::Subdirectories | QDir::FollowSymlinks")
<< QString("entrylist") << QDirIterator::IteratorFlags(QDirIterator::Subdirectories | QDirIterator::FollowSymlinks)
<< QDir::Filters(QDir::NoFilter) << QStringList("*")