| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qdir.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||
| 41 | #include "qdir.h" | - | ||||||||||||||||||||||||
| 42 | #include "qdir_p.h" | - | ||||||||||||||||||||||||
| 43 | #include "qabstractfileengine_p.h" | - | ||||||||||||||||||||||||
| 44 | #include "qfsfileengine_p.h" | - | ||||||||||||||||||||||||
| 45 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 46 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 47 | #endif | - | ||||||||||||||||||||||||
| 48 | #include "qdiriterator.h" | - | ||||||||||||||||||||||||
| 49 | #include "qdatetime.h" | - | ||||||||||||||||||||||||
| 50 | #include "qstring.h" | - | ||||||||||||||||||||||||
| 51 | #include "qregexp.h" | - | ||||||||||||||||||||||||
| 52 | #include "qvector.h" | - | ||||||||||||||||||||||||
| 53 | #include "qvarlengtharray.h" | - | ||||||||||||||||||||||||
| 54 | #include "qfilesystementry_p.h" | - | ||||||||||||||||||||||||
| 55 | #include "qfilesystemmetadata_p.h" | - | ||||||||||||||||||||||||
| 56 | #include "qfilesystemengine_p.h" | - | ||||||||||||||||||||||||
| 57 | #include <qstringbuilder.h> | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | #ifdef QT_BUILD_CORE_LIB | - | ||||||||||||||||||||||||
| 60 | # include "qresource.h" | - | ||||||||||||||||||||||||
| 61 | # include "private/qcoreglobaldata_p.h" | - | ||||||||||||||||||||||||
| 62 | #endif | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | #include <algorithm> | - | ||||||||||||||||||||||||
| 65 | #include <stdlib.h> | - | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 70 | static QString driveSpec(const QString &path) | - | ||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||
| 72 | if (path.size() < 2) | - | ||||||||||||||||||||||||
| 73 | return QString(); | - | ||||||||||||||||||||||||
| 74 | char c = path.at(0).toLatin1(); | - | ||||||||||||||||||||||||
| 75 | if (c < 'a' && c > 'z' && c < 'A' && c > 'Z') | - | ||||||||||||||||||||||||
| 76 | return QString(); | - | ||||||||||||||||||||||||
| 77 | if (path.at(1).toLatin1() != ':') | - | ||||||||||||||||||||||||
| 78 | return QString(); | - | ||||||||||||||||||||||||
| 79 | return path.mid(0, 2); | - | ||||||||||||||||||||||||
| 80 | } | - | ||||||||||||||||||||||||
| 81 | #endif | - | ||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||
| 83 | //************* QDirPrivate | - | ||||||||||||||||||||||||
| 84 | QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_) | - | ||||||||||||||||||||||||
| 85 | : QSharedData() | - | ||||||||||||||||||||||||
| 86 | , fileListsInitialized(false) | - | ||||||||||||||||||||||||
| 87 | , nameFilters(nameFilters_) | - | ||||||||||||||||||||||||
| 88 | , sort(sort_) | - | ||||||||||||||||||||||||
| 89 | , filters(filters_) | - | ||||||||||||||||||||||||
| 90 | { | - | ||||||||||||||||||||||||
| 91 | setPath(path.isEmpty() ? QString::fromLatin1(".") : path); | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | bool empty = nameFilters.isEmpty(); | - | ||||||||||||||||||||||||
| 94 | if (!empty) {
| 27-18066 | ||||||||||||||||||||||||
| 95 | empty = true; | - | ||||||||||||||||||||||||
| 96 | for (int i = 0; i < nameFilters.size(); ++i) {
| 0-27 | ||||||||||||||||||||||||
| 97 | if (!nameFilters.at(i).isEmpty()) {
| 0-27 | ||||||||||||||||||||||||
| 98 | empty = false; | - | ||||||||||||||||||||||||
| 99 | break; executed 27 times by 2 tests: break;Executed by:
| 27 | ||||||||||||||||||||||||
| 100 | } | - | ||||||||||||||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 102 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 103 | if (empty)
| 27-18066 | ||||||||||||||||||||||||
| 104 | nameFilters = QStringList(QString::fromLatin1("*")); executed 18066 times by 248 tests: nameFilters = QStringList(QString::fromLatin1("*"));Executed by:
| 18066 | ||||||||||||||||||||||||
| 105 | } executed 18093 times by 248 tests: end of blockExecuted by:
| 18093 | ||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||
| 107 | QDirPrivate::QDirPrivate(const QDirPrivate ©) | - | ||||||||||||||||||||||||
| 108 | : QSharedData(copy) | - | ||||||||||||||||||||||||
| 109 | , fileListsInitialized(false) | - | ||||||||||||||||||||||||
| 110 | , nameFilters(copy.nameFilters) | - | ||||||||||||||||||||||||
| 111 | , sort(copy.sort) | - | ||||||||||||||||||||||||
| 112 | , filters(copy.filters) | - | ||||||||||||||||||||||||
| 113 | , dirEntry(copy.dirEntry) | - | ||||||||||||||||||||||||
| 114 | , metaData(copy.metaData) | - | ||||||||||||||||||||||||
| 115 | { | - | ||||||||||||||||||||||||
| 116 | } executed 375 times by 14 tests: end of blockExecuted by:
| 375 | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | bool QDirPrivate::exists() const | - | ||||||||||||||||||||||||
| 119 | { | - | ||||||||||||||||||||||||
| 120 | if (fileEngine.isNull()) {
| 111-3906 | ||||||||||||||||||||||||
| 121 | QFileSystemEngine::fillMetaData(dirEntry, metaData, | - | ||||||||||||||||||||||||
| 122 | QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat | - | ||||||||||||||||||||||||
| 123 | return metaData.exists() && metaData.isDirectory(); executed 3906 times by 64 tests: return metaData.exists() && metaData.isDirectory();Executed by:
| 3906 | ||||||||||||||||||||||||
| 124 | } | - | ||||||||||||||||||||||||
| 125 | const QAbstractFileEngine::FileFlags info = | - | ||||||||||||||||||||||||
| 126 | fileEngine->fileFlags(QAbstractFileEngine::DirectoryType | - | ||||||||||||||||||||||||
| 127 | | QAbstractFileEngine::ExistsFlag | - | ||||||||||||||||||||||||
| 128 | | QAbstractFileEngine::Refresh); | - | ||||||||||||||||||||||||
| 129 | if (!(info & QAbstractFileEngine::DirectoryType))
| 27-84 | ||||||||||||||||||||||||
| 130 | return false; executed 84 times by 2 tests: return false;Executed by:
| 84 | ||||||||||||||||||||||||
| 131 | return info & QAbstractFileEngine::ExistsFlag; executed 27 times by 2 tests: return info & QAbstractFileEngine::ExistsFlag;Executed by:
| 27 | ||||||||||||||||||||||||
| 132 | } | - | ||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | // static | - | ||||||||||||||||||||||||
| 135 | inline QChar QDirPrivate::getFilterSepChar(const QString &nameFilter) | - | ||||||||||||||||||||||||
| 136 | { | - | ||||||||||||||||||||||||
| 137 | QChar sep(QLatin1Char(';')); | - | ||||||||||||||||||||||||
| 138 | int i = nameFilter.indexOf(sep, 0); | - | ||||||||||||||||||||||||
| 139 | if (i == -1 && nameFilter.indexOf(QLatin1Char(' '), 0) != -1)
| 0-29 | ||||||||||||||||||||||||
| 140 | sep = QChar(QLatin1Char(' ')); never executed: sep = QChar(QLatin1Char(' ')); | 0 | ||||||||||||||||||||||||
| 141 | return sep; executed 32 times by 2 tests: return sep;Executed by:
| 32 | ||||||||||||||||||||||||
| 142 | } | - | ||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||
| 144 | // static | - | ||||||||||||||||||||||||
| 145 | inline QStringList QDirPrivate::splitFilters(const QString &nameFilter, QChar sep) | - | ||||||||||||||||||||||||
| 146 | { | - | ||||||||||||||||||||||||
| 147 | if (sep.isNull())
| 0-32 | ||||||||||||||||||||||||
| 148 | sep = getFilterSepChar(nameFilter); executed 32 times by 2 tests: sep = getFilterSepChar(nameFilter);Executed by:
| 32 | ||||||||||||||||||||||||
| 149 | QStringList ret = nameFilter.split(sep); | - | ||||||||||||||||||||||||
| 150 | for (int i = 0; i < ret.count(); ++i)
| 32-35 | ||||||||||||||||||||||||
| 151 | ret[i] = ret[i].trimmed(); executed 35 times by 2 tests: ret[i] = ret[i].trimmed();Executed by:
| 35 | ||||||||||||||||||||||||
| 152 | return ret; executed 32 times by 2 tests: return ret;Executed by:
| 32 | ||||||||||||||||||||||||
| 153 | } | - | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | inline void QDirPrivate::setPath(const QString &path) | - | ||||||||||||||||||||||||
| 156 | { | - | ||||||||||||||||||||||||
| 157 | QString p = QDir::fromNativeSeparators(path); | - | ||||||||||||||||||||||||
| 158 | if (p.endsWith(QLatin1Char('/'))
| 1093-17927 | ||||||||||||||||||||||||
| 159 | && p.length() > 1
| 324-769 | ||||||||||||||||||||||||
| 160 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 161 | # if defined (Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 162 | && (!(p.toLower() == QDir::rootPath().toLower())) | - | ||||||||||||||||||||||||
| 163 | # else | - | ||||||||||||||||||||||||
| 164 | && (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter())) | - | ||||||||||||||||||||||||
| 165 | # endif | - | ||||||||||||||||||||||||
| 166 | #endif | - | ||||||||||||||||||||||||
| 167 | ) { | - | ||||||||||||||||||||||||
| 168 | p.truncate(p.length() - 1); | - | ||||||||||||||||||||||||
| 169 | } executed 769 times by 15 tests: end of blockExecuted by:
| 769 | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath()); | - | ||||||||||||||||||||||||
| 172 | metaData.clear(); | - | ||||||||||||||||||||||||
| 173 | initFileEngine(); | - | ||||||||||||||||||||||||
| 174 | clearFileLists(); | - | ||||||||||||||||||||||||
| 175 | absoluteDirEntry = QFileSystemEntry(); | - | ||||||||||||||||||||||||
| 176 | } executed 19020 times by 248 tests: end of blockExecuted by:
| 19020 | ||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | inline void QDirPrivate::clearFileLists() | - | ||||||||||||||||||||||||
| 179 | { | - | ||||||||||||||||||||||||
| 180 | fileListsInitialized = false; | - | ||||||||||||||||||||||||
| 181 | files.clear(); | - | ||||||||||||||||||||||||
| 182 | fileInfos.clear(); | - | ||||||||||||||||||||||||
| 183 | } executed 19723 times by 248 tests: end of blockExecuted by:
| 19723 | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | inline void QDirPrivate::resolveAbsoluteEntry() const | - | ||||||||||||||||||||||||
| 186 | { | - | ||||||||||||||||||||||||
| 187 | if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty())
| 0-8343 | ||||||||||||||||||||||||
| 188 | return; executed 5149 times by 14 tests: return;Executed by:
| 5149 | ||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||
| 190 | QString absoluteName; | - | ||||||||||||||||||||||||
| 191 | if (fileEngine.isNull()) {
| 5-8338 | ||||||||||||||||||||||||
| 192 | if (!dirEntry.isRelative() && dirEntry.isClean()) {
| 51-7949 | ||||||||||||||||||||||||
| 193 | absoluteDirEntry = dirEntry; | - | ||||||||||||||||||||||||
| 194 | return; executed 7898 times by 133 tests: return;Executed by:
| 7898 | ||||||||||||||||||||||||
| 195 | } | - | ||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath(); | - | ||||||||||||||||||||||||
| 198 | } else { executed 440 times by 14 tests: end of blockExecuted by:
| 440 | ||||||||||||||||||||||||
| 199 | absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName); | - | ||||||||||||||||||||||||
| 200 | } executed 5 times by 2 tests: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName), QFileSystemEntry::FromInternalPath()); | - | ||||||||||||||||||||||||
| 203 | } executed 445 times by 15 tests: end of blockExecuted by:
| 445 | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | /* For sorting */ | - | ||||||||||||||||||||||||
| 206 | struct QDirSortItem | - | ||||||||||||||||||||||||
| 207 | { | - | ||||||||||||||||||||||||
| 208 | mutable QString filename_cache; | - | ||||||||||||||||||||||||
| 209 | mutable QString suffix_cache; | - | ||||||||||||||||||||||||
| 210 | QFileInfo item; | - | ||||||||||||||||||||||||
| 211 | }; | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | class QDirSortItemComparator | - | ||||||||||||||||||||||||
| 215 | { | - | ||||||||||||||||||||||||
| 216 | int qt_cmp_si_sort_flags; | - | ||||||||||||||||||||||||
| 217 | public: | - | ||||||||||||||||||||||||
| 218 | QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {} executed 970 times by 128 tests: end of blockExecuted by:
| 970 | ||||||||||||||||||||||||
| 219 | bool operator()(const QDirSortItem &, const QDirSortItem &) const; | - | ||||||||||||||||||||||||
| 220 | }; | - | ||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortItem &n2) const | - | ||||||||||||||||||||||||
| 223 | { | - | ||||||||||||||||||||||||
| 224 | const QDirSortItem* f1 = &n1; | - | ||||||||||||||||||||||||
| 225 | const QDirSortItem* f2 = &n2; | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir()))
| 671-64747 | ||||||||||||||||||||||||
| 228 | return f1->item.isDir(); executed 671 times by 4 tests: return f1->item.isDir();Executed by:
| 671 | ||||||||||||||||||||||||
| 229 | if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir()))
| 102-69596 | ||||||||||||||||||||||||
| 230 | return !f1->item.isDir(); executed 102 times by 1 test: return !f1->item.isDir();Executed by:
| 102 | ||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | qint64 r = 0; | - | ||||||||||||||||||||||||
| 233 | int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask) | - | ||||||||||||||||||||||||
| 234 | | (qt_cmp_si_sort_flags & QDir::Type); | - | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | switch (sortBy) { | - | ||||||||||||||||||||||||
| 237 | case QDir::Time: { executed 307 times by 2 tests: case QDir::Time:Executed by:
| 307 | ||||||||||||||||||||||||
| 238 | QDateTime firstModified = f1->item.lastModified(); | - | ||||||||||||||||||||||||
| 239 | QDateTime secondModified = f2->item.lastModified(); | - | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | // QDateTime by default will do all sorts of conversions on these to | - | ||||||||||||||||||||||||
| 242 | // find timezones, which is incredibly expensive. As we aren't | - | ||||||||||||||||||||||||
| 243 | // presenting these to the user, we don't care (at all) about the | - | ||||||||||||||||||||||||
| 244 | // local timezone, so force them to UTC to avoid that conversion. | - | ||||||||||||||||||||||||
| 245 | firstModified.setTimeSpec(Qt::UTC); | - | ||||||||||||||||||||||||
| 246 | secondModified.setTimeSpec(Qt::UTC); | - | ||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||
| 248 | r = firstModified.msecsTo(secondModified); | - | ||||||||||||||||||||||||
| 249 | break; executed 307 times by 2 tests: break;Executed by:
| 307 | ||||||||||||||||||||||||
| 250 | } | - | ||||||||||||||||||||||||
| 251 | case QDir::Size: executed 486 times by 2 tests: case QDir::Size:Executed by:
| 486 | ||||||||||||||||||||||||
| 252 | r = f2->item.size() - f1->item.size(); | - | ||||||||||||||||||||||||
| 253 | break; executed 486 times by 2 tests: break;Executed by:
| 486 | ||||||||||||||||||||||||
| 254 | case QDir::Type: executed 795 times by 2 tests: case QDir::Type:Executed by:
| 795 | ||||||||||||||||||||||||
| 255 | { | - | ||||||||||||||||||||||||
| 256 | bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase; | - | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | if (f1->suffix_cache.isNull())
| 331-464 | ||||||||||||||||||||||||
| 259 | f1->suffix_cache = ic ? f1->item.suffix().toLower() executed 464 times by 2 tests: f1->suffix_cache = ic ? f1->item.suffix().toLower() : f1->item.suffix();Executed by:
| 160-464 | ||||||||||||||||||||||||
| 260 | : f1->item.suffix(); executed 464 times by 2 tests: f1->suffix_cache = ic ? f1->item.suffix().toLower() : f1->item.suffix();Executed by:
| 464 | ||||||||||||||||||||||||
| 261 | if (f2->suffix_cache.isNull())
| 367-428 | ||||||||||||||||||||||||
| 262 | f2->suffix_cache = ic ? f2->item.suffix().toLower() executed 428 times by 2 tests: f2->suffix_cache = ic ? f2->item.suffix().toLower() : f2->item.suffix();Executed by:
| 137-428 | ||||||||||||||||||||||||
| 263 | : f2->item.suffix(); executed 428 times by 2 tests: f2->suffix_cache = ic ? f2->item.suffix().toLower() : f2->item.suffix();Executed by:
| 428 | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | r = qt_cmp_si_sort_flags & QDir::LocaleAware
| 0-795 | ||||||||||||||||||||||||
| 266 | ? f1->suffix_cache.localeAwareCompare(f2->suffix_cache) | - | ||||||||||||||||||||||||
| 267 | : f1->suffix_cache.compare(f2->suffix_cache); | - | ||||||||||||||||||||||||
| 268 | } | - | ||||||||||||||||||||||||
| 269 | break; executed 795 times by 2 tests: break;Executed by:
| 795 | ||||||||||||||||||||||||
| 270 | default: executed 68200 times by 128 tests: default:Executed by:
| 68200 | ||||||||||||||||||||||||
| 271 | ; | - | ||||||||||||||||||||||||
| 272 | } executed 68200 times by 128 tests: end of blockExecuted by:
| 68200 | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | if (r == 0 && sortBy != QDir::Unsorted) {
| 0-69172 | ||||||||||||||||||||||||
| 275 | // Still not sorted - sort by name | - | ||||||||||||||||||||||||
| 276 | bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase; | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | if (f1->filename_cache.isNull())
| 7573-61599 | ||||||||||||||||||||||||
| 279 | f1->filename_cache = ic ? f1->item.fileName().toLower() executed 7573 times by 128 tests: f1->filename_cache = ic ? f1->item.fileName().toLower() : f1->item.fileName();Executed by:
| 3171-7573 | ||||||||||||||||||||||||
| 280 | : f1->item.fileName(); executed 7573 times by 128 tests: f1->filename_cache = ic ? f1->item.fileName().toLower() : f1->item.fileName();Executed by:
| 7573 | ||||||||||||||||||||||||
| 281 | if (f2->filename_cache.isNull())
| 4929-64243 | ||||||||||||||||||||||||
| 282 | f2->filename_cache = ic ? f2->item.fileName().toLower() executed 4929 times by 128 tests: f2->filename_cache = ic ? f2->item.fileName().toLower() : f2->item.fileName();Executed by:
| 1327-4929 | ||||||||||||||||||||||||
| 283 | : f2->item.fileName(); executed 4929 times by 128 tests: f2->filename_cache = ic ? f2->item.fileName().toLower() : f2->item.fileName();Executed by:
| 4929 | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | r = qt_cmp_si_sort_flags & QDir::LocaleAware
| 0-69172 | ||||||||||||||||||||||||
| 286 | ? f1->filename_cache.localeAwareCompare(f2->filename_cache) | - | ||||||||||||||||||||||||
| 287 | : f1->filename_cache.compare(f2->filename_cache); | - | ||||||||||||||||||||||||
| 288 | } executed 69172 times by 128 tests: end of blockExecuted by:
| 69172 | ||||||||||||||||||||||||
| 289 | if (qt_cmp_si_sort_flags & QDir::Reversed)
| 1579-68209 | ||||||||||||||||||||||||
| 290 | return r > 0; executed 1579 times by 2 tests: return r > 0;Executed by:
| 1579 | ||||||||||||||||||||||||
| 291 | return r < 0; executed 68209 times by 128 tests: return r < 0;Executed by:
| 68209 | ||||||||||||||||||||||||
| 292 | } | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, | - | ||||||||||||||||||||||||
| 295 | QStringList *names, QFileInfoList *infos) | - | ||||||||||||||||||||||||
| 296 | { | - | ||||||||||||||||||||||||
| 297 | // names and infos are always empty lists or 0 here | - | ||||||||||||||||||||||||
| 298 | int n = l.size(); | - | ||||||||||||||||||||||||
| 299 | if (n > 0) {
| 320-1154 | ||||||||||||||||||||||||
| 300 | if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) {
| 0-970 | ||||||||||||||||||||||||
| 301 | if (infos)
| 63-121 | ||||||||||||||||||||||||
| 302 | *infos = l; executed 121 times by 4 tests: *infos = l;Executed by:
| 121 | ||||||||||||||||||||||||
| 303 | if (names) {
| 65-119 | ||||||||||||||||||||||||
| 304 | for (int i = 0; i < n; ++i)
| 65 | ||||||||||||||||||||||||
| 305 | names->append(l.at(i).fileName()); executed 65 times by 3 tests: names->append(l.at(i).fileName());Executed by:
| 65 | ||||||||||||||||||||||||
| 306 | } executed 65 times by 3 tests: end of blockExecuted by:
| 65 | ||||||||||||||||||||||||
| 307 | } else { executed 184 times by 6 tests: end of blockExecuted by:
| 184 | ||||||||||||||||||||||||
| 308 | QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]); | - | ||||||||||||||||||||||||
| 309 | for (int i = 0; i < n; ++i)
| 970-12585 | ||||||||||||||||||||||||
| 310 | si[i].item = l.at(i); executed 12585 times by 128 tests: si[i].item = l.at(i);Executed by:
| 12585 | ||||||||||||||||||||||||
| 311 | std::sort(si.data(), si.data() + n, QDirSortItemComparator(sort)); | - | ||||||||||||||||||||||||
| 312 | // put them back in the list(s) | - | ||||||||||||||||||||||||
| 313 | if (infos) {
| 359-611 | ||||||||||||||||||||||||
| 314 | for (int i = 0; i < n; ++i)
| 611-10063 | ||||||||||||||||||||||||
| 315 | infos->append(si[i].item); executed 10063 times by 18 tests: infos->append(si[i].item);Executed by:
| 10063 | ||||||||||||||||||||||||
| 316 | } executed 611 times by 18 tests: end of blockExecuted by:
| 611 | ||||||||||||||||||||||||
| 317 | if (names) {
| 418-552 | ||||||||||||||||||||||||
| 318 | for (int i = 0; i < n; ++i)
| 418-2848 | ||||||||||||||||||||||||
| 319 | names->append(si[i].item.fileName()); executed 2848 times by 119 tests: names->append(si[i].item.fileName());Executed by:
| 2848 | ||||||||||||||||||||||||
| 320 | } executed 418 times by 119 tests: end of blockExecuted by:
| 418 | ||||||||||||||||||||||||
| 321 | } executed 970 times by 128 tests: end of blockExecuted by:
| 970 | ||||||||||||||||||||||||
| 322 | } | - | ||||||||||||||||||||||||
| 323 | } executed 1474 times by 129 tests: end of blockExecuted by:
| 1474 | ||||||||||||||||||||||||
| 324 | inline void QDirPrivate::initFileLists(const QDir &dir) const | - | ||||||||||||||||||||||||
| 325 | { | - | ||||||||||||||||||||||||
| 326 | if (!fileListsInitialized) {
| 66-95 | ||||||||||||||||||||||||
| 327 | QFileInfoList l; | - | ||||||||||||||||||||||||
| 328 | QDirIterator it(dir); | - | ||||||||||||||||||||||||
| 329 | while (it.hasNext()) {
| 66-328 | ||||||||||||||||||||||||
| 330 | it.next(); | - | ||||||||||||||||||||||||
| 331 | l.append(it.fileInfo()); | - | ||||||||||||||||||||||||
| 332 | } executed 328 times by 6 tests: end of blockExecuted by:
| 328 | ||||||||||||||||||||||||
| 333 | sortFileList(sort, l, &files, &fileInfos); | - | ||||||||||||||||||||||||
| 334 | fileListsInitialized = true; | - | ||||||||||||||||||||||||
| 335 | } executed 66 times by 7 tests: end of blockExecuted by:
| 66 | ||||||||||||||||||||||||
| 336 | } executed 161 times by 7 tests: end of blockExecuted by:
| 161 | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | inline void QDirPrivate::initFileEngine() | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | fileEngine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData)); | - | ||||||||||||||||||||||||
| 341 | } executed 19723 times by 248 tests: end of blockExecuted by:
| 19723 | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | /*! | - | ||||||||||||||||||||||||
| 344 | \class QDir | - | ||||||||||||||||||||||||
| 345 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 346 | \brief The QDir class provides access to directory structures and their contents. | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | \ingroup io | - | ||||||||||||||||||||||||
| 349 | \ingroup shared | - | ||||||||||||||||||||||||
| 350 | \reentrant | - | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | - | |||||||||||||||||||||||||
| 353 | A QDir is used to manipulate path names, access information | - | ||||||||||||||||||||||||
| 354 | regarding paths and files, and manipulate the underlying file | - | ||||||||||||||||||||||||
| 355 | system. It can also be used to access Qt's \l{resource system}. | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | Qt uses "/" as a universal directory separator in the same way | - | ||||||||||||||||||||||||
| 358 | that "/" is used as a path separator in URLs. If you always use | - | ||||||||||||||||||||||||
| 359 | "/" as a directory separator, Qt will translate your paths to | - | ||||||||||||||||||||||||
| 360 | conform to the underlying operating system. | - | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | A QDir can point to a file using either a relative or an absolute | - | ||||||||||||||||||||||||
| 363 | path. Absolute paths begin with the directory separator | - | ||||||||||||||||||||||||
| 364 | (optionally preceded by a drive specification under Windows). | - | ||||||||||||||||||||||||
| 365 | Relative file names begin with a directory name or a file name and | - | ||||||||||||||||||||||||
| 366 | specify a path relative to the current directory. | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | Examples of absolute paths: | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | \snippet code/src_corelib_io_qdir.cpp 0 | - | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | On Windows, the second example above will be translated to | - | ||||||||||||||||||||||||
| 373 | \c{C:\Documents and Settings} when used to access files. | - | ||||||||||||||||||||||||
| 374 | - | |||||||||||||||||||||||||
| 375 | Examples of relative paths: | - | ||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||
| 377 | \snippet code/src_corelib_io_qdir.cpp 1 | - | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | You can use the isRelative() or isAbsolute() functions to check if | - | ||||||||||||||||||||||||
| 380 | a QDir is using a relative or an absolute file path. Call | - | ||||||||||||||||||||||||
| 381 | makeAbsolute() to convert a relative QDir to an absolute one. | - | ||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||
| 383 | \section1 Navigation and Directory Operations | - | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | A directory's path can be obtained with the path() function, and | - | ||||||||||||||||||||||||
| 386 | a new path set with the setPath() function. The absolute path to | - | ||||||||||||||||||||||||
| 387 | a directory is found by calling absolutePath(). | - | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | The name of a directory is found using the dirName() function. This | - | ||||||||||||||||||||||||
| 390 | typically returns the last element in the absolute path that specifies | - | ||||||||||||||||||||||||
| 391 | the location of the directory. However, it can also return "." if | - | ||||||||||||||||||||||||
| 392 | the QDir represents the current directory. | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | \snippet code/src_corelib_io_qdir.cpp 2 | - | ||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | The path for a directory can also be changed with the cd() and cdUp() | - | ||||||||||||||||||||||||
| 397 | functions, both of which operate like familiar shell commands. | - | ||||||||||||||||||||||||
| 398 | When cd() is called with the name of an existing directory, the QDir | - | ||||||||||||||||||||||||
| 399 | object changes directory so that it represents that directory instead. | - | ||||||||||||||||||||||||
| 400 | The cdUp() function changes the directory of the QDir object so that | - | ||||||||||||||||||||||||
| 401 | it refers to its parent directory; i.e. cd("..") is equivalent to | - | ||||||||||||||||||||||||
| 402 | cdUp(). | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | Directories can be created with mkdir(), renamed with rename(), and | - | ||||||||||||||||||||||||
| 405 | removed with rmdir(). | - | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | You can test for the presence of a directory with a given name by | - | ||||||||||||||||||||||||
| 408 | using exists(), and the properties of a directory can be tested with | - | ||||||||||||||||||||||||
| 409 | isReadable(), isAbsolute(), isRelative(), and isRoot(). | - | ||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | The refresh() function re-reads the directory's data from disk. | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | \section1 Files and Directory Contents | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | Directories contain a number of entries, representing files, | - | ||||||||||||||||||||||||
| 416 | directories, and symbolic links. The number of entries in a | - | ||||||||||||||||||||||||
| 417 | directory is returned by count(). | - | ||||||||||||||||||||||||
| 418 | A string list of the names of all the entries in a directory can be | - | ||||||||||||||||||||||||
| 419 | obtained with entryList(). If you need information about each | - | ||||||||||||||||||||||||
| 420 | entry, use entryInfoList() to obtain a list of QFileInfo objects. | - | ||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||
| 422 | Paths to files and directories within a directory can be | - | ||||||||||||||||||||||||
| 423 | constructed using filePath() and absoluteFilePath(). | - | ||||||||||||||||||||||||
| 424 | The filePath() function returns a path to the specified file | - | ||||||||||||||||||||||||
| 425 | or directory relative to the path of the QDir object; | - | ||||||||||||||||||||||||
| 426 | absoluteFilePath() returns an absolute path to the specified | - | ||||||||||||||||||||||||
| 427 | file or directory. Neither of these functions checks for the | - | ||||||||||||||||||||||||
| 428 | existence of files or directory; they only construct paths. | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | \snippet code/src_corelib_io_qdir.cpp 3 | - | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | Files can be removed by using the remove() function. Directories | - | ||||||||||||||||||||||||
| 433 | cannot be removed in the same way as files; use rmdir() to remove | - | ||||||||||||||||||||||||
| 434 | them instead. | - | ||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | It is possible to reduce the number of entries returned by | - | ||||||||||||||||||||||||
| 437 | entryList() and entryInfoList() by applying filters to a QDir object. | - | ||||||||||||||||||||||||
| 438 | You can apply a name filter to specify a pattern with wildcards that | - | ||||||||||||||||||||||||
| 439 | file names need to match, an attribute filter that selects properties | - | ||||||||||||||||||||||||
| 440 | of entries and can distinguish between files and directories, and a | - | ||||||||||||||||||||||||
| 441 | sort order. | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | Name filters are lists of strings that are passed to setNameFilters(). | - | ||||||||||||||||||||||||
| 444 | Attribute filters consist of a bitwise OR combination of Filters, and | - | ||||||||||||||||||||||||
| 445 | these are specified when calling setFilter(). | - | ||||||||||||||||||||||||
| 446 | The sort order is specified using setSorting() with a bitwise OR | - | ||||||||||||||||||||||||
| 447 | combination of SortFlags. | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | You can test to see if a filename matches a filter using the match() | - | ||||||||||||||||||||||||
| 450 | function. | - | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | Filter and sort order flags may also be specified when calling | - | ||||||||||||||||||||||||
| 453 | entryList() and entryInfoList() in order to override previously defined | - | ||||||||||||||||||||||||
| 454 | behavior. | - | ||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | \section1 The Current Directory and Other Special Paths | - | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | Access to some common directories is provided with a number of static | - | ||||||||||||||||||||||||
| 459 | functions that return QDir objects. There are also corresponding functions | - | ||||||||||||||||||||||||
| 460 | for these that return strings: | - | ||||||||||||||||||||||||
| 461 | - | |||||||||||||||||||||||||
| 462 | \table | - | ||||||||||||||||||||||||
| 463 | \header \li QDir \li QString \li Return Value | - | ||||||||||||||||||||||||
| 464 | \row \li current() \li currentPath() \li The application's working directory | - | ||||||||||||||||||||||||
| 465 | \row \li home() \li homePath() \li The user's home directory | - | ||||||||||||||||||||||||
| 466 | \row \li root() \li rootPath() \li The root directory | - | ||||||||||||||||||||||||
| 467 | \row \li temp() \li tempPath() \li The system's temporary directory | - | ||||||||||||||||||||||||
| 468 | \endtable | - | ||||||||||||||||||||||||
| 469 | - | |||||||||||||||||||||||||
| 470 | The setCurrent() static function can also be used to set the application's | - | ||||||||||||||||||||||||
| 471 | working directory. | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | If you want to find the directory containing the application's executable, | - | ||||||||||||||||||||||||
| 474 | see \l{QCoreApplication::applicationDirPath()}. | - | ||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||
| 476 | The drives() static function provides a list of root directories for each | - | ||||||||||||||||||||||||
| 477 | device that contains a filing system. On Unix systems this returns a list | - | ||||||||||||||||||||||||
| 478 | containing a single root directory "/"; on Windows the list will usually | - | ||||||||||||||||||||||||
| 479 | contain \c{C:/}, and possibly other drive letters such as \c{D:/}, depending | - | ||||||||||||||||||||||||
| 480 | on the configuration of the user's system. | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | \section1 Path Manipulation and Strings | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | Paths containing "." elements that reference the current directory at that | - | ||||||||||||||||||||||||
| 485 | point in the path, ".." elements that reference the parent directory, and | - | ||||||||||||||||||||||||
| 486 | symbolic links can be reduced to a canonical form using the canonicalPath() | - | ||||||||||||||||||||||||
| 487 | function. | - | ||||||||||||||||||||||||
| 488 | - | |||||||||||||||||||||||||
| 489 | Paths can also be simplified by using cleanPath() to remove redundant "/" | - | ||||||||||||||||||||||||
| 490 | and ".." elements. | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | It is sometimes necessary to be able to show a path in the native | - | ||||||||||||||||||||||||
| 493 | representation for the user's platform. The static toNativeSeparators() | - | ||||||||||||||||||||||||
| 494 | function returns a copy of the specified path in which each directory | - | ||||||||||||||||||||||||
| 495 | separator is replaced by the appropriate separator for the underlying | - | ||||||||||||||||||||||||
| 496 | operating system. | - | ||||||||||||||||||||||||
| 497 | - | |||||||||||||||||||||||||
| 498 | \section1 Examples | - | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | Check if a directory exists: | - | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | \snippet code/src_corelib_io_qdir.cpp 4 | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | (We could also use the static convenience function | - | ||||||||||||||||||||||||
| 505 | QFile::exists().) | - | ||||||||||||||||||||||||
| 506 | - | |||||||||||||||||||||||||
| 507 | Traversing directories and reading a file: | - | ||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | \snippet code/src_corelib_io_qdir.cpp 5 | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | A program that lists all the files in the current directory | - | ||||||||||||||||||||||||
| 512 | (excluding symbolic links), sorted by size, smallest first: | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | \snippet qdir-listfiles/main.cpp 0 | - | ||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||
| 516 | \sa QFileInfo, QFile, QFileDialog, QCoreApplication::applicationDirPath(), {Find Files Example} | - | ||||||||||||||||||||||||
| 517 | */ | - | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | /*! | - | ||||||||||||||||||||||||
| 520 | \fn QDir &QDir::operator=(QDir &&other) | - | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | Move-assigns \a other to this QDir instance. | - | ||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||
| 524 | \since 5.2 | - | ||||||||||||||||||||||||
| 525 | */ | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | /*! | - | ||||||||||||||||||||||||
| 528 | \internal | - | ||||||||||||||||||||||||
| 529 | */ | - | ||||||||||||||||||||||||
| 530 | QDir::QDir(QDirPrivate &p) : d_ptr(&p) | - | ||||||||||||||||||||||||
| 531 | { | - | ||||||||||||||||||||||||
| 532 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | /*! | - | ||||||||||||||||||||||||
| 535 | Constructs a QDir pointing to the given directory \a path. If path | - | ||||||||||||||||||||||||
| 536 | is empty the program's working directory, ("."), is used. | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | \sa currentPath() | - | ||||||||||||||||||||||||
| 539 | */ | - | ||||||||||||||||||||||||
| 540 | QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(path)) | - | ||||||||||||||||||||||||
| 541 | { | - | ||||||||||||||||||||||||
| 542 | } executed 18066 times by 248 tests: end of blockExecuted by:
| 18066 | ||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||
| 544 | /*! | - | ||||||||||||||||||||||||
| 545 | Constructs a QDir with path \a path, that filters its entries by | - | ||||||||||||||||||||||||
| 546 | name using \a nameFilter and by attributes using \a filters. It | - | ||||||||||||||||||||||||
| 547 | also sorts the names using \a sort. | - | ||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||
| 549 | The default \a nameFilter is an empty string, which excludes | - | ||||||||||||||||||||||||
| 550 | nothing; the default \a filters is \l AllEntries, which also means | - | ||||||||||||||||||||||||
| 551 | exclude nothing. The default \a sort is \l Name | \l IgnoreCase, | - | ||||||||||||||||||||||||
| 552 | i.e. sort by name case-insensitively. | - | ||||||||||||||||||||||||
| 553 | - | |||||||||||||||||||||||||
| 554 | If \a path is an empty string, QDir uses "." (the current | - | ||||||||||||||||||||||||
| 555 | directory). If \a nameFilter is an empty string, QDir uses the | - | ||||||||||||||||||||||||
| 556 | name filter "*" (all files). | - | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | Note that \a path need not exist. | - | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | \sa exists(), setPath(), setNameFilters(), setFilter(), setSorting() | - | ||||||||||||||||||||||||
| 561 | */ | - | ||||||||||||||||||||||||
| 562 | QDir::QDir(const QString &path, const QString &nameFilter, | - | ||||||||||||||||||||||||
| 563 | SortFlags sort, Filters filters) | - | ||||||||||||||||||||||||
| 564 | : d_ptr(new QDirPrivate(path, QDir::nameFiltersFromString(nameFilter), sort, filters)) | - | ||||||||||||||||||||||||
| 565 | { | - | ||||||||||||||||||||||||
| 566 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | /*! | - | ||||||||||||||||||||||||
| 569 | Constructs a QDir object that is a copy of the QDir object for | - | ||||||||||||||||||||||||
| 570 | directory \a dir. | - | ||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||
| 572 | \sa operator=() | - | ||||||||||||||||||||||||
| 573 | */ | - | ||||||||||||||||||||||||
| 574 | QDir::QDir(const QDir &dir) | - | ||||||||||||||||||||||||
| 575 | : d_ptr(dir.d_ptr) | - | ||||||||||||||||||||||||
| 576 | { | - | ||||||||||||||||||||||||
| 577 | } executed 324 times by 7 tests: end of blockExecuted by:
| 324 | ||||||||||||||||||||||||
| 578 | - | |||||||||||||||||||||||||
| 579 | /*! | - | ||||||||||||||||||||||||
| 580 | Destroys the QDir object frees up its resources. This has no | - | ||||||||||||||||||||||||
| 581 | effect on the underlying directory in the file system. | - | ||||||||||||||||||||||||
| 582 | */ | - | ||||||||||||||||||||||||
| 583 | QDir::~QDir() | - | ||||||||||||||||||||||||
| 584 | { | - | ||||||||||||||||||||||||
| 585 | } | - | ||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||||||||
| 588 | Sets the path of the directory to \a path. The path is cleaned of | - | ||||||||||||||||||||||||
| 589 | redundant ".", ".." and of multiple separators. No check is made | - | ||||||||||||||||||||||||
| 590 | to see whether a directory with this path actually exists; but you | - | ||||||||||||||||||||||||
| 591 | can check for yourself using exists(). | - | ||||||||||||||||||||||||
| 592 | - | |||||||||||||||||||||||||
| 593 | The path can be either absolute or relative. Absolute paths begin | - | ||||||||||||||||||||||||
| 594 | with the directory separator "/" (optionally preceded by a drive | - | ||||||||||||||||||||||||
| 595 | specification under Windows). Relative file names begin with a | - | ||||||||||||||||||||||||
| 596 | directory name or a file name and specify a path relative to the | - | ||||||||||||||||||||||||
| 597 | current directory. An example of an absolute path is the string | - | ||||||||||||||||||||||||
| 598 | "/tmp/quartz", a relative path might look like "src/fatlib". | - | ||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||
| 600 | \sa path(), absolutePath(), exists(), cleanPath(), dirName(), | - | ||||||||||||||||||||||||
| 601 | absoluteFilePath(), isRelative(), makeAbsolute() | - | ||||||||||||||||||||||||
| 602 | */ | - | ||||||||||||||||||||||||
| 603 | void QDir::setPath(const QString &path) | - | ||||||||||||||||||||||||
| 604 | { | - | ||||||||||||||||||||||||
| 605 | d_ptr->setPath(path); | - | ||||||||||||||||||||||||
| 606 | } executed 873 times by 12 tests: end of blockExecuted by:
| 873 | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | /*! | - | ||||||||||||||||||||||||
| 609 | Returns the path. This may contain symbolic links, but never | - | ||||||||||||||||||||||||
| 610 | contains redundant ".", ".." or multiple separators. | - | ||||||||||||||||||||||||
| 611 | - | |||||||||||||||||||||||||
| 612 | The returned path can be either absolute or relative (see | - | ||||||||||||||||||||||||
| 613 | setPath()). | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | \sa setPath(), absolutePath(), exists(), cleanPath(), dirName(), | - | ||||||||||||||||||||||||
| 616 | absoluteFilePath(), toNativeSeparators(), makeAbsolute() | - | ||||||||||||||||||||||||
| 617 | */ | - | ||||||||||||||||||||||||
| 618 | QString QDir::path() const | - | ||||||||||||||||||||||||
| 619 | { | - | ||||||||||||||||||||||||
| 620 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 621 | return d->dirEntry.filePath(); executed 17022 times by 74 tests: return d->dirEntry.filePath();Executed by:
| 17022 | ||||||||||||||||||||||||
| 622 | } | - | ||||||||||||||||||||||||
| 623 | - | |||||||||||||||||||||||||
| 624 | /*! | - | ||||||||||||||||||||||||
| 625 | Returns the absolute path (a path that starts with "/" or with a | - | ||||||||||||||||||||||||
| 626 | drive specification), which may contain symbolic links, but never | - | ||||||||||||||||||||||||
| 627 | contains redundant ".", ".." or multiple separators. | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | \sa setPath(), canonicalPath(), exists(), cleanPath(), | - | ||||||||||||||||||||||||
| 630 | dirName(), absoluteFilePath() | - | ||||||||||||||||||||||||
| 631 | */ | - | ||||||||||||||||||||||||
| 632 | QString QDir::absolutePath() const | - | ||||||||||||||||||||||||
| 633 | { | - | ||||||||||||||||||||||||
| 634 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 635 | d->resolveAbsoluteEntry(); | - | ||||||||||||||||||||||||
| 636 | return d->absoluteDirEntry.filePath(); executed 12064 times by 65 tests: return d->absoluteDirEntry.filePath();Executed by:
| 12064 | ||||||||||||||||||||||||
| 637 | } | - | ||||||||||||||||||||||||
| 638 | - | |||||||||||||||||||||||||
| 639 | /*! | - | ||||||||||||||||||||||||
| 640 | Returns the canonical path, i.e. a path without symbolic links or | - | ||||||||||||||||||||||||
| 641 | redundant "." or ".." elements. | - | ||||||||||||||||||||||||
| 642 | - | |||||||||||||||||||||||||
| 643 | On systems that do not have symbolic links this function will | - | ||||||||||||||||||||||||
| 644 | always return the same string that absolutePath() returns. If the | - | ||||||||||||||||||||||||
| 645 | canonical path does not exist (normally due to dangling symbolic | - | ||||||||||||||||||||||||
| 646 | links) canonicalPath() returns an empty string. | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | Example: | - | ||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||
| 650 | \snippet code/src_corelib_io_qdir.cpp 6 | - | ||||||||||||||||||||||||
| 651 | - | |||||||||||||||||||||||||
| 652 | \sa path(), absolutePath(), exists(), cleanPath(), dirName(), | - | ||||||||||||||||||||||||
| 653 | absoluteFilePath() | - | ||||||||||||||||||||||||
| 654 | */ | - | ||||||||||||||||||||||||
| 655 | QString QDir::canonicalPath() const | - | ||||||||||||||||||||||||
| 656 | { | - | ||||||||||||||||||||||||
| 657 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 658 | if (d->fileEngine.isNull()) {
| 1-1186 | ||||||||||||||||||||||||
| 659 | QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData); | - | ||||||||||||||||||||||||
| 660 | return answer.filePath(); executed 1186 times by 36 tests: return answer.filePath();Executed by:
| 1186 | ||||||||||||||||||||||||
| 661 | } | - | ||||||||||||||||||||||||
| 662 | return d->fileEngine->fileName(QAbstractFileEngine::CanonicalName); executed 1 time by 1 test: return d->fileEngine->fileName(QAbstractFileEngine::CanonicalName);Executed by:
| 1 | ||||||||||||||||||||||||
| 663 | } | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | /*! | - | ||||||||||||||||||||||||
| 666 | Returns the name of the directory; this is \e not the same as the | - | ||||||||||||||||||||||||
| 667 | path, e.g. a directory with the name "mail", might have the path | - | ||||||||||||||||||||||||
| 668 | "/var/spool/mail". If the directory has no name (e.g. it is the | - | ||||||||||||||||||||||||
| 669 | root directory) an empty string is returned. | - | ||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||
| 671 | No check is made to ensure that a directory with this name | - | ||||||||||||||||||||||||
| 672 | actually exists; but see exists(). | - | ||||||||||||||||||||||||
| 673 | - | |||||||||||||||||||||||||
| 674 | \sa path(), filePath(), absolutePath(), absoluteFilePath() | - | ||||||||||||||||||||||||
| 675 | */ | - | ||||||||||||||||||||||||
| 676 | QString QDir::dirName() const | - | ||||||||||||||||||||||||
| 677 | { | - | ||||||||||||||||||||||||
| 678 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 679 | return d->dirEntry.fileName(); executed 25 times by 6 tests: return d->dirEntry.fileName();Executed by:
| 25 | ||||||||||||||||||||||||
| 680 | } | - | ||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | /*! | - | ||||||||||||||||||||||||
| 683 | Returns the path name of a file in the directory. Does \e not | - | ||||||||||||||||||||||||
| 684 | check if the file actually exists in the directory; but see | - | ||||||||||||||||||||||||
| 685 | exists(). If the QDir is relative the returned path name will also | - | ||||||||||||||||||||||||
| 686 | be relative. Redundant multiple separators or "." and ".." | - | ||||||||||||||||||||||||
| 687 | directories in \a fileName are not removed (see cleanPath()). | - | ||||||||||||||||||||||||
| 688 | - | |||||||||||||||||||||||||
| 689 | \sa dirName(), absoluteFilePath(), isRelative(), canonicalPath() | - | ||||||||||||||||||||||||
| 690 | */ | - | ||||||||||||||||||||||||
| 691 | QString QDir::filePath(const QString &fileName) const | - | ||||||||||||||||||||||||
| 692 | { | - | ||||||||||||||||||||||||
| 693 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 694 | if (isAbsolutePath(fileName))
| 4239-7833 | ||||||||||||||||||||||||
| 695 | return fileName; executed 4239 times by 59 tests: return fileName;Executed by:
| 4239 | ||||||||||||||||||||||||
| 696 | - | |||||||||||||||||||||||||
| 697 | QString ret = d->dirEntry.filePath(); | - | ||||||||||||||||||||||||
| 698 | if (!fileName.isEmpty()) {
| 1-7832 | ||||||||||||||||||||||||
| 699 | if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/'))
| 0-7832 | ||||||||||||||||||||||||
| 700 | ret += QLatin1Char('/'); executed 7831 times by 217 tests: ret += QLatin1Char('/');Executed by:
| 7831 | ||||||||||||||||||||||||
| 701 | ret += fileName; | - | ||||||||||||||||||||||||
| 702 | } executed 7832 times by 217 tests: end of blockExecuted by:
| 7832 | ||||||||||||||||||||||||
| 703 | return ret; executed 7833 times by 217 tests: return ret;Executed by:
| 7833 | ||||||||||||||||||||||||
| 704 | } | - | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | /*! | - | ||||||||||||||||||||||||
| 707 | Returns the absolute path name of a file in the directory. Does \e | - | ||||||||||||||||||||||||
| 708 | not check if the file actually exists in the directory; but see | - | ||||||||||||||||||||||||
| 709 | exists(). Redundant multiple separators or "." and ".." | - | ||||||||||||||||||||||||
| 710 | directories in \a fileName are not removed (see cleanPath()). | - | ||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||
| 712 | \sa relativeFilePath(), filePath(), canonicalPath() | - | ||||||||||||||||||||||||
| 713 | */ | - | ||||||||||||||||||||||||
| 714 | QString QDir::absoluteFilePath(const QString &fileName) const | - | ||||||||||||||||||||||||
| 715 | { | - | ||||||||||||||||||||||||
| 716 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 717 | if (isAbsolutePath(fileName))
| 240-1419 | ||||||||||||||||||||||||
| 718 | return fileName; executed 240 times by 6 tests: return fileName;Executed by:
| 240 | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | d->resolveAbsoluteEntry(); | - | ||||||||||||||||||||||||
| 721 | const QString absoluteDirPath = d->absoluteDirEntry.filePath(); | - | ||||||||||||||||||||||||
| 722 | if (fileName.isEmpty())
| 4-1415 | ||||||||||||||||||||||||
| 723 | return absoluteDirPath; executed 4 times by 2 tests: return absoluteDirPath;Executed by:
| 4 | ||||||||||||||||||||||||
| 724 | if (!absoluteDirPath.endsWith(QLatin1Char('/')))
| 1-1414 | ||||||||||||||||||||||||
| 725 | return absoluteDirPath % QLatin1Char('/') % fileName; executed 1414 times by 88 tests: return absoluteDirPath % QLatin1Char('/') % fileName;Executed by:
| 1414 | ||||||||||||||||||||||||
| 726 | return absoluteDirPath % fileName; executed 1 time by 1 test: return absoluteDirPath % fileName;Executed by:
| 1 | ||||||||||||||||||||||||
| 727 | } | - | ||||||||||||||||||||||||
| 728 | - | |||||||||||||||||||||||||
| 729 | /*! | - | ||||||||||||||||||||||||
| 730 | Returns the path to \a fileName relative to the directory. | - | ||||||||||||||||||||||||
| 731 | - | |||||||||||||||||||||||||
| 732 | \snippet code/src_corelib_io_qdir.cpp 7 | - | ||||||||||||||||||||||||
| 733 | - | |||||||||||||||||||||||||
| 734 | \sa absoluteFilePath(), filePath(), canonicalPath() | - | ||||||||||||||||||||||||
| 735 | */ | - | ||||||||||||||||||||||||
| 736 | QString QDir::relativeFilePath(const QString &fileName) const | - | ||||||||||||||||||||||||
| 737 | { | - | ||||||||||||||||||||||||
| 738 | QString dir = cleanPath(absolutePath()); | - | ||||||||||||||||||||||||
| 739 | QString file = cleanPath(fileName); | - | ||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||
| 741 | if (isRelativePath(file) || isRelativePath(dir))
| 0-66 | ||||||||||||||||||||||||
| 742 | return file; executed 41 times by 2 tests: return file;Executed by:
| 41 | ||||||||||||||||||||||||
| 743 | - | |||||||||||||||||||||||||
| 744 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 745 | QString dirDrive = driveSpec(dir); | - | ||||||||||||||||||||||||
| 746 | QString fileDrive = driveSpec(file); | - | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | bool fileDriveMissing = false; | - | ||||||||||||||||||||||||
| 749 | if (fileDrive.isEmpty()) { | - | ||||||||||||||||||||||||
| 750 | fileDrive = dirDrive; | - | ||||||||||||||||||||||||
| 751 | fileDriveMissing = true; | - | ||||||||||||||||||||||||
| 752 | } | - | ||||||||||||||||||||||||
| 753 | - | |||||||||||||||||||||||||
| 754 | if (fileDrive.toLower() != dirDrive.toLower() | - | ||||||||||||||||||||||||
| 755 | || (file.startsWith(QLatin1String("//")) | - | ||||||||||||||||||||||||
| 756 | && !dir.startsWith(QLatin1String("//")))) | - | ||||||||||||||||||||||||
| 757 | return file; | - | ||||||||||||||||||||||||
| 758 | - | |||||||||||||||||||||||||
| 759 | dir.remove(0, dirDrive.size()); | - | ||||||||||||||||||||||||
| 760 | if (!fileDriveMissing) | - | ||||||||||||||||||||||||
| 761 | file.remove(0, fileDrive.size()); | - | ||||||||||||||||||||||||
| 762 | #endif | - | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | QString result; | - | ||||||||||||||||||||||||
| 765 | QVector<QStringRef> dirElts = dir.splitRef(QLatin1Char('/'), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
| 766 | QVector<QStringRef> fileElts = file.splitRef(QLatin1Char('/'), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
| 767 | - | |||||||||||||||||||||||||
| 768 | int i = 0; | - | ||||||||||||||||||||||||
| 769 | while (i < dirElts.size() && i < fileElts.size() &&
| 0-132 | ||||||||||||||||||||||||
| 770 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 771 | dirElts.at(i).compare(fileElts.at(i), Qt::CaseInsensitive) == 0) | - | ||||||||||||||||||||||||
| 772 | #else | - | ||||||||||||||||||||||||
| 773 | dirElts.at(i) == fileElts.at(i))
| 4-128 | ||||||||||||||||||||||||
| 774 | #endif | - | ||||||||||||||||||||||||
| 775 | ++i; executed 128 times by 3 tests: ++i;Executed by:
| 128 | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | for (int j = 0; j < dirElts.size() - i; ++j)
| 32-66 | ||||||||||||||||||||||||
| 778 | result += QLatin1String("../"); executed 32 times by 2 tests: result += QLatin1String("../");Executed by:
| 32 | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | for (int j = i; j < fileElts.size(); ++j) {
| 66-92 | ||||||||||||||||||||||||
| 781 | result += fileElts.at(j); | - | ||||||||||||||||||||||||
| 782 | if (j < fileElts.size() - 1)
| 30-62 | ||||||||||||||||||||||||
| 783 | result += QLatin1Char('/'); executed 30 times by 4 tests: result += QLatin1Char('/');Executed by:
| 30 | ||||||||||||||||||||||||
| 784 | } executed 92 times by 4 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | if (result.isEmpty())
| 4-62 | ||||||||||||||||||||||||
| 787 | return QLatin1String("."); executed 4 times by 2 tests: return QLatin1String(".");Executed by:
| 4 | ||||||||||||||||||||||||
| 788 | return result; executed 62 times by 4 tests: return result;Executed by:
| 62 | ||||||||||||||||||||||||
| 789 | } | - | ||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | /*! | - | ||||||||||||||||||||||||
| 792 | \since 4.2 | - | ||||||||||||||||||||||||
| 793 | - | |||||||||||||||||||||||||
| 794 | Returns \a pathName with the '/' separators converted to | - | ||||||||||||||||||||||||
| 795 | separators that are appropriate for the underlying operating | - | ||||||||||||||||||||||||
| 796 | system. | - | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | On Windows, toNativeSeparators("c:/winnt/system32") returns | - | ||||||||||||||||||||||||
| 799 | "c:\\winnt\\system32". | - | ||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||
| 801 | The returned string may be the same as the argument on some | - | ||||||||||||||||||||||||
| 802 | operating systems, for example on Unix. | - | ||||||||||||||||||||||||
| 803 | - | |||||||||||||||||||||||||
| 804 | \sa fromNativeSeparators(), separator() | - | ||||||||||||||||||||||||
| 805 | */ | - | ||||||||||||||||||||||||
| 806 | QString QDir::toNativeSeparators(const QString &pathName) | - | ||||||||||||||||||||||||
| 807 | { | - | ||||||||||||||||||||||||
| 808 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 809 | int i = pathName.indexOf(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 810 | if (i != -1) { | - | ||||||||||||||||||||||||
| 811 | QString n(pathName); | - | ||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||
| 813 | QChar * const data = n.data(); | - | ||||||||||||||||||||||||
| 814 | data[i++] = QLatin1Char('\\'); | - | ||||||||||||||||||||||||
| 815 | - | |||||||||||||||||||||||||
| 816 | for (; i < n.length(); ++i) { | - | ||||||||||||||||||||||||
| 817 | if (data[i] == QLatin1Char('/')) | - | ||||||||||||||||||||||||
| 818 | data[i] = QLatin1Char('\\'); | - | ||||||||||||||||||||||||
| 819 | } | - | ||||||||||||||||||||||||
| 820 | - | |||||||||||||||||||||||||
| 821 | return n; | - | ||||||||||||||||||||||||
| 822 | } | - | ||||||||||||||||||||||||
| 823 | #endif | - | ||||||||||||||||||||||||
| 824 | return pathName; executed 119668 times by 271 tests: return pathName;Executed by:
| 119668 | ||||||||||||||||||||||||
| 825 | } | - | ||||||||||||||||||||||||
| 826 | - | |||||||||||||||||||||||||
| 827 | /*! | - | ||||||||||||||||||||||||
| 828 | \since 4.2 | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | Returns \a pathName using '/' as file separator. On Windows, | - | ||||||||||||||||||||||||
| 831 | for instance, fromNativeSeparators("\c{c:\\winnt\\system32}") returns | - | ||||||||||||||||||||||||
| 832 | "c:/winnt/system32". | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | The returned string may be the same as the argument on some | - | ||||||||||||||||||||||||
| 835 | operating systems, for example on Unix. | - | ||||||||||||||||||||||||
| 836 | - | |||||||||||||||||||||||||
| 837 | \sa toNativeSeparators(), separator() | - | ||||||||||||||||||||||||
| 838 | */ | - | ||||||||||||||||||||||||
| 839 | QString QDir::fromNativeSeparators(const QString &pathName) | - | ||||||||||||||||||||||||
| 840 | { | - | ||||||||||||||||||||||||
| 841 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 842 | int i = pathName.indexOf(QLatin1Char('\\')); | - | ||||||||||||||||||||||||
| 843 | if (i != -1) { | - | ||||||||||||||||||||||||
| 844 | QString n(pathName); | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | QChar * const data = n.data(); | - | ||||||||||||||||||||||||
| 847 | data[i++] = QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 848 | - | |||||||||||||||||||||||||
| 849 | for (; i < n.length(); ++i) { | - | ||||||||||||||||||||||||
| 850 | if (data[i] == QLatin1Char('\\')) | - | ||||||||||||||||||||||||
| 851 | data[i] = QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 852 | } | - | ||||||||||||||||||||||||
| 853 | - | |||||||||||||||||||||||||
| 854 | return n; | - | ||||||||||||||||||||||||
| 855 | } | - | ||||||||||||||||||||||||
| 856 | #endif | - | ||||||||||||||||||||||||
| 857 | return pathName; executed 613846 times by 310 tests: return pathName;Executed by:
| 613846 | ||||||||||||||||||||||||
| 858 | } | - | ||||||||||||||||||||||||
| 859 | - | |||||||||||||||||||||||||
| 860 | /*! | - | ||||||||||||||||||||||||
| 861 | Changes the QDir's directory to \a dirName. | - | ||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 | Returns \c true if the new directory exists; | - | ||||||||||||||||||||||||
| 864 | otherwise returns \c false. Note that the logical cd() operation is | - | ||||||||||||||||||||||||
| 865 | not performed if the new directory does not exist. | - | ||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||
| 867 | Calling cd("..") is equivalent to calling cdUp(). | - | ||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||
| 869 | \sa cdUp(), isReadable(), exists(), path() | - | ||||||||||||||||||||||||
| 870 | */ | - | ||||||||||||||||||||||||
| 871 | bool QDir::cd(const QString &dirName) | - | ||||||||||||||||||||||||
| 872 | { | - | ||||||||||||||||||||||||
| 873 | // Don't detach just yet. | - | ||||||||||||||||||||||||
| 874 | const QDirPrivate * const d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | if (dirName.isEmpty() || dirName == QLatin1String("."))
| 0-58 | ||||||||||||||||||||||||
| 877 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||||||||
| 878 | QString newPath; | - | ||||||||||||||||||||||||
| 879 | if (isAbsolutePath(dirName)) {
| 3-54 | ||||||||||||||||||||||||
| 880 | newPath = cleanPath(dirName); | - | ||||||||||||||||||||||||
| 881 | } else { executed 3 times by 2 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 882 | if (isRoot())
| 4-50 | ||||||||||||||||||||||||
| 883 | newPath = d->dirEntry.filePath(); executed 4 times by 2 tests: newPath = d->dirEntry.filePath();Executed by:
| 4 | ||||||||||||||||||||||||
| 884 | else | - | ||||||||||||||||||||||||
| 885 | newPath = d->dirEntry.filePath() % QLatin1Char('/'); executed 50 times by 10 tests: newPath = d->dirEntry.filePath() % QLatin1Char('/');Executed by:
| 50 | ||||||||||||||||||||||||
| 886 | newPath += dirName; | - | ||||||||||||||||||||||||
| 887 | if (dirName.indexOf(QLatin1Char('/')) >= 0
| 4-50 | ||||||||||||||||||||||||
| 888 | || dirName == QLatin1String("..")
| 18-32 | ||||||||||||||||||||||||
| 889 | || d->dirEntry.filePath() == QLatin1String(".")) {
| 3-15 | ||||||||||||||||||||||||
| 890 | newPath = cleanPath(newPath); | - | ||||||||||||||||||||||||
| 891 | #if defined (Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 892 | //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. | - | ||||||||||||||||||||||||
| 893 | if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/.."))
| 0-39 | ||||||||||||||||||||||||
| 894 | #elif defined (Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 895 | const QString rootPath = QDir::rootPath(); | - | ||||||||||||||||||||||||
| 896 | if (newPath.size() < rootPath.size() && rootPath.startsWith(newPath)) | - | ||||||||||||||||||||||||
| 897 | #else | - | ||||||||||||||||||||||||
| 898 | /* | - | ||||||||||||||||||||||||
| 899 | cleanPath() already took care of replacing '\' with '/'. | - | ||||||||||||||||||||||||
| 900 | We can't use startsWith here because the letter of the drive is unknown. | - | ||||||||||||||||||||||||
| 901 | After cleanPath() if path is "[A-Z]:/.." or starts with "[A-Z]:/../" it means trying to cd above root. | - | ||||||||||||||||||||||||
| 902 | */ | - | ||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | if (newPath.midRef(1, 4) == QLatin1String(":/..") && (newPath.length() == 5 || newPath.at(5) == QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 905 | #endif | - | ||||||||||||||||||||||||
| 906 | return false; executed 5 times by 2 tests: return false;Executed by:
| 5 | ||||||||||||||||||||||||
| 907 | /* | - | ||||||||||||||||||||||||
| 908 | If newPath starts with .., we convert it to absolute to | - | ||||||||||||||||||||||||
| 909 | avoid infinite looping on | - | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | QDir dir("."); | - | ||||||||||||||||||||||||
| 912 | while (dir.cdUp()) | - | ||||||||||||||||||||||||
| 913 | ; | - | ||||||||||||||||||||||||
| 914 | */ | - | ||||||||||||||||||||||||
| 915 | if (newPath.startsWith(QLatin1String(".."))) {
| 2-32 | ||||||||||||||||||||||||
| 916 | newPath = QFileInfo(newPath).absoluteFilePath(); | - | ||||||||||||||||||||||||
| 917 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 918 | } executed 34 times by 8 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 919 | } executed 49 times by 10 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | QScopedPointer<QDirPrivate> dir(new QDirPrivate(*d_ptr.constData())); | - | ||||||||||||||||||||||||
| 922 | dir->setPath(newPath); | - | ||||||||||||||||||||||||
| 923 | if (!dir->exists())
| 3-49 | ||||||||||||||||||||||||
| 924 | return false; executed 3 times by 2 tests: return false;Executed by:
| 3 | ||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||
| 926 | d_ptr = dir.take(); | - | ||||||||||||||||||||||||
| 927 | return true; executed 49 times by 11 tests: return true;Executed by:
| 49 | ||||||||||||||||||||||||
| 928 | } | - | ||||||||||||||||||||||||
| 929 | - | |||||||||||||||||||||||||
| 930 | /*! | - | ||||||||||||||||||||||||
| 931 | Changes directory by moving one directory up from the QDir's | - | ||||||||||||||||||||||||
| 932 | current directory. | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | Returns \c true if the new directory exists; | - | ||||||||||||||||||||||||
| 935 | otherwise returns \c false. Note that the logical cdUp() operation is | - | ||||||||||||||||||||||||
| 936 | not performed if the new directory does not exist. | - | ||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||
| 938 | \sa cd(), isReadable(), exists(), path() | - | ||||||||||||||||||||||||
| 939 | */ | - | ||||||||||||||||||||||||
| 940 | bool QDir::cdUp() | - | ||||||||||||||||||||||||
| 941 | { | - | ||||||||||||||||||||||||
| 942 | return cd(QString::fromLatin1("..")); executed 26 times by 8 tests: return cd(QString::fromLatin1(".."));Executed by:
| 26 | ||||||||||||||||||||||||
| 943 | } | - | ||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||
| 945 | /*! | - | ||||||||||||||||||||||||
| 946 | Returns the string list set by setNameFilters() | - | ||||||||||||||||||||||||
| 947 | */ | - | ||||||||||||||||||||||||
| 948 | QStringList QDir::nameFilters() const | - | ||||||||||||||||||||||||
| 949 | { | - | ||||||||||||||||||||||||
| 950 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 951 | return d->nameFilters; executed 13 times by 1 test: return d->nameFilters;Executed by:
| 13 | ||||||||||||||||||||||||
| 952 | } | - | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | /*! | - | ||||||||||||||||||||||||
| 955 | Sets the name filters used by entryList() and entryInfoList() to the | - | ||||||||||||||||||||||||
| 956 | list of filters specified by \a nameFilters. | - | ||||||||||||||||||||||||
| 957 | - | |||||||||||||||||||||||||
| 958 | Each name filter is a wildcard (globbing) filter that understands | - | ||||||||||||||||||||||||
| 959 | \c{*} and \c{?} wildcards. (See \l{QRegExp wildcard matching}.) | - | ||||||||||||||||||||||||
| 960 | - | |||||||||||||||||||||||||
| 961 | For example, the following code sets three name filters on a QDir | - | ||||||||||||||||||||||||
| 962 | to ensure that only files with extensions typically used for C++ | - | ||||||||||||||||||||||||
| 963 | source files are listed: | - | ||||||||||||||||||||||||
| 964 | - | |||||||||||||||||||||||||
| 965 | \snippet qdir-namefilters/main.cpp 0 | - | ||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||
| 967 | \sa nameFilters(), setFilter() | - | ||||||||||||||||||||||||
| 968 | */ | - | ||||||||||||||||||||||||
| 969 | void QDir::setNameFilters(const QStringList &nameFilters) | - | ||||||||||||||||||||||||
| 970 | { | - | ||||||||||||||||||||||||
| 971 | QDirPrivate* d = d_ptr.data(); | - | ||||||||||||||||||||||||
| 972 | d->initFileEngine(); | - | ||||||||||||||||||||||||
| 973 | d->clearFileLists(); | - | ||||||||||||||||||||||||
| 974 | - | |||||||||||||||||||||||||
| 975 | d->nameFilters = nameFilters; | - | ||||||||||||||||||||||||
| 976 | } executed 376 times by 9 tests: end of blockExecuted by:
| 376 | ||||||||||||||||||||||||
| 977 | - | |||||||||||||||||||||||||
| 978 | /*! | - | ||||||||||||||||||||||||
| 979 | \obsolete | - | ||||||||||||||||||||||||
| 980 | - | |||||||||||||||||||||||||
| 981 | Use QDir::addSearchPath() with a prefix instead. | - | ||||||||||||||||||||||||
| 982 | - | |||||||||||||||||||||||||
| 983 | Adds \a path to the search paths searched in to find resources | - | ||||||||||||||||||||||||
| 984 | that are not specified with an absolute path. The default search | - | ||||||||||||||||||||||||
| 985 | path is to search only in the root (\c{:/}). | - | ||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||
| 987 | \sa {The Qt Resource System} | - | ||||||||||||||||||||||||
| 988 | */ | - | ||||||||||||||||||||||||
| 989 | void QDir::addResourceSearchPath(const QString &path) | - | ||||||||||||||||||||||||
| 990 | { | - | ||||||||||||||||||||||||
| 991 | #ifdef QT_BUILD_CORE_LIB | - | ||||||||||||||||||||||||
| 992 | QResource::addSearchPath(path); | - | ||||||||||||||||||||||||
| 993 | #else | - | ||||||||||||||||||||||||
| 994 | Q_UNUSED(path) | - | ||||||||||||||||||||||||
| 995 | #endif | - | ||||||||||||||||||||||||
| 996 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | #ifdef QT_BUILD_CORE_LIB | - | ||||||||||||||||||||||||
| 999 | /*! | - | ||||||||||||||||||||||||
| 1000 | \since 4.3 | - | ||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | Sets or replaces Qt's search paths for file names with the prefix \a prefix | - | ||||||||||||||||||||||||
| 1003 | to \a searchPaths. | - | ||||||||||||||||||||||||
| 1004 | - | |||||||||||||||||||||||||
| 1005 | To specify a prefix for a file name, prepend the prefix followed by a single | - | ||||||||||||||||||||||||
| 1006 | colon (e.g., "images:undo.png", "xmldocs:books.xml"). \a prefix can only | - | ||||||||||||||||||||||||
| 1007 | contain letters or numbers (e.g., it cannot contain a colon, nor a slash). | - | ||||||||||||||||||||||||
| 1008 | - | |||||||||||||||||||||||||
| 1009 | Qt uses this search path to locate files with a known prefix. The search | - | ||||||||||||||||||||||||
| 1010 | path entries are tested in order, starting with the first entry. | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | \snippet code/src_corelib_io_qdir.cpp 8 | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | File name prefix must be at least 2 characters long to avoid conflicts with | - | ||||||||||||||||||||||||
| 1015 | Windows drive letters. | - | ||||||||||||||||||||||||
| 1016 | - | |||||||||||||||||||||||||
| 1017 | Search paths may contain paths to \l{The Qt Resource System}. | - | ||||||||||||||||||||||||
| 1018 | */ | - | ||||||||||||||||||||||||
| 1019 | void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths) | - | ||||||||||||||||||||||||
| 1020 | { | - | ||||||||||||||||||||||||
| 1021 | if (prefix.length() < 2) {
| 0-35 | ||||||||||||||||||||||||
| 1022 | qWarning("QDir::setSearchPaths: Prefix must be longer than 1 character"); | - | ||||||||||||||||||||||||
| 1023 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1024 | } | - | ||||||||||||||||||||||||
| 1025 | - | |||||||||||||||||||||||||
| 1026 | for (int i = 0; i < prefix.count(); ++i) {
| 35-318 | ||||||||||||||||||||||||
| 1027 | if (!prefix.at(i).isLetterOrNumber()) {
| 0-318 | ||||||||||||||||||||||||
| 1028 | qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers"); | - | ||||||||||||||||||||||||
| 1029 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||||||||
| 1031 | } executed 318 times by 2 tests: end of blockExecuted by:
| 318 | ||||||||||||||||||||||||
| 1032 | - | |||||||||||||||||||||||||
| 1033 | QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); | - | ||||||||||||||||||||||||
| 1034 | QMap<QString, QStringList> &paths = QCoreGlobalData::instance()->dirSearchPaths; | - | ||||||||||||||||||||||||
| 1035 | if (searchPaths.isEmpty()) {
| 13-22 | ||||||||||||||||||||||||
| 1036 | paths.remove(prefix); | - | ||||||||||||||||||||||||
| 1037 | } else { executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 1038 | paths.insert(prefix, searchPaths); | - | ||||||||||||||||||||||||
| 1039 | } executed 13 times by 2 tests: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 1040 | } | - | ||||||||||||||||||||||||
| 1041 | - | |||||||||||||||||||||||||
| 1042 | /*! | - | ||||||||||||||||||||||||
| 1043 | \since 4.3 | - | ||||||||||||||||||||||||
| 1044 | - | |||||||||||||||||||||||||
| 1045 | Adds \a path to the search path for \a prefix. | - | ||||||||||||||||||||||||
| 1046 | - | |||||||||||||||||||||||||
| 1047 | \sa setSearchPaths() | - | ||||||||||||||||||||||||
| 1048 | */ | - | ||||||||||||||||||||||||
| 1049 | void QDir::addSearchPath(const QString &prefix, const QString &path) | - | ||||||||||||||||||||||||
| 1050 | { | - | ||||||||||||||||||||||||
| 1051 | if (path.isEmpty())
| 0-13 | ||||||||||||||||||||||||
| 1052 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||
| 1054 | QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); | - | ||||||||||||||||||||||||
| 1055 | QCoreGlobalData::instance()->dirSearchPaths[prefix] += path; | - | ||||||||||||||||||||||||
| 1056 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 1057 | - | |||||||||||||||||||||||||
| 1058 | /*! | - | ||||||||||||||||||||||||
| 1059 | \since 4.3 | - | ||||||||||||||||||||||||
| 1060 | - | |||||||||||||||||||||||||
| 1061 | Returns the search paths for \a prefix. | - | ||||||||||||||||||||||||
| 1062 | - | |||||||||||||||||||||||||
| 1063 | \sa setSearchPaths(), addSearchPath() | - | ||||||||||||||||||||||||
| 1064 | */ | - | ||||||||||||||||||||||||
| 1065 | QStringList QDir::searchPaths(const QString &prefix) | - | ||||||||||||||||||||||||
| 1066 | { | - | ||||||||||||||||||||||||
| 1067 | QReadLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); | - | ||||||||||||||||||||||||
| 1068 | return QCoreGlobalData::instance()->dirSearchPaths.value(prefix); executed 123 times by 5 tests: return QCoreGlobalData::instance()->dirSearchPaths.value(prefix);Executed by:
| 123 | ||||||||||||||||||||||||
| 1069 | } | - | ||||||||||||||||||||||||
| 1070 | - | |||||||||||||||||||||||||
| 1071 | #endif // QT_BUILD_CORE_LIB | - | ||||||||||||||||||||||||
| 1072 | - | |||||||||||||||||||||||||
| 1073 | /*! | - | ||||||||||||||||||||||||
| 1074 | Returns the value set by setFilter() | - | ||||||||||||||||||||||||
| 1075 | */ | - | ||||||||||||||||||||||||
| 1076 | QDir::Filters QDir::filter() const | - | ||||||||||||||||||||||||
| 1077 | { | - | ||||||||||||||||||||||||
| 1078 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1079 | return d->filters; executed 16 times by 1 test: return d->filters;Executed by:
| 16 | ||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | /*! | - | ||||||||||||||||||||||||
| 1083 | \enum QDir::Filter | - | ||||||||||||||||||||||||
| 1084 | - | |||||||||||||||||||||||||
| 1085 | This enum describes the filtering options available to QDir; e.g. | - | ||||||||||||||||||||||||
| 1086 | for entryList() and entryInfoList(). The filter value is specified | - | ||||||||||||||||||||||||
| 1087 | by combining values from the following list using the bitwise OR | - | ||||||||||||||||||||||||
| 1088 | operator: | - | ||||||||||||||||||||||||
| 1089 | - | |||||||||||||||||||||||||
| 1090 | \value Dirs List directories that match the filters. | - | ||||||||||||||||||||||||
| 1091 | \value AllDirs List all directories; i.e. don't apply the filters | - | ||||||||||||||||||||||||
| 1092 | to directory names. | - | ||||||||||||||||||||||||
| 1093 | \value Files List files. | - | ||||||||||||||||||||||||
| 1094 | \value Drives List disk drives (ignored under Unix). | - | ||||||||||||||||||||||||
| 1095 | \value NoSymLinks Do not list symbolic links (ignored by operating | - | ||||||||||||||||||||||||
| 1096 | systems that don't support symbolic links). | - | ||||||||||||||||||||||||
| 1097 | \value NoDotAndDotDot Do not list the special entries "." and "..". | - | ||||||||||||||||||||||||
| 1098 | \value NoDot Do not list the special entry ".". | - | ||||||||||||||||||||||||
| 1099 | \value NoDotDot Do not list the special entry "..". | - | ||||||||||||||||||||||||
| 1100 | \value AllEntries List directories, files, drives and symlinks (this does not list | - | ||||||||||||||||||||||||
| 1101 | broken symlinks unless you specify System). | - | ||||||||||||||||||||||||
| 1102 | \value Readable List files for which the application has read | - | ||||||||||||||||||||||||
| 1103 | access. The Readable value needs to be combined | - | ||||||||||||||||||||||||
| 1104 | with Dirs or Files. | - | ||||||||||||||||||||||||
| 1105 | \value Writable List files for which the application has write | - | ||||||||||||||||||||||||
| 1106 | access. The Writable value needs to be combined | - | ||||||||||||||||||||||||
| 1107 | with Dirs or Files. | - | ||||||||||||||||||||||||
| 1108 | \value Executable List files for which the application has | - | ||||||||||||||||||||||||
| 1109 | execute access. The Executable value needs to be | - | ||||||||||||||||||||||||
| 1110 | combined with Dirs or Files. | - | ||||||||||||||||||||||||
| 1111 | \value Modified Only list files that have been modified (ignored | - | ||||||||||||||||||||||||
| 1112 | on Unix). | - | ||||||||||||||||||||||||
| 1113 | \value Hidden List hidden files (on Unix, files starting with a "."). | - | ||||||||||||||||||||||||
| 1114 | \value System List system files (on Unix, FIFOs, sockets and | - | ||||||||||||||||||||||||
| 1115 | device files are included; on Windows, \c {.lnk} | - | ||||||||||||||||||||||||
| 1116 | files are included) | - | ||||||||||||||||||||||||
| 1117 | \value CaseSensitive The filter should be case sensitive. | - | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | \omitvalue TypeMask | - | ||||||||||||||||||||||||
| 1120 | \omitvalue AccessMask | - | ||||||||||||||||||||||||
| 1121 | \omitvalue PermissionMask | - | ||||||||||||||||||||||||
| 1122 | \omitvalue NoFilter | - | ||||||||||||||||||||||||
| 1123 | - | |||||||||||||||||||||||||
| 1124 | Functions that use Filter enum values to filter lists of files | - | ||||||||||||||||||||||||
| 1125 | and directories will include symbolic links to files and directories | - | ||||||||||||||||||||||||
| 1126 | unless you set the NoSymLinks value. | - | ||||||||||||||||||||||||
| 1127 | - | |||||||||||||||||||||||||
| 1128 | A default constructed QDir will not filter out files based on | - | ||||||||||||||||||||||||
| 1129 | their permissions, so entryList() and entryInfoList() will return | - | ||||||||||||||||||||||||
| 1130 | all files that are readable, writable, executable, or any | - | ||||||||||||||||||||||||
| 1131 | combination of the three. This makes the default easy to write, | - | ||||||||||||||||||||||||
| 1132 | and at the same time useful. | - | ||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||
| 1134 | For example, setting the \c Readable, \c Writable, and \c Files | - | ||||||||||||||||||||||||
| 1135 | flags allows all files to be listed for which the application has read | - | ||||||||||||||||||||||||
| 1136 | access, write access or both. If the \c Dirs and \c Drives flags are | - | ||||||||||||||||||||||||
| 1137 | also included in this combination then all drives, directories, all | - | ||||||||||||||||||||||||
| 1138 | files that the application can read, write, or execute, and symlinks | - | ||||||||||||||||||||||||
| 1139 | to such files/directories can be listed. | - | ||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||
| 1141 | To retrieve the permissons for a directory, use the | - | ||||||||||||||||||||||||
| 1142 | entryInfoList() function to get the associated QFileInfo objects | - | ||||||||||||||||||||||||
| 1143 | and then use the QFileInfo::permissons() to obtain the permissions | - | ||||||||||||||||||||||||
| 1144 | and ownership for each file. | - | ||||||||||||||||||||||||
| 1145 | */ | - | ||||||||||||||||||||||||
| 1146 | - | |||||||||||||||||||||||||
| 1147 | /*! | - | ||||||||||||||||||||||||
| 1148 | Sets the filter used by entryList() and entryInfoList() to \a | - | ||||||||||||||||||||||||
| 1149 | filters. The filter is used to specify the kind of files that | - | ||||||||||||||||||||||||
| 1150 | should be returned by entryList() and entryInfoList(). See | - | ||||||||||||||||||||||||
| 1151 | \l{QDir::Filter}. | - | ||||||||||||||||||||||||
| 1152 | - | |||||||||||||||||||||||||
| 1153 | \sa filter(), setNameFilters() | - | ||||||||||||||||||||||||
| 1154 | */ | - | ||||||||||||||||||||||||
| 1155 | void QDir::setFilter(Filters filters) | - | ||||||||||||||||||||||||
| 1156 | { | - | ||||||||||||||||||||||||
| 1157 | QDirPrivate* d = d_ptr.data(); | - | ||||||||||||||||||||||||
| 1158 | d->initFileEngine(); | - | ||||||||||||||||||||||||
| 1159 | d->clearFileLists(); | - | ||||||||||||||||||||||||
| 1160 | - | |||||||||||||||||||||||||
| 1161 | d->filters = filters; | - | ||||||||||||||||||||||||
| 1162 | } executed 320 times by 6 tests: end of blockExecuted by:
| 320 | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | /*! | - | ||||||||||||||||||||||||
| 1165 | Returns the value set by setSorting() | - | ||||||||||||||||||||||||
| 1166 | - | |||||||||||||||||||||||||
| 1167 | \sa setSorting(), SortFlag | - | ||||||||||||||||||||||||
| 1168 | */ | - | ||||||||||||||||||||||||
| 1169 | QDir::SortFlags QDir::sorting() const | - | ||||||||||||||||||||||||
| 1170 | { | - | ||||||||||||||||||||||||
| 1171 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1172 | return d->sort; executed 16 times by 1 test: return d->sort;Executed by:
| 16 | ||||||||||||||||||||||||
| 1173 | } | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | /*! | - | ||||||||||||||||||||||||
| 1176 | \enum QDir::SortFlag | - | ||||||||||||||||||||||||
| 1177 | - | |||||||||||||||||||||||||
| 1178 | This enum describes the sort options available to QDir, e.g. for | - | ||||||||||||||||||||||||
| 1179 | entryList() and entryInfoList(). The sort value is specified by | - | ||||||||||||||||||||||||
| 1180 | OR-ing together values from the following list: | - | ||||||||||||||||||||||||
| 1181 | - | |||||||||||||||||||||||||
| 1182 | \value Name Sort by name. | - | ||||||||||||||||||||||||
| 1183 | \value Time Sort by time (modification time). | - | ||||||||||||||||||||||||
| 1184 | \value Size Sort by file size. | - | ||||||||||||||||||||||||
| 1185 | \value Type Sort by file type (extension). | - | ||||||||||||||||||||||||
| 1186 | \value Unsorted Do not sort. | - | ||||||||||||||||||||||||
| 1187 | \value NoSort Not sorted by default. | - | ||||||||||||||||||||||||
| 1188 | - | |||||||||||||||||||||||||
| 1189 | \value DirsFirst Put the directories first, then the files. | - | ||||||||||||||||||||||||
| 1190 | \value DirsLast Put the files first, then the directories. | - | ||||||||||||||||||||||||
| 1191 | \value Reversed Reverse the sort order. | - | ||||||||||||||||||||||||
| 1192 | \value IgnoreCase Sort case-insensitively. | - | ||||||||||||||||||||||||
| 1193 | \value LocaleAware Sort items appropriately using the current locale settings. | - | ||||||||||||||||||||||||
| 1194 | - | |||||||||||||||||||||||||
| 1195 | \omitvalue SortByMask | - | ||||||||||||||||||||||||
| 1196 | - | |||||||||||||||||||||||||
| 1197 | You can only specify one of the first four. | - | ||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||
| 1199 | If you specify both DirsFirst and Reversed, directories are | - | ||||||||||||||||||||||||
| 1200 | still put first, but in reverse order; the files will be listed | - | ||||||||||||||||||||||||
| 1201 | after the directories, again in reverse order. | - | ||||||||||||||||||||||||
| 1202 | */ | - | ||||||||||||||||||||||||
| 1203 | - | |||||||||||||||||||||||||
| 1204 | /*! | - | ||||||||||||||||||||||||
| 1205 | Sets the sort order used by entryList() and entryInfoList(). | - | ||||||||||||||||||||||||
| 1206 | - | |||||||||||||||||||||||||
| 1207 | The \a sort is specified by OR-ing values from the enum | - | ||||||||||||||||||||||||
| 1208 | \l{QDir::SortFlag}. | - | ||||||||||||||||||||||||
| 1209 | - | |||||||||||||||||||||||||
| 1210 | \sa sorting(), SortFlag | - | ||||||||||||||||||||||||
| 1211 | */ | - | ||||||||||||||||||||||||
| 1212 | void QDir::setSorting(SortFlags sort) | - | ||||||||||||||||||||||||
| 1213 | { | - | ||||||||||||||||||||||||
| 1214 | QDirPrivate* d = d_ptr.data(); | - | ||||||||||||||||||||||||
| 1215 | d->initFileEngine(); | - | ||||||||||||||||||||||||
| 1216 | d->clearFileLists(); | - | ||||||||||||||||||||||||
| 1217 | - | |||||||||||||||||||||||||
| 1218 | d->sort = sort; | - | ||||||||||||||||||||||||
| 1219 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 1220 | - | |||||||||||||||||||||||||
| 1221 | /*! | - | ||||||||||||||||||||||||
| 1222 | Returns the total number of directories and files in the directory. | - | ||||||||||||||||||||||||
| 1223 | - | |||||||||||||||||||||||||
| 1224 | Equivalent to entryList().count(). | - | ||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | \sa operator[](), entryList() | - | ||||||||||||||||||||||||
| 1227 | */ | - | ||||||||||||||||||||||||
| 1228 | uint QDir::count() const | - | ||||||||||||||||||||||||
| 1229 | { | - | ||||||||||||||||||||||||
| 1230 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1231 | d->initFileLists(*this); | - | ||||||||||||||||||||||||
| 1232 | return d->files.count(); executed 29 times by 2 tests: return d->files.count();Executed by:
| 29 | ||||||||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | /*! | - | ||||||||||||||||||||||||
| 1236 | Returns the file name at position \a pos in the list of file | - | ||||||||||||||||||||||||
| 1237 | names. Equivalent to entryList().at(index). | - | ||||||||||||||||||||||||
| 1238 | \a pos must be a valid index position in the list (i.e., 0 <= pos < count()). | - | ||||||||||||||||||||||||
| 1239 | - | |||||||||||||||||||||||||
| 1240 | \sa count(), entryList() | - | ||||||||||||||||||||||||
| 1241 | */ | - | ||||||||||||||||||||||||
| 1242 | QString QDir::operator[](int pos) const | - | ||||||||||||||||||||||||
| 1243 | { | - | ||||||||||||||||||||||||
| 1244 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1245 | d->initFileLists(*this); | - | ||||||||||||||||||||||||
| 1246 | return d->files[pos]; executed 53 times by 2 tests: return d->files[pos];Executed by:
| 53 | ||||||||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||||||||
| 1248 | - | |||||||||||||||||||||||||
| 1249 | /*! | - | ||||||||||||||||||||||||
| 1250 | \overload | - | ||||||||||||||||||||||||
| 1251 | - | |||||||||||||||||||||||||
| 1252 | Returns a list of the names of all the files and directories in | - | ||||||||||||||||||||||||
| 1253 | the directory, ordered according to the name and attribute filters | - | ||||||||||||||||||||||||
| 1254 | previously set with setNameFilters() and setFilter(), and sorted according | - | ||||||||||||||||||||||||
| 1255 | to the flags set with setSorting(). | - | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | The attribute filter and sorting specifications can be overridden using the | - | ||||||||||||||||||||||||
| 1258 | \a filters and \a sort arguments. | - | ||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | Returns an empty list if the directory is unreadable, does not | - | ||||||||||||||||||||||||
| 1261 | exist, or if nothing matches the specification. | - | ||||||||||||||||||||||||
| 1262 | - | |||||||||||||||||||||||||
| 1263 | \note To list symlinks that point to non existing files, \l System must be | - | ||||||||||||||||||||||||
| 1264 | passed to the filter. | - | ||||||||||||||||||||||||
| 1265 | - | |||||||||||||||||||||||||
| 1266 | \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() | - | ||||||||||||||||||||||||
| 1267 | */ | - | ||||||||||||||||||||||||
| 1268 | QStringList QDir::entryList(Filters filters, SortFlags sort) const | - | ||||||||||||||||||||||||
| 1269 | { | - | ||||||||||||||||||||||||
| 1270 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1271 | return entryList(d->nameFilters, filters, sort); executed 693 times by 118 tests: return entryList(d->nameFilters, filters, sort);Executed by:
| 693 | ||||||||||||||||||||||||
| 1272 | } | - | ||||||||||||||||||||||||
| 1273 | - | |||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | /*! | - | ||||||||||||||||||||||||
| 1276 | \overload | - | ||||||||||||||||||||||||
| 1277 | - | |||||||||||||||||||||||||
| 1278 | Returns a list of QFileInfo objects for all the files and directories in | - | ||||||||||||||||||||||||
| 1279 | the directory, ordered according to the name and attribute filters | - | ||||||||||||||||||||||||
| 1280 | previously set with setNameFilters() and setFilter(), and sorted according | - | ||||||||||||||||||||||||
| 1281 | to the flags set with setSorting(). | - | ||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||
| 1283 | The attribute filter and sorting specifications can be overridden using the | - | ||||||||||||||||||||||||
| 1284 | \a filters and \a sort arguments. | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | Returns an empty list if the directory is unreadable, does not | - | ||||||||||||||||||||||||
| 1287 | exist, or if nothing matches the specification. | - | ||||||||||||||||||||||||
| 1288 | - | |||||||||||||||||||||||||
| 1289 | \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() | - | ||||||||||||||||||||||||
| 1290 | */ | - | ||||||||||||||||||||||||
| 1291 | QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const | - | ||||||||||||||||||||||||
| 1292 | { | - | ||||||||||||||||||||||||
| 1293 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1294 | return entryInfoList(d->nameFilters, filters, sort); executed 253 times by 9 tests: return entryInfoList(d->nameFilters, filters, sort);Executed by:
| 253 | ||||||||||||||||||||||||
| 1295 | } | - | ||||||||||||||||||||||||
| 1296 | - | |||||||||||||||||||||||||
| 1297 | /*! | - | ||||||||||||||||||||||||
| 1298 | Returns a list of the names of all the files and | - | ||||||||||||||||||||||||
| 1299 | directories in the directory, ordered according to the name | - | ||||||||||||||||||||||||
| 1300 | and attribute filters previously set with setNameFilters() | - | ||||||||||||||||||||||||
| 1301 | and setFilter(), and sorted according to the flags set with | - | ||||||||||||||||||||||||
| 1302 | setSorting(). | - | ||||||||||||||||||||||||
| 1303 | - | |||||||||||||||||||||||||
| 1304 | The name filter, file attribute filter, and sorting specification | - | ||||||||||||||||||||||||
| 1305 | can be overridden using the \a nameFilters, \a filters, and \a sort | - | ||||||||||||||||||||||||
| 1306 | arguments. | - | ||||||||||||||||||||||||
| 1307 | - | |||||||||||||||||||||||||
| 1308 | Returns an empty list if the directory is unreadable, does not | - | ||||||||||||||||||||||||
| 1309 | exist, or if nothing matches the specification. | - | ||||||||||||||||||||||||
| 1310 | - | |||||||||||||||||||||||||
| 1311 | \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() | - | ||||||||||||||||||||||||
| 1312 | */ | - | ||||||||||||||||||||||||
| 1313 | QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, | - | ||||||||||||||||||||||||
| 1314 | SortFlags sort) const | - | ||||||||||||||||||||||||
| 1315 | { | - | ||||||||||||||||||||||||
| 1316 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||
| 1318 | if (filters == NoFilter)
| 64-684 | ||||||||||||||||||||||||
| 1319 | filters = d->filters; executed 64 times by 7 tests: filters = d->filters;Executed by:
| 64 | ||||||||||||||||||||||||
| 1320 | if (sort == NoSort)
| 39-709 | ||||||||||||||||||||||||
| 1321 | sort = d->sort; executed 709 times by 120 tests: sort = d->sort;Executed by:
| 709 | ||||||||||||||||||||||||
| 1322 | - | |||||||||||||||||||||||||
| 1323 | if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
| 8-659 | ||||||||||||||||||||||||
| 1324 | d->initFileLists(*this); | - | ||||||||||||||||||||||||
| 1325 | return d->files; executed 68 times by 6 tests: return d->files;Executed by:
| 68 | ||||||||||||||||||||||||
| 1326 | } | - | ||||||||||||||||||||||||
| 1327 | - | |||||||||||||||||||||||||
| 1328 | QFileInfoList l; | - | ||||||||||||||||||||||||
| 1329 | QDirIterator it(d->dirEntry.filePath(), nameFilters, filters); | - | ||||||||||||||||||||||||
| 1330 | while (it.hasNext()) {
| 680-2585 | ||||||||||||||||||||||||
| 1331 | it.next(); | - | ||||||||||||||||||||||||
| 1332 | l.append(it.fileInfo()); | - | ||||||||||||||||||||||||
| 1333 | } executed 2585 times by 116 tests: end of blockExecuted by:
| 2585 | ||||||||||||||||||||||||
| 1334 | QStringList ret; | - | ||||||||||||||||||||||||
| 1335 | d->sortFileList(sort, l, &ret, 0); | - | ||||||||||||||||||||||||
| 1336 | return ret; executed 680 times by 116 tests: return ret;Executed by:
| 680 | ||||||||||||||||||||||||
| 1337 | } | - | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | /*! | - | ||||||||||||||||||||||||
| 1340 | Returns a list of QFileInfo objects for all the files and | - | ||||||||||||||||||||||||
| 1341 | directories in the directory, ordered according to the name | - | ||||||||||||||||||||||||
| 1342 | and attribute filters previously set with setNameFilters() | - | ||||||||||||||||||||||||
| 1343 | and setFilter(), and sorted according to the flags set with | - | ||||||||||||||||||||||||
| 1344 | setSorting(). | - | ||||||||||||||||||||||||
| 1345 | - | |||||||||||||||||||||||||
| 1346 | The name filter, file attribute filter, and sorting specification | - | ||||||||||||||||||||||||
| 1347 | can be overridden using the \a nameFilters, \a filters, and \a sort | - | ||||||||||||||||||||||||
| 1348 | arguments. | - | ||||||||||||||||||||||||
| 1349 | - | |||||||||||||||||||||||||
| 1350 | Returns an empty list if the directory is unreadable, does not | - | ||||||||||||||||||||||||
| 1351 | exist, or if nothing matches the specification. | - | ||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||
| 1353 | \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() | - | ||||||||||||||||||||||||
| 1354 | */ | - | ||||||||||||||||||||||||
| 1355 | QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters, | - | ||||||||||||||||||||||||
| 1356 | SortFlags sort) const | - | ||||||||||||||||||||||||
| 1357 | { | - | ||||||||||||||||||||||||
| 1358 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1359 | - | |||||||||||||||||||||||||
| 1360 | if (filters == NoFilter)
| 42-697 | ||||||||||||||||||||||||
| 1361 | filters = d->filters; executed 42 times by 5 tests: filters = d->filters;Executed by:
| 42 | ||||||||||||||||||||||||
| 1362 | if (sort == NoSort)
| 183-556 | ||||||||||||||||||||||||
| 1363 | sort = d->sort; executed 183 times by 11 tests: sort = d->sort;Executed by:
| 183 | ||||||||||||||||||||||||
| 1364 | - | |||||||||||||||||||||||||
| 1365 | if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
| 5-697 | ||||||||||||||||||||||||
| 1366 | d->initFileLists(*this); | - | ||||||||||||||||||||||||
| 1367 | return d->fileInfos; executed 11 times by 2 tests: return d->fileInfos;Executed by:
| 11 | ||||||||||||||||||||||||
| 1368 | } | - | ||||||||||||||||||||||||
| 1369 | - | |||||||||||||||||||||||||
| 1370 | QFileInfoList l; | - | ||||||||||||||||||||||||
| 1371 | QDirIterator it(d->dirEntry.filePath(), nameFilters, filters); | - | ||||||||||||||||||||||||
| 1372 | while (it.hasNext()) {
| 728-9856 | ||||||||||||||||||||||||
| 1373 | it.next(); | - | ||||||||||||||||||||||||
| 1374 | l.append(it.fileInfo()); | - | ||||||||||||||||||||||||
| 1375 | } executed 9856 times by 14 tests: end of blockExecuted by:
| 9856 | ||||||||||||||||||||||||
| 1376 | QFileInfoList ret; | - | ||||||||||||||||||||||||
| 1377 | d->sortFileList(sort, l, 0, &ret); | - | ||||||||||||||||||||||||
| 1378 | return ret; executed 728 times by 14 tests: return ret;Executed by:
| 728 | ||||||||||||||||||||||||
| 1379 | } | - | ||||||||||||||||||||||||
| 1380 | - | |||||||||||||||||||||||||
| 1381 | /*! | - | ||||||||||||||||||||||||
| 1382 | Creates a sub-directory called \a dirName. | - | ||||||||||||||||||||||||
| 1383 | - | |||||||||||||||||||||||||
| 1384 | Returns \c true on success; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | If the directory already exists when this function is called, it will return false. | - | ||||||||||||||||||||||||
| 1387 | - | |||||||||||||||||||||||||
| 1388 | \sa rmdir() | - | ||||||||||||||||||||||||
| 1389 | */ | - | ||||||||||||||||||||||||
| 1390 | bool QDir::mkdir(const QString &dirName) const | - | ||||||||||||||||||||||||
| 1391 | { | - | ||||||||||||||||||||||||
| 1392 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | if (dirName.isEmpty()) {
| 0-1425 | ||||||||||||||||||||||||
| 1395 | qWarning("QDir::mkdir: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1396 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1397 | } | - | ||||||||||||||||||||||||
| 1398 | - | |||||||||||||||||||||||||
| 1399 | QString fn = filePath(dirName); | - | ||||||||||||||||||||||||
| 1400 | if (d->fileEngine.isNull())
| 0-1425 | ||||||||||||||||||||||||
| 1401 | return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false); executed 1425 times by 18 tests: return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);Executed by:
| 1425 | ||||||||||||||||||||||||
| 1402 | return d->fileEngine->mkdir(fn, false); never executed: return d->fileEngine->mkdir(fn, false); | 0 | ||||||||||||||||||||||||
| 1403 | } | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | /*! | - | ||||||||||||||||||||||||
| 1406 | Removes the directory specified by \a dirName. | - | ||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||
| 1408 | The directory must be empty for rmdir() to succeed. | - | ||||||||||||||||||||||||
| 1409 | - | |||||||||||||||||||||||||
| 1410 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1411 | - | |||||||||||||||||||||||||
| 1412 | \sa mkdir() | - | ||||||||||||||||||||||||
| 1413 | */ | - | ||||||||||||||||||||||||
| 1414 | bool QDir::rmdir(const QString &dirName) const | - | ||||||||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||||||||
| 1416 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1417 | - | |||||||||||||||||||||||||
| 1418 | if (dirName.isEmpty()) {
| 2-2734 | ||||||||||||||||||||||||
| 1419 | qWarning("QDir::rmdir: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1420 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 1421 | } | - | ||||||||||||||||||||||||
| 1422 | - | |||||||||||||||||||||||||
| 1423 | QString fn = filePath(dirName); | - | ||||||||||||||||||||||||
| 1424 | if (d->fileEngine.isNull())
| 0-2734 | ||||||||||||||||||||||||
| 1425 | return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false); executed 2734 times by 55 tests: return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);Executed by:
| 2734 | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | return d->fileEngine->rmdir(fn, false); never executed: return d->fileEngine->rmdir(fn, false); | 0 | ||||||||||||||||||||||||
| 1428 | } | - | ||||||||||||||||||||||||
| 1429 | - | |||||||||||||||||||||||||
| 1430 | /*! | - | ||||||||||||||||||||||||
| 1431 | Creates the directory path \a dirPath. | - | ||||||||||||||||||||||||
| 1432 | - | |||||||||||||||||||||||||
| 1433 | The function will create all parent directories necessary to | - | ||||||||||||||||||||||||
| 1434 | create the directory. | - | ||||||||||||||||||||||||
| 1435 | - | |||||||||||||||||||||||||
| 1436 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1437 | - | |||||||||||||||||||||||||
| 1438 | If the path already exists when this function is called, it will return true. | - | ||||||||||||||||||||||||
| 1439 | - | |||||||||||||||||||||||||
| 1440 | \sa rmpath() | - | ||||||||||||||||||||||||
| 1441 | */ | - | ||||||||||||||||||||||||
| 1442 | bool QDir::mkpath(const QString &dirPath) const | - | ||||||||||||||||||||||||
| 1443 | { | - | ||||||||||||||||||||||||
| 1444 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1445 | - | |||||||||||||||||||||||||
| 1446 | if (dirPath.isEmpty()) {
| 0-398 | ||||||||||||||||||||||||
| 1447 | qWarning("QDir::mkpath: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1448 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1449 | } | - | ||||||||||||||||||||||||
| 1450 | - | |||||||||||||||||||||||||
| 1451 | QString fn = filePath(dirPath); | - | ||||||||||||||||||||||||
| 1452 | if (d->fileEngine.isNull())
| 0-398 | ||||||||||||||||||||||||
| 1453 | return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true); executed 398 times by 13 tests: return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);Executed by:
| 398 | ||||||||||||||||||||||||
| 1454 | return d->fileEngine->mkdir(fn, true); never executed: return d->fileEngine->mkdir(fn, true); | 0 | ||||||||||||||||||||||||
| 1455 | } | - | ||||||||||||||||||||||||
| 1456 | - | |||||||||||||||||||||||||
| 1457 | /*! | - | ||||||||||||||||||||||||
| 1458 | Removes the directory path \a dirPath. | - | ||||||||||||||||||||||||
| 1459 | - | |||||||||||||||||||||||||
| 1460 | The function will remove all parent directories in \a dirPath, | - | ||||||||||||||||||||||||
| 1461 | provided that they are empty. This is the opposite of | - | ||||||||||||||||||||||||
| 1462 | mkpath(dirPath). | - | ||||||||||||||||||||||||
| 1463 | - | |||||||||||||||||||||||||
| 1464 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1465 | - | |||||||||||||||||||||||||
| 1466 | \sa mkpath() | - | ||||||||||||||||||||||||
| 1467 | */ | - | ||||||||||||||||||||||||
| 1468 | bool QDir::rmpath(const QString &dirPath) const | - | ||||||||||||||||||||||||
| 1469 | { | - | ||||||||||||||||||||||||
| 1470 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1471 | - | |||||||||||||||||||||||||
| 1472 | if (dirPath.isEmpty()) {
| 0-79 | ||||||||||||||||||||||||
| 1473 | qWarning("QDir::rmpath: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1474 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1475 | } | - | ||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | QString fn = filePath(dirPath); | - | ||||||||||||||||||||||||
| 1478 | if (d->fileEngine.isNull())
| 0-79 | ||||||||||||||||||||||||
| 1479 | return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true); executed 79 times by 2 tests: return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);Executed by:
| 79 | ||||||||||||||||||||||||
| 1480 | return d->fileEngine->rmdir(fn, true); never executed: return d->fileEngine->rmdir(fn, true); | 0 | ||||||||||||||||||||||||
| 1481 | } | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | /*! | - | ||||||||||||||||||||||||
| 1484 | \since 5.0 | - | ||||||||||||||||||||||||
| 1485 | Removes the directory, including all its contents. | - | ||||||||||||||||||||||||
| 1486 | - | |||||||||||||||||||||||||
| 1487 | Returns \c true if successful, otherwise false. | - | ||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||
| 1489 | If a file or directory cannot be removed, removeRecursively() keeps going | - | ||||||||||||||||||||||||
| 1490 | and attempts to delete as many files and sub-directories as possible, | - | ||||||||||||||||||||||||
| 1491 | then returns \c false. | - | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | If the directory was already removed, the method returns \c true | - | ||||||||||||||||||||||||
| 1494 | (expected result already reached). | - | ||||||||||||||||||||||||
| 1495 | - | |||||||||||||||||||||||||
| 1496 | Note: this function is meant for removing a small application-internal | - | ||||||||||||||||||||||||
| 1497 | directory (such as a temporary directory), but not user-visible | - | ||||||||||||||||||||||||
| 1498 | directories. For user-visible operations, it is rather recommended | - | ||||||||||||||||||||||||
| 1499 | to report errors more precisely to the user, to offer solutions | - | ||||||||||||||||||||||||
| 1500 | in case of errors, to show progress during the deletion since it | - | ||||||||||||||||||||||||
| 1501 | could take several minutes, etc. | - | ||||||||||||||||||||||||
| 1502 | */ | - | ||||||||||||||||||||||||
| 1503 | bool QDir::removeRecursively() | - | ||||||||||||||||||||||||
| 1504 | { | - | ||||||||||||||||||||||||
| 1505 | if (!d_ptr->exists())
| 133-2388 | ||||||||||||||||||||||||
| 1506 | return true; executed 133 times by 5 tests: return true;Executed by:
| 133 | ||||||||||||||||||||||||
| 1507 | - | |||||||||||||||||||||||||
| 1508 | bool success = true; | - | ||||||||||||||||||||||||
| 1509 | const QString dirPath = path(); | - | ||||||||||||||||||||||||
| 1510 | // not empty -- we must empty it first | - | ||||||||||||||||||||||||
| 1511 | QDirIterator di(dirPath, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot); | - | ||||||||||||||||||||||||
| 1512 | while (di.hasNext()) {
| 2388-3348 | ||||||||||||||||||||||||
| 1513 | di.next(); | - | ||||||||||||||||||||||||
| 1514 | const QFileInfo& fi = di.fileInfo(); | - | ||||||||||||||||||||||||
| 1515 | const QString &filePath = di.filePath(); | - | ||||||||||||||||||||||||
| 1516 | bool ok; | - | ||||||||||||||||||||||||
| 1517 | if (fi.isDir() && !fi.isSymLink()) {
| 1-2057 | ||||||||||||||||||||||||
| 1518 | ok = QDir(filePath).removeRecursively(); // recursive | - | ||||||||||||||||||||||||
| 1519 | } else { executed 2056 times by 22 tests: end of blockExecuted by:
| 2056 | ||||||||||||||||||||||||
| 1520 | ok = QFile::remove(filePath); | - | ||||||||||||||||||||||||
| 1521 | if (!ok) { // Read-only files prevent directory deletion on Windows, retry with Write permission.
| 0-1292 | ||||||||||||||||||||||||
| 1522 | const QFile::Permissions permissions = QFile::permissions(filePath); | - | ||||||||||||||||||||||||
| 1523 | if (!(permissions & QFile::WriteUser))
| 0 | ||||||||||||||||||||||||
| 1524 | ok = QFile::setPermissions(filePath, permissions | QFile::WriteUser) never executed: ok = QFile::setPermissions(filePath, permissions | QFile::WriteUser) && QFile::remove(filePath);
| 0 | ||||||||||||||||||||||||
| 1525 | && QFile::remove(filePath); never executed: ok = QFile::setPermissions(filePath, permissions | QFile::WriteUser) && QFile::remove(filePath);
| 0 | ||||||||||||||||||||||||
| 1526 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1527 | } executed 1292 times by 37 tests: end of blockExecuted by:
| 1292 | ||||||||||||||||||||||||
| 1528 | if (!ok)
| 0-3348 | ||||||||||||||||||||||||
| 1529 | success = false; never executed: success = false; | 0 | ||||||||||||||||||||||||
| 1530 | } executed 3348 times by 42 tests: end of blockExecuted by:
| 3348 | ||||||||||||||||||||||||
| 1531 | - | |||||||||||||||||||||||||
| 1532 | if (success)
| 0-2388 | ||||||||||||||||||||||||
| 1533 | success = rmdir(absolutePath()); executed 2388 times by 52 tests: success = rmdir(absolutePath());Executed by:
| 2388 | ||||||||||||||||||||||||
| 1534 | - | |||||||||||||||||||||||||
| 1535 | return success; executed 2388 times by 52 tests: return success;Executed by:
| 2388 | ||||||||||||||||||||||||
| 1536 | } | - | ||||||||||||||||||||||||
| 1537 | - | |||||||||||||||||||||||||
| 1538 | /*! | - | ||||||||||||||||||||||||
| 1539 | Returns \c true if the directory is readable \e and we can open files | - | ||||||||||||||||||||||||
| 1540 | by name; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1541 | - | |||||||||||||||||||||||||
| 1542 | \warning A false value from this function is not a guarantee that | - | ||||||||||||||||||||||||
| 1543 | files in the directory are not accessible. | - | ||||||||||||||||||||||||
| 1544 | - | |||||||||||||||||||||||||
| 1545 | \sa QFileInfo::isReadable() | - | ||||||||||||||||||||||||
| 1546 | */ | - | ||||||||||||||||||||||||
| 1547 | bool QDir::isReadable() const | - | ||||||||||||||||||||||||
| 1548 | { | - | ||||||||||||||||||||||||
| 1549 | const QDirPrivate* d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1550 | - | |||||||||||||||||||||||||
| 1551 | if (d->fileEngine.isNull()) {
| 0-3 | ||||||||||||||||||||||||
| 1552 | if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
| 0-3 | ||||||||||||||||||||||||
| 1553 | QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission); executed 3 times by 1 test: QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);Executed by:
| 3 | ||||||||||||||||||||||||
| 1554 | - | |||||||||||||||||||||||||
| 1555 | return (d->metaData.permissions() & QFile::ReadUser) != 0; executed 3 times by 1 test: return (d->metaData.permissions() & QFile::ReadUser) != 0;Executed by:
| 3 | ||||||||||||||||||||||||
| 1556 | } | - | ||||||||||||||||||||||||
| 1557 | - | |||||||||||||||||||||||||
| 1558 | const QAbstractFileEngine::FileFlags info = | - | ||||||||||||||||||||||||
| 1559 | d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType | - | ||||||||||||||||||||||||
| 1560 | | QAbstractFileEngine::PermsMask); | - | ||||||||||||||||||||||||
| 1561 | if (!(info & QAbstractFileEngine::DirectoryType))
| 0 | ||||||||||||||||||||||||
| 1562 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1563 | return info & QAbstractFileEngine::ReadUserPerm; never executed: return info & QAbstractFileEngine::ReadUserPerm; | 0 | ||||||||||||||||||||||||
| 1564 | } | - | ||||||||||||||||||||||||
| 1565 | - | |||||||||||||||||||||||||
| 1566 | /*! | - | ||||||||||||||||||||||||
| 1567 | \overload | - | ||||||||||||||||||||||||
| 1568 | - | |||||||||||||||||||||||||
| 1569 | Returns \c true if the directory exists; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1570 | (If a file with the same name is found this function will return false). | - | ||||||||||||||||||||||||
| 1571 | - | |||||||||||||||||||||||||
| 1572 | The overload of this function that accepts an argument is used to test | - | ||||||||||||||||||||||||
| 1573 | for the presence of files and directories within a directory. | - | ||||||||||||||||||||||||
| 1574 | - | |||||||||||||||||||||||||
| 1575 | \sa QFileInfo::exists(), QFile::exists() | - | ||||||||||||||||||||||||
| 1576 | */ | - | ||||||||||||||||||||||||
| 1577 | bool QDir::exists() const | - | ||||||||||||||||||||||||
| 1578 | { | - | ||||||||||||||||||||||||
| 1579 | return d_ptr->exists(); executed 1444 times by 18 tests: return d_ptr->exists();Executed by:
| 1444 | ||||||||||||||||||||||||
| 1580 | } | - | ||||||||||||||||||||||||
| 1581 | - | |||||||||||||||||||||||||
| 1582 | /*! | - | ||||||||||||||||||||||||
| 1583 | Returns \c true if the directory is the root directory; otherwise | - | ||||||||||||||||||||||||
| 1584 | returns \c false. | - | ||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||
| 1586 | Note: If the directory is a symbolic link to the root directory | - | ||||||||||||||||||||||||
| 1587 | this function returns \c false. If you want to test for this use | - | ||||||||||||||||||||||||
| 1588 | canonicalPath(), e.g. | - | ||||||||||||||||||||||||
| 1589 | - | |||||||||||||||||||||||||
| 1590 | \snippet code/src_corelib_io_qdir.cpp 9 | - | ||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||
| 1592 | \sa root(), rootPath() | - | ||||||||||||||||||||||||
| 1593 | */ | - | ||||||||||||||||||||||||
| 1594 | bool QDir::isRoot() const | - | ||||||||||||||||||||||||
| 1595 | { | - | ||||||||||||||||||||||||
| 1596 | if (d_ptr->fileEngine.isNull())
| 2-60 | ||||||||||||||||||||||||
| 1597 | return d_ptr->dirEntry.isRoot(); executed 60 times by 10 tests: return d_ptr->dirEntry.isRoot();Executed by:
| 60 | ||||||||||||||||||||||||
| 1598 | return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag; executed 2 times by 1 test: return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;Executed by:
| 2 | ||||||||||||||||||||||||
| 1599 | } | - | ||||||||||||||||||||||||
| 1600 | - | |||||||||||||||||||||||||
| 1601 | /*! | - | ||||||||||||||||||||||||
| 1602 | \fn bool QDir::isAbsolute() const | - | ||||||||||||||||||||||||
| 1603 | - | |||||||||||||||||||||||||
| 1604 | Returns \c true if the directory's path is absolute; otherwise | - | ||||||||||||||||||||||||
| 1605 | returns \c false. See isAbsolutePath(). | - | ||||||||||||||||||||||||
| 1606 | - | |||||||||||||||||||||||||
| 1607 | \sa isRelative(), makeAbsolute(), cleanPath() | - | ||||||||||||||||||||||||
| 1608 | */ | - | ||||||||||||||||||||||||
| 1609 | - | |||||||||||||||||||||||||
| 1610 | /*! | - | ||||||||||||||||||||||||
| 1611 | \fn bool QDir::isAbsolutePath(const QString &) | - | ||||||||||||||||||||||||
| 1612 | - | |||||||||||||||||||||||||
| 1613 | Returns \c true if \a path is absolute; returns \c false if it is | - | ||||||||||||||||||||||||
| 1614 | relative. | - | ||||||||||||||||||||||||
| 1615 | - | |||||||||||||||||||||||||
| 1616 | \sa isAbsolute(), isRelativePath(), makeAbsolute(), cleanPath() | - | ||||||||||||||||||||||||
| 1617 | */ | - | ||||||||||||||||||||||||
| 1618 | - | |||||||||||||||||||||||||
| 1619 | /*! | - | ||||||||||||||||||||||||
| 1620 | Returns \c true if the directory path is relative; otherwise returns | - | ||||||||||||||||||||||||
| 1621 | false. (Under Unix a path is relative if it does not start with a | - | ||||||||||||||||||||||||
| 1622 | "/"). | - | ||||||||||||||||||||||||
| 1623 | - | |||||||||||||||||||||||||
| 1624 | \sa makeAbsolute(), isAbsolute(), isAbsolutePath(), cleanPath() | - | ||||||||||||||||||||||||
| 1625 | */ | - | ||||||||||||||||||||||||
| 1626 | bool QDir::isRelative() const | - | ||||||||||||||||||||||||
| 1627 | { | - | ||||||||||||||||||||||||
| 1628 | if (d_ptr->fileEngine.isNull())
| 1-15 | ||||||||||||||||||||||||
| 1629 | return d_ptr->dirEntry.isRelative(); executed 15 times by 2 tests: return d_ptr->dirEntry.isRelative();Executed by:
| 15 | ||||||||||||||||||||||||
| 1630 | return d_ptr->fileEngine->isRelativePath(); executed 1 time by 1 test: return d_ptr->fileEngine->isRelativePath();Executed by:
| 1 | ||||||||||||||||||||||||
| 1631 | } | - | ||||||||||||||||||||||||
| 1632 | - | |||||||||||||||||||||||||
| 1633 | - | |||||||||||||||||||||||||
| 1634 | /*! | - | ||||||||||||||||||||||||
| 1635 | Converts the directory path to an absolute path. If it is already | - | ||||||||||||||||||||||||
| 1636 | absolute nothing happens. Returns \c true if the conversion | - | ||||||||||||||||||||||||
| 1637 | succeeded; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1638 | - | |||||||||||||||||||||||||
| 1639 | \sa isAbsolute(), isAbsolutePath(), isRelative(), cleanPath() | - | ||||||||||||||||||||||||
| 1640 | */ | - | ||||||||||||||||||||||||
| 1641 | bool QDir::makeAbsolute() | - | ||||||||||||||||||||||||
| 1642 | { | - | ||||||||||||||||||||||||
| 1643 | const QDirPrivate *d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1644 | QScopedPointer<QDirPrivate> dir; | - | ||||||||||||||||||||||||
| 1645 | if (!d->fileEngine.isNull()) {
| 0-1 | ||||||||||||||||||||||||
| 1646 | QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName); | - | ||||||||||||||||||||||||
| 1647 | if (QDir::isRelativePath(absolutePath))
| 0 | ||||||||||||||||||||||||
| 1648 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1649 | - | |||||||||||||||||||||||||
| 1650 | dir.reset(new QDirPrivate(*d_ptr.constData())); | - | ||||||||||||||||||||||||
| 1651 | dir->setPath(absolutePath); | - | ||||||||||||||||||||||||
| 1652 | } else { // native FS never executed: end of block | 0 | ||||||||||||||||||||||||
| 1653 | d->resolveAbsoluteEntry(); | - | ||||||||||||||||||||||||
| 1654 | dir.reset(new QDirPrivate(*d_ptr.constData())); | - | ||||||||||||||||||||||||
| 1655 | dir->setPath(d->absoluteDirEntry.filePath()); | - | ||||||||||||||||||||||||
| 1656 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 1657 | d_ptr = dir.take(); // actually detach | - | ||||||||||||||||||||||||
| 1658 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||||||||
| 1659 | } | - | ||||||||||||||||||||||||
| 1660 | - | |||||||||||||||||||||||||
| 1661 | /*! | - | ||||||||||||||||||||||||
| 1662 | Returns \c true if directory \a dir and this directory have the same | - | ||||||||||||||||||||||||
| 1663 | path and their sort and filter settings are the same; otherwise | - | ||||||||||||||||||||||||
| 1664 | returns \c false. | - | ||||||||||||||||||||||||
| 1665 | - | |||||||||||||||||||||||||
| 1666 | Example: | - | ||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||
| 1668 | \snippet code/src_corelib_io_qdir.cpp 10 | - | ||||||||||||||||||||||||
| 1669 | */ | - | ||||||||||||||||||||||||
| 1670 | bool QDir::operator==(const QDir &dir) const | - | ||||||||||||||||||||||||
| 1671 | { | - | ||||||||||||||||||||||||
| 1672 | const QDirPrivate *d = d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1673 | const QDirPrivate *other = dir.d_ptr.constData(); | - | ||||||||||||||||||||||||
| 1674 | - | |||||||||||||||||||||||||
| 1675 | if (d == other)
| 0-82 | ||||||||||||||||||||||||
| 1676 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1677 | Qt::CaseSensitivity sensitive; | - | ||||||||||||||||||||||||
| 1678 | if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
| 0-82 | ||||||||||||||||||||||||
| 1679 | if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
| 0-82 | ||||||||||||||||||||||||
| 1680 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1681 | - | |||||||||||||||||||||||||
| 1682 | sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 0-82 | ||||||||||||||||||||||||
| 1683 | } else { executed 82 times by 4 tests: end of blockExecuted by:
| 82 | ||||||||||||||||||||||||
| 1684 | if (d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive())
| 0 | ||||||||||||||||||||||||
| 1685 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1686 | sensitive = d->fileEngine->caseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 0 | ||||||||||||||||||||||||
| 1687 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1688 | - | |||||||||||||||||||||||||
| 1689 | if (d->filters == other->filters
| 4-78 | ||||||||||||||||||||||||
| 1690 | && d->sort == other->sort
| 4-74 | ||||||||||||||||||||||||
| 1691 | && d->nameFilters == other->nameFilters) {
| 4-70 | ||||||||||||||||||||||||
| 1692 | - | |||||||||||||||||||||||||
| 1693 | // Assume directories are the same if path is the same | - | ||||||||||||||||||||||||
| 1694 | if (d->dirEntry.filePath() == other->dirEntry.filePath())
| 22-48 | ||||||||||||||||||||||||
| 1695 | return true; executed 22 times by 3 tests: return true;Executed by:
| 22 | ||||||||||||||||||||||||
| 1696 | - | |||||||||||||||||||||||||
| 1697 | if (exists()) {
| 4-44 | ||||||||||||||||||||||||
| 1698 | if (!dir.exists())
| 0-44 | ||||||||||||||||||||||||
| 1699 | return false; //can't be equal if only one exists never executed: return false; | 0 | ||||||||||||||||||||||||
| 1700 | // Both exist, fallback to expensive canonical path computation | - | ||||||||||||||||||||||||
| 1701 | return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0; executed 44 times by 2 tests: return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;Executed by:
| 44 | ||||||||||||||||||||||||
| 1702 | } else { | - | ||||||||||||||||||||||||
| 1703 | if (dir.exists())
| 0-4 | ||||||||||||||||||||||||
| 1704 | return false; //can't be equal if only one exists never executed: return false; | 0 | ||||||||||||||||||||||||
| 1705 | // Neither exists, compare absolute paths rather than canonical (which would be empty strings) | - | ||||||||||||||||||||||||
| 1706 | d->resolveAbsoluteEntry(); | - | ||||||||||||||||||||||||
| 1707 | other->resolveAbsoluteEntry(); | - | ||||||||||||||||||||||||
| 1708 | return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0; executed 4 times by 1 test: return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;Executed by:
| 4 | ||||||||||||||||||||||||
| 1709 | } | - | ||||||||||||||||||||||||
| 1710 | } | - | ||||||||||||||||||||||||
| 1711 | return false; executed 12 times by 1 test: return false;Executed by:
| 12 | ||||||||||||||||||||||||
| 1712 | } | - | ||||||||||||||||||||||||
| 1713 | - | |||||||||||||||||||||||||
| 1714 | /*! | - | ||||||||||||||||||||||||
| 1715 | Makes a copy of the \a dir object and assigns it to this QDir | - | ||||||||||||||||||||||||
| 1716 | object. | - | ||||||||||||||||||||||||
| 1717 | */ | - | ||||||||||||||||||||||||
| 1718 | QDir &QDir::operator=(const QDir &dir) | - | ||||||||||||||||||||||||
| 1719 | { | - | ||||||||||||||||||||||||
| 1720 | d_ptr = dir.d_ptr; | - | ||||||||||||||||||||||||
| 1721 | return *this; executed 377 times by 8 tests: return *this;Executed by:
| 377 | ||||||||||||||||||||||||
| 1722 | } | - | ||||||||||||||||||||||||
| 1723 | - | |||||||||||||||||||||||||
| 1724 | /*! | - | ||||||||||||||||||||||||
| 1725 | \overload | - | ||||||||||||||||||||||||
| 1726 | \obsolete | - | ||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||
| 1728 | Sets the directory path to the given \a path. | - | ||||||||||||||||||||||||
| 1729 | - | |||||||||||||||||||||||||
| 1730 | Use setPath() instead. | - | ||||||||||||||||||||||||
| 1731 | */ | - | ||||||||||||||||||||||||
| 1732 | QDir &QDir::operator=(const QString &path) | - | ||||||||||||||||||||||||
| 1733 | { | - | ||||||||||||||||||||||||
| 1734 | d_ptr->setPath(path); | - | ||||||||||||||||||||||||
| 1735 | return *this; executed 1 time by 1 test: return *this;Executed by:
| 1 | ||||||||||||||||||||||||
| 1736 | } | - | ||||||||||||||||||||||||
| 1737 | - | |||||||||||||||||||||||||
| 1738 | /*! | - | ||||||||||||||||||||||||
| 1739 | \fn void QDir::swap(QDir &other) | - | ||||||||||||||||||||||||
| 1740 | \since 5.0 | - | ||||||||||||||||||||||||
| 1741 | - | |||||||||||||||||||||||||
| 1742 | Swaps this QDir instance with \a other. This function is very fast | - | ||||||||||||||||||||||||
| 1743 | and never fails. | - | ||||||||||||||||||||||||
| 1744 | */ | - | ||||||||||||||||||||||||
| 1745 | - | |||||||||||||||||||||||||
| 1746 | /*! | - | ||||||||||||||||||||||||
| 1747 | \fn bool QDir::operator!=(const QDir &dir) const | - | ||||||||||||||||||||||||
| 1748 | - | |||||||||||||||||||||||||
| 1749 | Returns \c true if directory \a dir and this directory have different | - | ||||||||||||||||||||||||
| 1750 | paths or different sort or filter settings; otherwise returns | - | ||||||||||||||||||||||||
| 1751 | false. | - | ||||||||||||||||||||||||
| 1752 | - | |||||||||||||||||||||||||
| 1753 | Example: | - | ||||||||||||||||||||||||
| 1754 | - | |||||||||||||||||||||||||
| 1755 | \snippet code/src_corelib_io_qdir.cpp 11 | - | ||||||||||||||||||||||||
| 1756 | */ | - | ||||||||||||||||||||||||
| 1757 | - | |||||||||||||||||||||||||
| 1758 | /*! | - | ||||||||||||||||||||||||
| 1759 | Removes the file, \a fileName. | - | ||||||||||||||||||||||||
| 1760 | - | |||||||||||||||||||||||||
| 1761 | Returns \c true if the file is removed successfully; otherwise | - | ||||||||||||||||||||||||
| 1762 | returns \c false. | - | ||||||||||||||||||||||||
| 1763 | */ | - | ||||||||||||||||||||||||
| 1764 | bool QDir::remove(const QString &fileName) | - | ||||||||||||||||||||||||
| 1765 | { | - | ||||||||||||||||||||||||
| 1766 | if (fileName.isEmpty()) {
| 1-26 | ||||||||||||||||||||||||
| 1767 | qWarning("QDir::remove: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1768 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 1769 | } | - | ||||||||||||||||||||||||
| 1770 | return QFile::remove(filePath(fileName)); executed 26 times by 3 tests: return QFile::remove(filePath(fileName));Executed by:
| 26 | ||||||||||||||||||||||||
| 1771 | } | - | ||||||||||||||||||||||||
| 1772 | - | |||||||||||||||||||||||||
| 1773 | /*! | - | ||||||||||||||||||||||||
| 1774 | Renames a file or directory from \a oldName to \a newName, and returns | - | ||||||||||||||||||||||||
| 1775 | true if successful; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1776 | - | |||||||||||||||||||||||||
| 1777 | On most file systems, rename() fails only if \a oldName does not | - | ||||||||||||||||||||||||
| 1778 | exist, or if a file with the new name already exists. | - | ||||||||||||||||||||||||
| 1779 | However, there are also other reasons why rename() can | - | ||||||||||||||||||||||||
| 1780 | fail. For example, on at least one file system rename() fails if | - | ||||||||||||||||||||||||
| 1781 | \a newName points to an open file. | - | ||||||||||||||||||||||||
| 1782 | - | |||||||||||||||||||||||||
| 1783 | If \a oldName is a file (not a directory) that can't be renamed | - | ||||||||||||||||||||||||
| 1784 | right away, Qt will try to copy \a oldName to \a newName and remove | - | ||||||||||||||||||||||||
| 1785 | \a oldName. | - | ||||||||||||||||||||||||
| 1786 | - | |||||||||||||||||||||||||
| 1787 | \sa QFile::rename() | - | ||||||||||||||||||||||||
| 1788 | */ | - | ||||||||||||||||||||||||
| 1789 | bool QDir::rename(const QString &oldName, const QString &newName) | - | ||||||||||||||||||||||||
| 1790 | { | - | ||||||||||||||||||||||||
| 1791 | if (oldName.isEmpty() || newName.isEmpty()) {
| 1-18 | ||||||||||||||||||||||||
| 1792 | qWarning("QDir::rename: Empty or null file name(s)"); | - | ||||||||||||||||||||||||
| 1793 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 1794 | } | - | ||||||||||||||||||||||||
| 1795 | - | |||||||||||||||||||||||||
| 1796 | QFile file(filePath(oldName)); | - | ||||||||||||||||||||||||
| 1797 | if (!file.exists())
| 1-16 | ||||||||||||||||||||||||
| 1798 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 1799 | return file.rename(filePath(newName)); executed 16 times by 4 tests: return file.rename(filePath(newName));Executed by:
| 16 | ||||||||||||||||||||||||
| 1800 | } | - | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | /*! | - | ||||||||||||||||||||||||
| 1803 | Returns \c true if the file called \a name exists; otherwise returns | - | ||||||||||||||||||||||||
| 1804 | false. | - | ||||||||||||||||||||||||
| 1805 | - | |||||||||||||||||||||||||
| 1806 | Unless \a name contains an absolute file path, the file name is assumed | - | ||||||||||||||||||||||||
| 1807 | to be relative to the directory itself, so this function is typically used | - | ||||||||||||||||||||||||
| 1808 | to check for the presence of files within a directory. | - | ||||||||||||||||||||||||
| 1809 | - | |||||||||||||||||||||||||
| 1810 | \sa QFileInfo::exists(), QFile::exists() | - | ||||||||||||||||||||||||
| 1811 | */ | - | ||||||||||||||||||||||||
| 1812 | bool QDir::exists(const QString &name) const | - | ||||||||||||||||||||||||
| 1813 | { | - | ||||||||||||||||||||||||
| 1814 | if (name.isEmpty()) {
| 1-5115 | ||||||||||||||||||||||||
| 1815 | qWarning("QDir::exists: Empty or null file name"); | - | ||||||||||||||||||||||||
| 1816 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 1817 | } | - | ||||||||||||||||||||||||
| 1818 | return QFile::exists(filePath(name)); executed 5115 times by 195 tests: return QFile::exists(filePath(name));Executed by:
| 5115 | ||||||||||||||||||||||||
| 1819 | } | - | ||||||||||||||||||||||||
| 1820 | - | |||||||||||||||||||||||||
| 1821 | /*! | - | ||||||||||||||||||||||||
| 1822 | Returns a list of the root directories on this system. | - | ||||||||||||||||||||||||
| 1823 | - | |||||||||||||||||||||||||
| 1824 | On Windows this returns a list of QFileInfo objects containing "C:/", | - | ||||||||||||||||||||||||
| 1825 | "D:/", etc. On other operating systems, it returns a list containing | - | ||||||||||||||||||||||||
| 1826 | just one root directory (i.e. "/"). | - | ||||||||||||||||||||||||
| 1827 | - | |||||||||||||||||||||||||
| 1828 | \sa root(), rootPath() | - | ||||||||||||||||||||||||
| 1829 | */ | - | ||||||||||||||||||||||||
| 1830 | QFileInfoList QDir::drives() | - | ||||||||||||||||||||||||
| 1831 | { | - | ||||||||||||||||||||||||
| 1832 | #ifdef QT_NO_FSFILEENGINE | - | ||||||||||||||||||||||||
| 1833 | return QFileInfoList(); | - | ||||||||||||||||||||||||
| 1834 | #else | - | ||||||||||||||||||||||||
| 1835 | return QFSFileEngine::drives(); executed 78 times by 13 tests: return QFSFileEngine::drives();Executed by:
| 78 | ||||||||||||||||||||||||
| 1836 | #endif | - | ||||||||||||||||||||||||
| 1837 | } | - | ||||||||||||||||||||||||
| 1838 | - | |||||||||||||||||||||||||
| 1839 | /*! | - | ||||||||||||||||||||||||
| 1840 | Returns the native directory separator: "/" under Unix | - | ||||||||||||||||||||||||
| 1841 | and "\\" under Windows. | - | ||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||
| 1843 | You do not need to use this function to build file paths. If you | - | ||||||||||||||||||||||||
| 1844 | always use "/", Qt will translate your paths to conform to the | - | ||||||||||||||||||||||||
| 1845 | underlying operating system. If you want to display paths to the | - | ||||||||||||||||||||||||
| 1846 | user using their operating system's separator use | - | ||||||||||||||||||||||||
| 1847 | toNativeSeparators(). | - | ||||||||||||||||||||||||
| 1848 | - | |||||||||||||||||||||||||
| 1849 | \sa listSeparator() | - | ||||||||||||||||||||||||
| 1850 | */ | - | ||||||||||||||||||||||||
| 1851 | QChar QDir::separator() | - | ||||||||||||||||||||||||
| 1852 | { | - | ||||||||||||||||||||||||
| 1853 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 1854 | return QLatin1Char('\\'); | - | ||||||||||||||||||||||||
| 1855 | #else | - | ||||||||||||||||||||||||
| 1856 | return QLatin1Char('/'); executed 90130 times by 185 tests: return QLatin1Char('/');Executed by:
| 90130 | ||||||||||||||||||||||||
| 1857 | #endif | - | ||||||||||||||||||||||||
| 1858 | } | - | ||||||||||||||||||||||||
| 1859 | - | |||||||||||||||||||||||||
| 1860 | /*! | - | ||||||||||||||||||||||||
| 1861 | \fn QDir::listSeparator() | - | ||||||||||||||||||||||||
| 1862 | \since 5.6 | - | ||||||||||||||||||||||||
| 1863 | - | |||||||||||||||||||||||||
| 1864 | Returns the native path list separator: ':' under Unix | - | ||||||||||||||||||||||||
| 1865 | and ';' under Windows. | - | ||||||||||||||||||||||||
| 1866 | - | |||||||||||||||||||||||||
| 1867 | \sa separator() | - | ||||||||||||||||||||||||
| 1868 | */ | - | ||||||||||||||||||||||||
| 1869 | - | |||||||||||||||||||||||||
| 1870 | /*! | - | ||||||||||||||||||||||||
| 1871 | Sets the application's current working directory to \a path. | - | ||||||||||||||||||||||||
| 1872 | Returns \c true if the directory was successfully changed; otherwise | - | ||||||||||||||||||||||||
| 1873 | returns \c false. | - | ||||||||||||||||||||||||
| 1874 | - | |||||||||||||||||||||||||
| 1875 | \sa current(), currentPath(), home(), root(), temp() | - | ||||||||||||||||||||||||
| 1876 | */ | - | ||||||||||||||||||||||||
| 1877 | bool QDir::setCurrent(const QString &path) | - | ||||||||||||||||||||||||
| 1878 | { | - | ||||||||||||||||||||||||
| 1879 | return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path)); executed 494 times by 25 tests: return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));Executed by:
| 494 | ||||||||||||||||||||||||
| 1880 | } | - | ||||||||||||||||||||||||
| 1881 | - | |||||||||||||||||||||||||
| 1882 | /*! | - | ||||||||||||||||||||||||
| 1883 | \fn QDir QDir::current() | - | ||||||||||||||||||||||||
| 1884 | - | |||||||||||||||||||||||||
| 1885 | Returns the application's current directory. | - | ||||||||||||||||||||||||
| 1886 | - | |||||||||||||||||||||||||
| 1887 | The directory is constructed using the absolute path of the current directory, | - | ||||||||||||||||||||||||
| 1888 | ensuring that its path() will be the same as its absolutePath(). | - | ||||||||||||||||||||||||
| 1889 | - | |||||||||||||||||||||||||
| 1890 | \sa currentPath(), setCurrent(), home(), root(), temp() | - | ||||||||||||||||||||||||
| 1891 | */ | - | ||||||||||||||||||||||||
| 1892 | - | |||||||||||||||||||||||||
| 1893 | /*! | - | ||||||||||||||||||||||||
| 1894 | Returns the absolute path of the application's current directory. The | - | ||||||||||||||||||||||||
| 1895 | current directory is the last directory set with QDir::setCurrent() or, if | - | ||||||||||||||||||||||||
| 1896 | that was never called, the directory at which this application was started | - | ||||||||||||||||||||||||
| 1897 | at by the parent process. | - | ||||||||||||||||||||||||
| 1898 | - | |||||||||||||||||||||||||
| 1899 | \sa current(), setCurrent(), homePath(), rootPath(), tempPath(), QCoreApplication::applicationDirPath() | - | ||||||||||||||||||||||||
| 1900 | */ | - | ||||||||||||||||||||||||
| 1901 | QString QDir::currentPath() | - | ||||||||||||||||||||||||
| 1902 | { | - | ||||||||||||||||||||||||
| 1903 | return QFileSystemEngine::currentPath().filePath(); executed 1623 times by 45 tests: return QFileSystemEngine::currentPath().filePath();Executed by:
| 1623 | ||||||||||||||||||||||||
| 1904 | } | - | ||||||||||||||||||||||||
| 1905 | - | |||||||||||||||||||||||||
| 1906 | /*! | - | ||||||||||||||||||||||||
| 1907 | \fn QDir QDir::home() | - | ||||||||||||||||||||||||
| 1908 | - | |||||||||||||||||||||||||
| 1909 | Returns the user's home directory. | - | ||||||||||||||||||||||||
| 1910 | - | |||||||||||||||||||||||||
| 1911 | The directory is constructed using the absolute path of the home directory, | - | ||||||||||||||||||||||||
| 1912 | ensuring that its path() will be the same as its absolutePath(). | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | See homePath() for details. | - | ||||||||||||||||||||||||
| 1915 | - | |||||||||||||||||||||||||
| 1916 | \sa drives(), current(), root(), temp() | - | ||||||||||||||||||||||||
| 1917 | */ | - | ||||||||||||||||||||||||
| 1918 | - | |||||||||||||||||||||||||
| 1919 | /*! | - | ||||||||||||||||||||||||
| 1920 | Returns the absolute path of the user's home directory. | - | ||||||||||||||||||||||||
| 1921 | - | |||||||||||||||||||||||||
| 1922 | Under Windows this function will return the directory of the | - | ||||||||||||||||||||||||
| 1923 | current user's profile. Typically, this is: | - | ||||||||||||||||||||||||
| 1924 | - | |||||||||||||||||||||||||
| 1925 | \snippet code/src_corelib_io_qdir.cpp 12 | - | ||||||||||||||||||||||||
| 1926 | - | |||||||||||||||||||||||||
| 1927 | Use the toNativeSeparators() function to convert the separators to | - | ||||||||||||||||||||||||
| 1928 | the ones that are appropriate for the underlying operating system. | - | ||||||||||||||||||||||||
| 1929 | - | |||||||||||||||||||||||||
| 1930 | If the directory of the current user's profile does not exist or | - | ||||||||||||||||||||||||
| 1931 | cannot be retrieved, the following alternatives will be checked (in | - | ||||||||||||||||||||||||
| 1932 | the given order) until an existing and available path is found: | - | ||||||||||||||||||||||||
| 1933 | - | |||||||||||||||||||||||||
| 1934 | \list 1 | - | ||||||||||||||||||||||||
| 1935 | \li The path specified by the \c USERPROFILE environment variable. | - | ||||||||||||||||||||||||
| 1936 | \li The path formed by concatenating the \c HOMEDRIVE and \c HOMEPATH | - | ||||||||||||||||||||||||
| 1937 | environment variables. | - | ||||||||||||||||||||||||
| 1938 | \li The path specified by the \c HOME environment variable. | - | ||||||||||||||||||||||||
| 1939 | \li The path returned by the rootPath() function (which uses the \c SystemDrive | - | ||||||||||||||||||||||||
| 1940 | environment variable) | - | ||||||||||||||||||||||||
| 1941 | \li The \c{C:/} directory. | - | ||||||||||||||||||||||||
| 1942 | \endlist | - | ||||||||||||||||||||||||
| 1943 | - | |||||||||||||||||||||||||
| 1944 | Under non-Windows operating systems the \c HOME environment | - | ||||||||||||||||||||||||
| 1945 | variable is used if it exists, otherwise the path returned by the | - | ||||||||||||||||||||||||
| 1946 | rootPath(). | - | ||||||||||||||||||||||||
| 1947 | - | |||||||||||||||||||||||||
| 1948 | \sa home(), currentPath(), rootPath(), tempPath() | - | ||||||||||||||||||||||||
| 1949 | */ | - | ||||||||||||||||||||||||
| 1950 | QString QDir::homePath() | - | ||||||||||||||||||||||||
| 1951 | { | - | ||||||||||||||||||||||||
| 1952 | return QFileSystemEngine::homePath(); executed 4648 times by 68 tests: return QFileSystemEngine::homePath();Executed by:
| 4648 | ||||||||||||||||||||||||
| 1953 | } | - | ||||||||||||||||||||||||
| 1954 | - | |||||||||||||||||||||||||
| 1955 | /*! | - | ||||||||||||||||||||||||
| 1956 | \fn QDir QDir::temp() | - | ||||||||||||||||||||||||
| 1957 | - | |||||||||||||||||||||||||
| 1958 | Returns the system's temporary directory. | - | ||||||||||||||||||||||||
| 1959 | - | |||||||||||||||||||||||||
| 1960 | The directory is constructed using the absolute path of the temporary directory, | - | ||||||||||||||||||||||||
| 1961 | ensuring that its path() will be the same as its absolutePath(). | - | ||||||||||||||||||||||||
| 1962 | - | |||||||||||||||||||||||||
| 1963 | See tempPath() for details. | - | ||||||||||||||||||||||||
| 1964 | - | |||||||||||||||||||||||||
| 1965 | \sa drives(), current(), home(), root() | - | ||||||||||||||||||||||||
| 1966 | */ | - | ||||||||||||||||||||||||
| 1967 | - | |||||||||||||||||||||||||
| 1968 | /*! | - | ||||||||||||||||||||||||
| 1969 | Returns the absolute path of the system's temporary directory. | - | ||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||
| 1971 | On Unix/Linux systems this is the path in the \c TMPDIR environment | - | ||||||||||||||||||||||||
| 1972 | variable or \c{/tmp} if \c TMPDIR is not defined. On Windows this is | - | ||||||||||||||||||||||||
| 1973 | usually the path in the \c TEMP or \c TMP environment | - | ||||||||||||||||||||||||
| 1974 | variable. | - | ||||||||||||||||||||||||
| 1975 | The path returned by this method doesn't end with a directory separator | - | ||||||||||||||||||||||||
| 1976 | unless it is the root directory (of a drive). | - | ||||||||||||||||||||||||
| 1977 | - | |||||||||||||||||||||||||
| 1978 | \sa temp(), currentPath(), homePath(), rootPath() | - | ||||||||||||||||||||||||
| 1979 | */ | - | ||||||||||||||||||||||||
| 1980 | QString QDir::tempPath() | - | ||||||||||||||||||||||||
| 1981 | { | - | ||||||||||||||||||||||||
| 1982 | return QFileSystemEngine::tempPath(); executed 8783 times by 49 tests: return QFileSystemEngine::tempPath();Executed by:
| 8783 | ||||||||||||||||||||||||
| 1983 | } | - | ||||||||||||||||||||||||
| 1984 | - | |||||||||||||||||||||||||
| 1985 | /*! | - | ||||||||||||||||||||||||
| 1986 | \fn QDir QDir::root() | - | ||||||||||||||||||||||||
| 1987 | - | |||||||||||||||||||||||||
| 1988 | Returns the root directory. | - | ||||||||||||||||||||||||
| 1989 | - | |||||||||||||||||||||||||
| 1990 | The directory is constructed using the absolute path of the root directory, | - | ||||||||||||||||||||||||
| 1991 | ensuring that its path() will be the same as its absolutePath(). | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | See rootPath() for details. | - | ||||||||||||||||||||||||
| 1994 | - | |||||||||||||||||||||||||
| 1995 | \sa drives(), current(), home(), temp() | - | ||||||||||||||||||||||||
| 1996 | */ | - | ||||||||||||||||||||||||
| 1997 | - | |||||||||||||||||||||||||
| 1998 | /*! | - | ||||||||||||||||||||||||
| 1999 | Returns the absolute path of the root directory. | - | ||||||||||||||||||||||||
| 2000 | - | |||||||||||||||||||||||||
| 2001 | For Unix operating systems this returns "/". For Windows file | - | ||||||||||||||||||||||||
| 2002 | systems this normally returns "c:/". | - | ||||||||||||||||||||||||
| 2003 | - | |||||||||||||||||||||||||
| 2004 | \sa root(), drives(), currentPath(), homePath(), tempPath() | - | ||||||||||||||||||||||||
| 2005 | */ | - | ||||||||||||||||||||||||
| 2006 | QString QDir::rootPath() | - | ||||||||||||||||||||||||
| 2007 | { | - | ||||||||||||||||||||||||
| 2008 | return QFileSystemEngine::rootPath(); executed 43 times by 6 tests: return QFileSystemEngine::rootPath();Executed by:
| 43 | ||||||||||||||||||||||||
| 2009 | } | - | ||||||||||||||||||||||||
| 2010 | - | |||||||||||||||||||||||||
| 2011 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 2012 | /*! | - | ||||||||||||||||||||||||
| 2013 | \overload | - | ||||||||||||||||||||||||
| 2014 | - | |||||||||||||||||||||||||
| 2015 | Returns \c true if the \a fileName matches any of the wildcard (glob) | - | ||||||||||||||||||||||||
| 2016 | patterns in the list of \a filters; otherwise returns \c false. The | - | ||||||||||||||||||||||||
| 2017 | matching is case insensitive. | - | ||||||||||||||||||||||||
| 2018 | - | |||||||||||||||||||||||||
| 2019 | \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() | - | ||||||||||||||||||||||||
| 2020 | */ | - | ||||||||||||||||||||||||
| 2021 | bool QDir::match(const QStringList &filters, const QString &fileName) | - | ||||||||||||||||||||||||
| 2022 | { | - | ||||||||||||||||||||||||
| 2023 | for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
| 4-14 | ||||||||||||||||||||||||
| 2024 | QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard); | - | ||||||||||||||||||||||||
| 2025 | if (rx.exactMatch(fileName))
| 6-8 | ||||||||||||||||||||||||
| 2026 | return true; executed 6 times by 1 test: return true;Executed by:
| 6 | ||||||||||||||||||||||||
| 2027 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 2028 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||||||||
| 2029 | } | - | ||||||||||||||||||||||||
| 2030 | - | |||||||||||||||||||||||||
| 2031 | /*! | - | ||||||||||||||||||||||||
| 2032 | Returns \c true if the \a fileName matches the wildcard (glob) | - | ||||||||||||||||||||||||
| 2033 | pattern \a filter; otherwise returns \c false. The \a filter may | - | ||||||||||||||||||||||||
| 2034 | contain multiple patterns separated by spaces or semicolons. | - | ||||||||||||||||||||||||
| 2035 | The matching is case insensitive. | - | ||||||||||||||||||||||||
| 2036 | - | |||||||||||||||||||||||||
| 2037 | \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() | - | ||||||||||||||||||||||||
| 2038 | */ | - | ||||||||||||||||||||||||
| 2039 | bool QDir::match(const QString &filter, const QString &fileName) | - | ||||||||||||||||||||||||
| 2040 | { | - | ||||||||||||||||||||||||
| 2041 | return match(nameFiltersFromString(filter), fileName); executed 5 times by 1 test: return match(nameFiltersFromString(filter), fileName);Executed by:
| 5 | ||||||||||||||||||||||||
| 2042 | } | - | ||||||||||||||||||||||||
| 2043 | #endif // QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 2044 | - | |||||||||||||||||||||||||
| 2045 | /*! | - | ||||||||||||||||||||||||
| 2046 | Returns \a path with redundant directory separators removed, | - | ||||||||||||||||||||||||
| 2047 | and "."s and ".."s resolved (as far as possible). | - | ||||||||||||||||||||||||
| 2048 | - | |||||||||||||||||||||||||
| 2049 | This method is shared with QUrl, so it doesn't deal with QDir::separator(), | - | ||||||||||||||||||||||||
| 2050 | nor does it remove the trailing slash, if any. | - | ||||||||||||||||||||||||
| 2051 | */ | - | ||||||||||||||||||||||||
| 2052 | Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool allowUncPaths) | - | ||||||||||||||||||||||||
| 2053 | { | - | ||||||||||||||||||||||||
| 2054 | const int len = name.length(); | - | ||||||||||||||||||||||||
| 2055 | - | |||||||||||||||||||||||||
| 2056 | if (len == 0)
| 0-76323 | ||||||||||||||||||||||||
| 2057 | return name; never executed: return name; | 0 | ||||||||||||||||||||||||
| 2058 | - | |||||||||||||||||||||||||
| 2059 | int i = len - 1; | - | ||||||||||||||||||||||||
| 2060 | QVarLengthArray<QChar> outVector(len); | - | ||||||||||||||||||||||||
| 2061 | int used = len; | - | ||||||||||||||||||||||||
| 2062 | QChar *out = outVector.data(); | - | ||||||||||||||||||||||||
| 2063 | const QChar *p = name.unicode(); | - | ||||||||||||||||||||||||
| 2064 | const QChar *prefix = p; | - | ||||||||||||||||||||||||
| 2065 | int up = 0; | - | ||||||||||||||||||||||||
| 2066 | - | |||||||||||||||||||||||||
| 2067 | int prefixLength = 0; | - | ||||||||||||||||||||||||
| 2068 | - | |||||||||||||||||||||||||
| 2069 | if (allowUncPaths && len >= 2 && p[1].unicode() == '/' && p[0].unicode() == '/') {
| 2-76271 | ||||||||||||||||||||||||
| 2070 | // starts with double slash | - | ||||||||||||||||||||||||
| 2071 | prefixLength = 2; | - | ||||||||||||||||||||||||
| 2072 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 2073 | } else if (len >= 2 && p[1].unicode() == ':') { | - | ||||||||||||||||||||||||
| 2074 | // remember the drive letter | - | ||||||||||||||||||||||||
| 2075 | prefixLength = (len > 2 && p[2].unicode() == '/') ? 3 : 2; | - | ||||||||||||||||||||||||
| 2076 | #endif | - | ||||||||||||||||||||||||
| 2077 | } else if (p[0].unicode() == '/') { executed 3 times by 1 test: end of blockExecuted by:
| 3-76179 | ||||||||||||||||||||||||
| 2078 | prefixLength = 1; | - | ||||||||||||||||||||||||
| 2079 | } executed 76179 times by 184 tests: end of blockExecuted by:
| 76179 | ||||||||||||||||||||||||
| 2080 | p += prefixLength; | - | ||||||||||||||||||||||||
| 2081 | i -= prefixLength; | - | ||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | // replicate trailing slash (i > 0 checks for emptiness of input string p) | - | ||||||||||||||||||||||||
| 2084 | if (i > 0 && p[i].unicode() == '/') {
| 100-76223 | ||||||||||||||||||||||||
| 2085 | out[--used].unicode() = '/'; | - | ||||||||||||||||||||||||
| 2086 | --i; | - | ||||||||||||||||||||||||
| 2087 | } executed 232 times by 14 tests: end of blockExecuted by:
| 232 | ||||||||||||||||||||||||
| 2088 | - | |||||||||||||||||||||||||
| 2089 | while (i >= 0) {
| 76323-357473 | ||||||||||||||||||||||||
| 2090 | // remove trailing slashes | - | ||||||||||||||||||||||||
| 2091 | if (p[i].unicode() == '/') {
| 3548-353925 | ||||||||||||||||||||||||
| 2092 | --i; | - | ||||||||||||||||||||||||
| 2093 | continue; executed 3548 times by 64 tests: continue;Executed by:
| 3548 | ||||||||||||||||||||||||
| 2094 | } | - | ||||||||||||||||||||||||
| 2095 | - | |||||||||||||||||||||||||
| 2096 | // remove current directory | - | ||||||||||||||||||||||||
| 2097 | if (p[i].unicode() == '.' && (i == 0 || p[i-1].unicode() == '/')) {
| 43-350402 | ||||||||||||||||||||||||
| 2098 | --i; | - | ||||||||||||||||||||||||
| 2099 | continue; executed 1546 times by 40 tests: continue;Executed by:
| 1546 | ||||||||||||||||||||||||
| 2100 | } | - | ||||||||||||||||||||||||
| 2101 | - | |||||||||||||||||||||||||
| 2102 | // detect up dir | - | ||||||||||||||||||||||||
| 2103 | if (i >= 1 && p[i].unicode() == '.' && p[i-1].unicode() == '.'
| 2-352356 | ||||||||||||||||||||||||
| 2104 | && (i == 1 || (i >= 2 && p[i-2].unicode() == '/'))) {
| 0-1907 | ||||||||||||||||||||||||
| 2105 | ++up; | - | ||||||||||||||||||||||||
| 2106 | i -= 2; | - | ||||||||||||||||||||||||
| 2107 | continue; executed 1970 times by 20 tests: continue;Executed by:
| 1970 | ||||||||||||||||||||||||
| 2108 | } | - | ||||||||||||||||||||||||
| 2109 | - | |||||||||||||||||||||||||
| 2110 | // prepend a slash before copying when not empty | - | ||||||||||||||||||||||||
| 2111 | if (!up && used != len && out[used].unicode() != '/')
| 221-349369 | ||||||||||||||||||||||||
| 2112 | out[--used] = QLatin1Char('/'); executed 273308 times by 174 tests: out[--used] = QLatin1Char('/');Executed by:
| 273308 | ||||||||||||||||||||||||
| 2113 | - | |||||||||||||||||||||||||
| 2114 | // skip or copy | - | ||||||||||||||||||||||||
| 2115 | while (i >= 0) {
| 73531-3370292 | ||||||||||||||||||||||||
| 2116 | if (p[i].unicode() == '/') { // do not copy slashes
| 276878-3093414 | ||||||||||||||||||||||||
| 2117 | --i; | - | ||||||||||||||||||||||||
| 2118 | break; executed 276878 times by 174 tests: break;Executed by:
| 276878 | ||||||||||||||||||||||||
| 2119 | } | - | ||||||||||||||||||||||||
| 2120 | - | |||||||||||||||||||||||||
| 2121 | // actual copy | - | ||||||||||||||||||||||||
| 2122 | if (!up)
| 9208-3084206 | ||||||||||||||||||||||||
| 2123 | out[--used] = p[i]; executed 3084206 times by 184 tests: out[--used] = p[i];Executed by:
| 3084206 | ||||||||||||||||||||||||
| 2124 | --i; | - | ||||||||||||||||||||||||
| 2125 | } executed 3093414 times by 184 tests: end of blockExecuted by:
| 3093414 | ||||||||||||||||||||||||
| 2126 | - | |||||||||||||||||||||||||
| 2127 | // decrement up after copying/skipping | - | ||||||||||||||||||||||||
| 2128 | if (up)
| 1040-349369 | ||||||||||||||||||||||||
| 2129 | --up; executed 1040 times by 20 tests: --up;Executed by:
| 1040 | ||||||||||||||||||||||||
| 2130 | } executed 350409 times by 184 tests: end of blockExecuted by:
| 350409 | ||||||||||||||||||||||||
| 2131 | - | |||||||||||||||||||||||||
| 2132 | // add remaining '..' | - | ||||||||||||||||||||||||
| 2133 | while (up) {
| 930-76323 | ||||||||||||||||||||||||
| 2134 | if (used != len && out[used].unicode() != '/') // is not empty and there isn't already a '/'
| 4-817 | ||||||||||||||||||||||||
| 2135 | out[--used] = QLatin1Char('/'); executed 813 times by 3 tests: out[--used] = QLatin1Char('/');Executed by:
| 813 | ||||||||||||||||||||||||
| 2136 | out[--used] = QLatin1Char('.'); | - | ||||||||||||||||||||||||
| 2137 | out[--used] = QLatin1Char('.'); | - | ||||||||||||||||||||||||
| 2138 | --up; | - | ||||||||||||||||||||||||
| 2139 | } executed 930 times by 5 tests: end of blockExecuted by:
| 930 | ||||||||||||||||||||||||
| 2140 | - | |||||||||||||||||||||||||
| 2141 | bool isEmpty = used == len; | - | ||||||||||||||||||||||||
| 2142 | - | |||||||||||||||||||||||||
| 2143 | if (prefixLength) {
| 141-76182 | ||||||||||||||||||||||||
| 2144 | if (!isEmpty && out[used].unicode() == '/') {
| 2-76061 | ||||||||||||||||||||||||
| 2145 | // Eventhough there is a prefix the out string is a slash. This happens, if the input | - | ||||||||||||||||||||||||
| 2146 | // string only consists of a prefix followed by one or more slashes. Just skip the slash. | - | ||||||||||||||||||||||||
| 2147 | ++used; | - | ||||||||||||||||||||||||
| 2148 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2149 | for (int i = prefixLength - 1; i >= 0; --i)
| 76182-76185 | ||||||||||||||||||||||||
| 2150 | out[--used] = prefix[i]; executed 76185 times by 184 tests: out[--used] = prefix[i];Executed by:
| 76185 | ||||||||||||||||||||||||
| 2151 | } else { executed 76182 times by 184 tests: end of blockExecuted by:
| 76182 | ||||||||||||||||||||||||
| 2152 | if (isEmpty) {
| 17-124 | ||||||||||||||||||||||||
| 2153 | // After resolving the input path, the resulting string is empty (e.g. "foo/.."). Return | - | ||||||||||||||||||||||||
| 2154 | // a dot in that case. | - | ||||||||||||||||||||||||
| 2155 | out[--used] = QLatin1Char('.'); | - | ||||||||||||||||||||||||
| 2156 | } else if (out[used].unicode() == '/') { executed 17 times by 4 tests: end of blockExecuted by:
| 5-119 | ||||||||||||||||||||||||
| 2157 | // After parsing the input string, out only contains a slash. That happens whenever all | - | ||||||||||||||||||||||||
| 2158 | // parts are resolved and there is a trailing slash ("./" or "foo/../" for example). | - | ||||||||||||||||||||||||
| 2159 | // Prepend a dot to have the correct return value. | - | ||||||||||||||||||||||||
| 2160 | out[--used] = QLatin1Char('.'); | - | ||||||||||||||||||||||||
| 2161 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 2162 | } executed 141 times by 10 tests: end of blockExecuted by:
| 141 | ||||||||||||||||||||||||
| 2163 | - | |||||||||||||||||||||||||
| 2164 | // If path was not modified return the original value | - | ||||||||||||||||||||||||
| 2165 | QString ret = (used == 0 ? name : QString(out + used, len - used));
| 4841-71482 | ||||||||||||||||||||||||
| 2166 | return ret; executed 76323 times by 184 tests: return ret;Executed by:
| 76323 | ||||||||||||||||||||||||
| 2167 | } | - | ||||||||||||||||||||||||
| 2168 | - | |||||||||||||||||||||||||
| 2169 | /*! | - | ||||||||||||||||||||||||
| 2170 | Returns \a path with directory separators normalized (converted to "/") and | - | ||||||||||||||||||||||||
| 2171 | redundant ones removed, and "."s and ".."s resolved (as far as possible). | - | ||||||||||||||||||||||||
| 2172 | - | |||||||||||||||||||||||||
| 2173 | Symbolic links are kept. This function does not return the | - | ||||||||||||||||||||||||
| 2174 | canonical path, but rather the simplest version of the input. | - | ||||||||||||||||||||||||
| 2175 | For example, "./local" becomes "local", "local/../bin" becomes | - | ||||||||||||||||||||||||
| 2176 | "bin" and "/local/usr/../bin" becomes "/local/bin". | - | ||||||||||||||||||||||||
| 2177 | - | |||||||||||||||||||||||||
| 2178 | \sa absolutePath(), canonicalPath() | - | ||||||||||||||||||||||||
| 2179 | */ | - | ||||||||||||||||||||||||
| 2180 | QString QDir::cleanPath(const QString &path) | - | ||||||||||||||||||||||||
| 2181 | { | - | ||||||||||||||||||||||||
| 2182 | if (path.isEmpty())
| 490-76249 | ||||||||||||||||||||||||
| 2183 | return path; executed 490 times by 5 tests: return path;Executed by:
| 490 | ||||||||||||||||||||||||
| 2184 | QString name = path; | - | ||||||||||||||||||||||||
| 2185 | QChar dir_separator = separator(); | - | ||||||||||||||||||||||||
| 2186 | if (dir_separator != QLatin1Char('/'))
| 0-76249 | ||||||||||||||||||||||||
| 2187 | name.replace(dir_separator, QLatin1Char('/')); never executed: name.replace(dir_separator, QLatin1Char('/')); | 0 | ||||||||||||||||||||||||
| 2188 | - | |||||||||||||||||||||||||
| 2189 | bool allowUncPaths = false; | - | ||||||||||||||||||||||||
| 2190 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) //allow unc paths | - | ||||||||||||||||||||||||
| 2191 | allowUncPaths = true; | - | ||||||||||||||||||||||||
| 2192 | #endif | - | ||||||||||||||||||||||||
| 2193 | - | |||||||||||||||||||||||||
| 2194 | QString ret = qt_normalizePathSegments(name, allowUncPaths); | - | ||||||||||||||||||||||||
| 2195 | - | |||||||||||||||||||||||||
| 2196 | // Strip away last slash except for root directories | - | ||||||||||||||||||||||||
| 2197 | if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
| 125-76124 | ||||||||||||||||||||||||
| 2198 | #if defined (Q_OS_WIN) | - | ||||||||||||||||||||||||
| 2199 | # if defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 2200 | if (!((ret.length() == 3 || ret.length() == QDir::rootPath().length()) && ret.at(1) == QLatin1Char(':'))) | - | ||||||||||||||||||||||||
| 2201 | # else | - | ||||||||||||||||||||||||
| 2202 | if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':'))) | - | ||||||||||||||||||||||||
| 2203 | # endif | - | ||||||||||||||||||||||||
| 2204 | #endif | - | ||||||||||||||||||||||||
| 2205 | ret.chop(1); | - | ||||||||||||||||||||||||
| 2206 | } executed 211 times by 13 tests: end of blockExecuted by:
| 211 | ||||||||||||||||||||||||
| 2207 | - | |||||||||||||||||||||||||
| 2208 | return ret; executed 76249 times by 184 tests: return ret;Executed by:
| 76249 | ||||||||||||||||||||||||
| 2209 | } | - | ||||||||||||||||||||||||
| 2210 | - | |||||||||||||||||||||||||
| 2211 | /*! | - | ||||||||||||||||||||||||
| 2212 | Returns \c true if \a path is relative; returns \c false if it is | - | ||||||||||||||||||||||||
| 2213 | absolute. | - | ||||||||||||||||||||||||
| 2214 | - | |||||||||||||||||||||||||
| 2215 | \sa isRelative(), isAbsolutePath(), makeAbsolute() | - | ||||||||||||||||||||||||
| 2216 | */ | - | ||||||||||||||||||||||||
| 2217 | bool QDir::isRelativePath(const QString &path) | - | ||||||||||||||||||||||||
| 2218 | { | - | ||||||||||||||||||||||||
| 2219 | return QFileInfo(path).isRelative(); executed 19303 times by 252 tests: return QFileInfo(path).isRelative();Executed by:
| 19303 | ||||||||||||||||||||||||
| 2220 | } | - | ||||||||||||||||||||||||
| 2221 | - | |||||||||||||||||||||||||
| 2222 | /*! | - | ||||||||||||||||||||||||
| 2223 | Refreshes the directory information. | - | ||||||||||||||||||||||||
| 2224 | */ | - | ||||||||||||||||||||||||
| 2225 | void QDir::refresh() const | - | ||||||||||||||||||||||||
| 2226 | { | - | ||||||||||||||||||||||||
| 2227 | QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data(); | - | ||||||||||||||||||||||||
| 2228 | d->metaData.clear(); | - | ||||||||||||||||||||||||
| 2229 | d->initFileEngine(); | - | ||||||||||||||||||||||||
| 2230 | d->clearFileLists(); | - | ||||||||||||||||||||||||
| 2231 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2232 | - | |||||||||||||||||||||||||
| 2233 | /*! | - | ||||||||||||||||||||||||
| 2234 | \internal | - | ||||||||||||||||||||||||
| 2235 | */ | - | ||||||||||||||||||||||||
| 2236 | QDirPrivate* QDir::d_func() | - | ||||||||||||||||||||||||
| 2237 | { | - | ||||||||||||||||||||||||
| 2238 | return d_ptr.data(); never executed: return d_ptr.data(); | 0 | ||||||||||||||||||||||||
| 2239 | } | - | ||||||||||||||||||||||||
| 2240 | - | |||||||||||||||||||||||||
| 2241 | /*! | - | ||||||||||||||||||||||||
| 2242 | \internal | - | ||||||||||||||||||||||||
| 2243 | - | |||||||||||||||||||||||||
| 2244 | Returns a list of name filters from the given \a nameFilter. (If | - | ||||||||||||||||||||||||
| 2245 | there is more than one filter, each pair of filters is separated | - | ||||||||||||||||||||||||
| 2246 | by a space or by a semicolon.) | - | ||||||||||||||||||||||||
| 2247 | */ | - | ||||||||||||||||||||||||
| 2248 | QStringList QDir::nameFiltersFromString(const QString &nameFilter) | - | ||||||||||||||||||||||||
| 2249 | { | - | ||||||||||||||||||||||||
| 2250 | return QDirPrivate::splitFilters(nameFilter); executed 32 times by 2 tests: return QDirPrivate::splitFilters(nameFilter);Executed by:
| 32 | ||||||||||||||||||||||||
| 2251 | } | - | ||||||||||||||||||||||||
| 2252 | - | |||||||||||||||||||||||||
| 2253 | /*! | - | ||||||||||||||||||||||||
| 2254 | \macro void Q_INIT_RESOURCE(name) | - | ||||||||||||||||||||||||
| 2255 | \relates QDir | - | ||||||||||||||||||||||||
| 2256 | - | |||||||||||||||||||||||||
| 2257 | Initializes the resources specified by the \c .qrc file with the | - | ||||||||||||||||||||||||
| 2258 | specified base \a name. Normally, when resources are built as part | - | ||||||||||||||||||||||||
| 2259 | of the application, the resources are loaded automatically at | - | ||||||||||||||||||||||||
| 2260 | startup. The Q_INIT_RESOURCE() macro is necessary on some platforms | - | ||||||||||||||||||||||||
| 2261 | for resources stored in a static library. | - | ||||||||||||||||||||||||
| 2262 | - | |||||||||||||||||||||||||
| 2263 | For example, if your application's resources are listed in a file | - | ||||||||||||||||||||||||
| 2264 | called \c myapp.qrc, you can ensure that the resources are | - | ||||||||||||||||||||||||
| 2265 | initialized at startup by adding this line to your \c main() | - | ||||||||||||||||||||||||
| 2266 | function: | - | ||||||||||||||||||||||||
| 2267 | - | |||||||||||||||||||||||||
| 2268 | \snippet code/src_corelib_io_qdir.cpp 13 | - | ||||||||||||||||||||||||
| 2269 | - | |||||||||||||||||||||||||
| 2270 | If the file name contains characters that cannot be part of a valid C++ function name | - | ||||||||||||||||||||||||
| 2271 | (such as '-'), they have to be replaced by the underscore character ('_'). | - | ||||||||||||||||||||||||
| 2272 | - | |||||||||||||||||||||||||
| 2273 | Note: This macro cannot be used in a namespace. It should be called from | - | ||||||||||||||||||||||||
| 2274 | main(). If that is not possible, the following workaround can be used | - | ||||||||||||||||||||||||
| 2275 | to init the resource \c myapp from the function \c{MyNamespace::myFunction}: | - | ||||||||||||||||||||||||
| 2276 | - | |||||||||||||||||||||||||
| 2277 | \snippet code/src_corelib_io_qdir.cpp 14 | - | ||||||||||||||||||||||||
| 2278 | - | |||||||||||||||||||||||||
| 2279 | \sa Q_CLEANUP_RESOURCE(), {The Qt Resource System} | - | ||||||||||||||||||||||||
| 2280 | */ | - | ||||||||||||||||||||||||
| 2281 | - | |||||||||||||||||||||||||
| 2282 | /*! | - | ||||||||||||||||||||||||
| 2283 | \since 4.1 | - | ||||||||||||||||||||||||
| 2284 | \macro void Q_CLEANUP_RESOURCE(name) | - | ||||||||||||||||||||||||
| 2285 | \relates QDir | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | Unloads the resources specified by the \c .qrc file with the base | - | ||||||||||||||||||||||||
| 2288 | name \a name. | - | ||||||||||||||||||||||||
| 2289 | - | |||||||||||||||||||||||||
| 2290 | Normally, Qt resources are unloaded automatically when the | - | ||||||||||||||||||||||||
| 2291 | application terminates, but if the resources are located in a | - | ||||||||||||||||||||||||
| 2292 | plugin that is being unloaded, call Q_CLEANUP_RESOURCE() to force | - | ||||||||||||||||||||||||
| 2293 | removal of your resources. | - | ||||||||||||||||||||||||
| 2294 | - | |||||||||||||||||||||||||
| 2295 | Note: This macro cannot be used in a namespace. Please see the | - | ||||||||||||||||||||||||
| 2296 | Q_INIT_RESOURCE documentation for a workaround. | - | ||||||||||||||||||||||||
| 2297 | - | |||||||||||||||||||||||||
| 2298 | Example: | - | ||||||||||||||||||||||||
| 2299 | - | |||||||||||||||||||||||||
| 2300 | \snippet code/src_corelib_io_qdir.cpp 15 | - | ||||||||||||||||||||||||
| 2301 | - | |||||||||||||||||||||||||
| 2302 | \sa Q_INIT_RESOURCE(), {The Qt Resource System} | - | ||||||||||||||||||||||||
| 2303 | */ | - | ||||||||||||||||||||||||
| 2304 | - | |||||||||||||||||||||||||
| 2305 | - | |||||||||||||||||||||||||
| 2306 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 2307 | QDebug operator<<(QDebug debug, QDir::Filters filters) | - | ||||||||||||||||||||||||
| 2308 | { | - | ||||||||||||||||||||||||
| 2309 | QDebugStateSaver save(debug); | - | ||||||||||||||||||||||||
| 2310 | debug.resetFormat(); | - | ||||||||||||||||||||||||
| 2311 | QStringList flags; | - | ||||||||||||||||||||||||
| 2312 | if (filters == QDir::NoFilter) {
| 0 | ||||||||||||||||||||||||
| 2313 | flags << QLatin1String("NoFilter"); | - | ||||||||||||||||||||||||
| 2314 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2315 | if (filters & QDir::Dirs) flags << QLatin1String("Dirs"); never executed: flags << QLatin1String("Dirs");
| 0 | ||||||||||||||||||||||||
| 2316 | if (filters & QDir::AllDirs) flags << QLatin1String("AllDirs"); never executed: flags << QLatin1String("AllDirs");
| 0 | ||||||||||||||||||||||||
| 2317 | if (filters & QDir::Files) flags << QLatin1String("Files"); never executed: flags << QLatin1String("Files");
| 0 | ||||||||||||||||||||||||
| 2318 | if (filters & QDir::Drives) flags << QLatin1String("Drives"); never executed: flags << QLatin1String("Drives");
| 0 | ||||||||||||||||||||||||
| 2319 | if (filters & QDir::NoSymLinks) flags << QLatin1String("NoSymLinks"); never executed: flags << QLatin1String("NoSymLinks");
| 0 | ||||||||||||||||||||||||
| 2320 | if (filters & QDir::NoDot) flags << QLatin1String("NoDot"); never executed: flags << QLatin1String("NoDot");
| 0 | ||||||||||||||||||||||||
| 2321 | if (filters & QDir::NoDotDot) flags << QLatin1String("NoDotDot"); never executed: flags << QLatin1String("NoDotDot");
| 0 | ||||||||||||||||||||||||
| 2322 | if ((filters & QDir::AllEntries) == QDir::AllEntries) flags << QLatin1String("AllEntries"); never executed: flags << QLatin1String("AllEntries");
| 0 | ||||||||||||||||||||||||
| 2323 | if (filters & QDir::Readable) flags << QLatin1String("Readable"); never executed: flags << QLatin1String("Readable");
| 0 | ||||||||||||||||||||||||
| 2324 | if (filters & QDir::Writable) flags << QLatin1String("Writable"); never executed: flags << QLatin1String("Writable");
| 0 | ||||||||||||||||||||||||
| 2325 | if (filters & QDir::Executable) flags << QLatin1String("Executable"); never executed: flags << QLatin1String("Executable");
| 0 | ||||||||||||||||||||||||
| 2326 | if (filters & QDir::Modified) flags << QLatin1String("Modified"); never executed: flags << QLatin1String("Modified");
| 0 | ||||||||||||||||||||||||
| 2327 | if (filters & QDir::Hidden) flags << QLatin1String("Hidden"); never executed: flags << QLatin1String("Hidden");
| 0 | ||||||||||||||||||||||||
| 2328 | if (filters & QDir::System) flags << QLatin1String("System"); never executed: flags << QLatin1String("System");
| 0 | ||||||||||||||||||||||||
| 2329 | if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive"); never executed: flags << QLatin1String("CaseSensitive");
| 0 | ||||||||||||||||||||||||
| 2330 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2331 | debug.noquote() << "QDir::Filters(" << flags.join(QLatin1Char('|')) << ')'; | - | ||||||||||||||||||||||||
| 2332 | return debug; never executed: return debug; | 0 | ||||||||||||||||||||||||
| 2333 | } | - | ||||||||||||||||||||||||
| 2334 | - | |||||||||||||||||||||||||
| 2335 | static QDebug operator<<(QDebug debug, QDir::SortFlags sorting) | - | ||||||||||||||||||||||||
| 2336 | { | - | ||||||||||||||||||||||||
| 2337 | QDebugStateSaver save(debug); | - | ||||||||||||||||||||||||
| 2338 | debug.resetFormat(); | - | ||||||||||||||||||||||||
| 2339 | if (sorting == QDir::NoSort) {
| 0 | ||||||||||||||||||||||||
| 2340 | debug << "QDir::SortFlags(NoSort)"; | - | ||||||||||||||||||||||||
| 2341 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2342 | QString type; | - | ||||||||||||||||||||||||
| 2343 | if ((sorting & 3) == QDir::Name) type = QLatin1String("Name"); never executed: type = QLatin1String("Name");
| 0 | ||||||||||||||||||||||||
| 2344 | if ((sorting & 3) == QDir::Time) type = QLatin1String("Time"); never executed: type = QLatin1String("Time");
| 0 | ||||||||||||||||||||||||
| 2345 | if ((sorting & 3) == QDir::Size) type = QLatin1String("Size"); never executed: type = QLatin1String("Size");
| 0 | ||||||||||||||||||||||||
| 2346 | if ((sorting & 3) == QDir::Unsorted) type = QLatin1String("Unsorted"); never executed: type = QLatin1String("Unsorted");
| 0 | ||||||||||||||||||||||||
| 2347 | - | |||||||||||||||||||||||||
| 2348 | QStringList flags; | - | ||||||||||||||||||||||||
| 2349 | if (sorting & QDir::DirsFirst) flags << QLatin1String("DirsFirst"); never executed: flags << QLatin1String("DirsFirst");
| 0 | ||||||||||||||||||||||||
| 2350 | if (sorting & QDir::DirsLast) flags << QLatin1String("DirsLast"); never executed: flags << QLatin1String("DirsLast");
| 0 | ||||||||||||||||||||||||
| 2351 | if (sorting & QDir::IgnoreCase) flags << QLatin1String("IgnoreCase"); never executed: flags << QLatin1String("IgnoreCase");
| 0 | ||||||||||||||||||||||||
| 2352 | if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware"); never executed: flags << QLatin1String("LocaleAware");
| 0 | ||||||||||||||||||||||||
| 2353 | if (sorting & QDir::Type) flags << QLatin1String("Type"); never executed: flags << QLatin1String("Type");
| 0 | ||||||||||||||||||||||||
| 2354 | debug.noquote() << "QDir::SortFlags(" << type << '|' << flags.join(QLatin1Char('|')) << ')'; | - | ||||||||||||||||||||||||
| 2355 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2356 | return debug; never executed: return debug; | 0 | ||||||||||||||||||||||||
| 2357 | } | - | ||||||||||||||||||||||||
| 2358 | - | |||||||||||||||||||||||||
| 2359 | QDebug operator<<(QDebug debug, const QDir &dir) | - | ||||||||||||||||||||||||
| 2360 | { | - | ||||||||||||||||||||||||
| 2361 | QDebugStateSaver save(debug); | - | ||||||||||||||||||||||||
| 2362 | debug.resetFormat(); | - | ||||||||||||||||||||||||
| 2363 | debug << "QDir(" << dir.path() << ", nameFilters = {" | - | ||||||||||||||||||||||||
| 2364 | << dir.nameFilters().join(QLatin1Char(',')) | - | ||||||||||||||||||||||||
| 2365 | << "}, " | - | ||||||||||||||||||||||||
| 2366 | << dir.sorting() | - | ||||||||||||||||||||||||
| 2367 | << ',' | - | ||||||||||||||||||||||||
| 2368 | << dir.filter() | - | ||||||||||||||||||||||||
| 2369 | << ')'; | - | ||||||||||||||||||||||||
| 2370 | return debug; never executed: return debug; | 0 | ||||||||||||||||||||||||
| 2371 | } | - | ||||||||||||||||||||||||
| 2372 | #endif // QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 2373 | - | |||||||||||||||||||||||||
| 2374 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |