| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfilesystemmodel.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | #include "qfilesystemmodel_p.h" | - | ||||||||||||||||||||||||
| 35 | #include "qfilesystemmodel.h" | - | ||||||||||||||||||||||||
| 36 | #include <qlocale.h> | - | ||||||||||||||||||||||||
| 37 | #include <qmimedata.h> | - | ||||||||||||||||||||||||
| 38 | #include <qurl.h> | - | ||||||||||||||||||||||||
| 39 | #include <qdebug.h> | - | ||||||||||||||||||||||||
| 40 | #include <qmessagebox.h> | - | ||||||||||||||||||||||||
| 41 | #include <qapplication.h> | - | ||||||||||||||||||||||||
| 42 | #include <QtCore/qcollator.h> | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | #include <algorithm> | - | ||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||
| 46 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 47 | # include <QtCore/QVarLengthArray> | - | ||||||||||||||||||||||||
| 48 | # include <qt_windows.h> | - | ||||||||||||||||||||||||
| 49 | #endif | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | /*! | - | ||||||||||||||||||||||||
| 56 | \enum QFileSystemModel::Roles | - | ||||||||||||||||||||||||
| 57 | \value FileIconRole | - | ||||||||||||||||||||||||
| 58 | \value FilePathRole | - | ||||||||||||||||||||||||
| 59 | \value FileNameRole | - | ||||||||||||||||||||||||
| 60 | \value FilePermissions | - | ||||||||||||||||||||||||
| 61 | */ | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | /*! | - | ||||||||||||||||||||||||
| 64 | \class QFileSystemModel | - | ||||||||||||||||||||||||
| 65 | \since 4.4 | - | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | \brief The QFileSystemModel class provides a data model for the local filesystem. | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | \ingroup model-view | - | ||||||||||||||||||||||||
| 70 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | This class provides access to the local filesystem, providing functions | - | ||||||||||||||||||||||||
| 73 | for renaming and removing files and directories, and for creating new | - | ||||||||||||||||||||||||
| 74 | directories. In the simplest case, it can be used with a suitable display | - | ||||||||||||||||||||||||
| 75 | widget as part of a browser or filter. | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | QFileSystemModel can be accessed using the standard interface provided by | - | ||||||||||||||||||||||||
| 78 | QAbstractItemModel, but it also provides some convenience functions that are | - | ||||||||||||||||||||||||
| 79 | specific to a directory model. | - | ||||||||||||||||||||||||
| 80 | The fileInfo(), isDir(), fileName() and filePath() functions provide information | - | ||||||||||||||||||||||||
| 81 | about the underlying files and directories related to items in the model. | - | ||||||||||||||||||||||||
| 82 | Directories can be created and removed using mkdir(), rmdir(). | - | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | \note QFileSystemModel requires an instance of \l QApplication. | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | \section1 Example Usage | - | ||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | A directory model that displays the contents of a default directory | - | ||||||||||||||||||||||||
| 89 | is usually constructed with a parent object: | - | ||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||
| 91 | \snippet shareddirmodel/main.cpp 2 | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | A tree view can be used to display the contents of the model | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | \snippet shareddirmodel/main.cpp 4 | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | and the contents of a particular directory can be displayed by | - | ||||||||||||||||||||||||
| 98 | setting the tree view's root index: | - | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | \snippet shareddirmodel/main.cpp 7 | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | The view's root index can be used to control how much of a | - | ||||||||||||||||||||||||
| 103 | hierarchical model is displayed. QFileSystemModel provides a convenience | - | ||||||||||||||||||||||||
| 104 | function that returns a suitable model index for a path to a | - | ||||||||||||||||||||||||
| 105 | directory within the model. | - | ||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||
| 107 | \section1 Caching and Performance | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | QFileSystemModel will not fetch any files or directories until setRootPath() | - | ||||||||||||||||||||||||
| 110 | is called. This will prevent any unnecessary querying on the file system | - | ||||||||||||||||||||||||
| 111 | until that point such as listing the drives on Windows. | - | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | Unlike QDirModel, QFileSystemModel uses a separate thread to populate | - | ||||||||||||||||||||||||
| 114 | itself so it will not cause the main thread to hang as the file system | - | ||||||||||||||||||||||||
| 115 | is being queried. Calls to rowCount() will return 0 until the model | - | ||||||||||||||||||||||||
| 116 | populates a directory. | - | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | QFileSystemModel keeps a cache with file information. The cache is | - | ||||||||||||||||||||||||
| 119 | automatically kept up to date using the QFileSystemWatcher. | - | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | \sa {Model Classes} | - | ||||||||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | /*! | - | ||||||||||||||||||||||||
| 125 | \fn bool QFileSystemModel::rmdir(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | Removes the directory corresponding to the model item \a index in the | - | ||||||||||||||||||||||||
| 128 | file system model and \b{deletes the corresponding directory from the | - | ||||||||||||||||||||||||
| 129 | file system}, returning true if successful. If the directory cannot be | - | ||||||||||||||||||||||||
| 130 | removed, false is returned. | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | \warning This function deletes directories from the file system; it does | - | ||||||||||||||||||||||||
| 133 | \b{not} move them to a location where they can be recovered. | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | \sa remove() | - | ||||||||||||||||||||||||
| 136 | */ | - | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | /*! | - | ||||||||||||||||||||||||
| 139 | \fn QIcon QFileSystemModel::fileName(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | Returns the file name for the item stored in the model under the given | - | ||||||||||||||||||||||||
| 142 | \a index. | - | ||||||||||||||||||||||||
| 143 | */ | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | /*! | - | ||||||||||||||||||||||||
| 146 | \fn QIcon QFileSystemModel::fileIcon(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | Returns the icon for the item stored in the model under the given | - | ||||||||||||||||||||||||
| 149 | \a index. | - | ||||||||||||||||||||||||
| 150 | */ | - | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | /*! | - | ||||||||||||||||||||||||
| 153 | \fn QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | Returns the QFileInfo for the item stored in the model under the given | - | ||||||||||||||||||||||||
| 156 | \a index. | - | ||||||||||||||||||||||||
| 157 | */ | - | ||||||||||||||||||||||||
| 158 | QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 159 | { | - | ||||||||||||||||||||||||
| 160 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 161 |     return d->node(index)->fileInfo(); never executed:  return d->node(index)->fileInfo(); | 0 | ||||||||||||||||||||||||
| 162 | } | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | /*! | - | ||||||||||||||||||||||||
| 165 | \fn void QFileSystemModel::rootPathChanged(const QString &newPath); | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | This signal is emitted whenever the root path has been changed to a \a newPath. | - | ||||||||||||||||||||||||
| 168 | */ | - | ||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | /*! | - | ||||||||||||||||||||||||
| 171 | \fn void QFileSystemModel::fileRenamed(const QString &path, const QString &oldName, const QString &newName) | - | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | This signal is emitted whenever a file with the \a oldName is successfully | - | ||||||||||||||||||||||||
| 174 | renamed to \a newName. The file is located in in the directory \a path. | - | ||||||||||||||||||||||||
| 175 | */ | - | ||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | /*! | - | ||||||||||||||||||||||||
| 178 | \since 4.7 | - | ||||||||||||||||||||||||
| 179 | \fn void QFileSystemModel::directoryLoaded(const QString &path) | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | This signal is emitted when the gatherer thread has finished to load the \a path. | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | */ | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | /*! | - | ||||||||||||||||||||||||
| 186 | \fn bool QFileSystemModel::remove(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||
| 188 | Removes the model item \a index from the file system model and \b{deletes the | - | ||||||||||||||||||||||||
| 189 | corresponding file from the file system}, returning true if successful. If the | - | ||||||||||||||||||||||||
| 190 | item cannot be removed, false is returned. | - | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | \warning This function deletes files from the file system; it does \b{not} | - | ||||||||||||||||||||||||
| 193 | move them to a location where they can be recovered. | - | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | \sa rmdir() | - | ||||||||||||||||||||||||
| 196 | */ | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | bool QFileSystemModel::remove(const QModelIndex &aindex) | - | ||||||||||||||||||||||||
| 199 | { | - | ||||||||||||||||||||||||
| 200 | const QString path = filePath(aindex); | - | ||||||||||||||||||||||||
| 201 |     const bool success = QFileInfo(path).isFile() ? QFile::remove(path) : QDir(path).removeRecursively();
  | 0 | ||||||||||||||||||||||||
| 202 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 203 |     if (success) {
  | 0 | ||||||||||||||||||||||||
| 204 | QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); | - | ||||||||||||||||||||||||
| 205 | d->fileInfoGatherer.removePath(path); | - | ||||||||||||||||||||||||
| 206 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 207 | #endif | - | ||||||||||||||||||||||||
| 208 |     return success; never executed:  return success; | 0 | ||||||||||||||||||||||||
| 209 | } | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | /*! | - | ||||||||||||||||||||||||
| 212 | Constructs a file system model with the given \a parent. | - | ||||||||||||||||||||||||
| 213 | */ | - | ||||||||||||||||||||||||
| 214 | QFileSystemModel::QFileSystemModel(QObject *parent) | - | ||||||||||||||||||||||||
| 215 | : QAbstractItemModel(*new QFileSystemModelPrivate, parent) | - | ||||||||||||||||||||||||
| 216 | { | - | ||||||||||||||||||||||||
| 217 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 218 | d->init(); | - | ||||||||||||||||||||||||
| 219 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | /*! | - | ||||||||||||||||||||||||
| 222 | \internal | - | ||||||||||||||||||||||||
| 223 | */ | - | ||||||||||||||||||||||||
| 224 | QFileSystemModel::QFileSystemModel(QFileSystemModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||||||||
| 225 | : QAbstractItemModel(dd, parent) | - | ||||||||||||||||||||||||
| 226 | { | - | ||||||||||||||||||||||||
| 227 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 228 | d->init(); | - | ||||||||||||||||||||||||
| 229 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | /*! | - | ||||||||||||||||||||||||
| 232 | Destroys this file system model. | - | ||||||||||||||||||||||||
| 233 | */ | - | ||||||||||||||||||||||||
| 234 | QFileSystemModel::~QFileSystemModel() | - | ||||||||||||||||||||||||
| 235 | { | - | ||||||||||||||||||||||||
| 236 | } | - | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | /*! | - | ||||||||||||||||||||||||
| 239 | \reimp | - | ||||||||||||||||||||||||
| 240 | */ | - | ||||||||||||||||||||||||
| 241 | QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 242 | { | - | ||||||||||||||||||||||||
| 243 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 244 |     if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
 
 
 
  | 0 | ||||||||||||||||||||||||
| 245 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | // get the parent node | - | ||||||||||||||||||||||||
| 248 |     QFileSystemModelPrivate::QFileSystemNode *parentNode = (d->indexValid(parent) ? d->node(parent) :
  | 0 | ||||||||||||||||||||||||
| 249 | const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&d->root)); | - | ||||||||||||||||||||||||
| 250 | Q_ASSERT(parentNode); | - | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | // now get the internal pointer for the index | - | ||||||||||||||||||||||||
| 253 | const QString &childName = parentNode->visibleChildren.at(d->translateVisibleLocation(parentNode, row)); | - | ||||||||||||||||||||||||
| 254 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = parentNode->children.value(childName); | - | ||||||||||||||||||||||||
| 255 | Q_ASSERT(indexNode); | - | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 |     return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode)); never executed:  return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode)); | 0 | ||||||||||||||||||||||||
| 258 | } | - | ||||||||||||||||||||||||
| 259 | - | |||||||||||||||||||||||||
| 260 | /*! | - | ||||||||||||||||||||||||
| 261 | \overload | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | Returns the model item index for the given \a path and \a column. | - | ||||||||||||||||||||||||
| 264 | */ | - | ||||||||||||||||||||||||
| 265 | QModelIndex QFileSystemModel::index(const QString &path, int column) const | - | ||||||||||||||||||||||||
| 266 | { | - | ||||||||||||||||||||||||
| 267 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 268 | QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false); | - | ||||||||||||||||||||||||
| 269 |     return d->index(node, column); never executed:  return d->index(node, column); | 0 | ||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | /*! | - | ||||||||||||||||||||||||
| 273 | \internal | - | ||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | Return the QFileSystemNode that goes to index. | - | ||||||||||||||||||||||||
| 276 | */ | - | ||||||||||||||||||||||||
| 277 | QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 278 | { | - | ||||||||||||||||||||||||
| 279 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 280 |         return const_cast<QFileSystemNode*>(&root); never executed:  return const_cast<QFileSystemNode*>(&root); | 0 | ||||||||||||||||||||||||
| 281 | QFileSystemModelPrivate::QFileSystemNode *indexNode = static_cast<QFileSystemModelPrivate::QFileSystemNode*>(index.internalPointer()); | - | ||||||||||||||||||||||||
| 282 | Q_ASSERT(indexNode); | - | ||||||||||||||||||||||||
| 283 |     return indexNode; never executed:  return indexNode; | 0 | ||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | #ifdef Q_OS_WIN32 | - | ||||||||||||||||||||||||
| 287 | static QString qt_GetLongPathName(const QString &strShortPath) | - | ||||||||||||||||||||||||
| 288 | { | - | ||||||||||||||||||||||||
| 289 | if (strShortPath.isEmpty() | - | ||||||||||||||||||||||||
| 290 | || strShortPath == QLatin1String(".") || strShortPath == QLatin1String("..")) | - | ||||||||||||||||||||||||
| 291 | return strShortPath; | - | ||||||||||||||||||||||||
| 292 | if (strShortPath.length() == 2 && strShortPath.endsWith(QLatin1Char(':'))) | - | ||||||||||||||||||||||||
| 293 | return strShortPath.toUpper(); | - | ||||||||||||||||||||||||
| 294 | const QString absPath = QDir(strShortPath).absolutePath(); | - | ||||||||||||||||||||||||
| 295 | if (absPath.startsWith(QLatin1String("//")) | - | ||||||||||||||||||||||||
| 296 | || absPath.startsWith(QLatin1String("\\\\"))) // unc | - | ||||||||||||||||||||||||
| 297 | return QDir::fromNativeSeparators(absPath); | - | ||||||||||||||||||||||||
| 298 | if (absPath.startsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 299 | return QString(); | - | ||||||||||||||||||||||||
| 300 | const QString inputString = QLatin1String("\\\\?\\") + QDir::toNativeSeparators(absPath); | - | ||||||||||||||||||||||||
| 301 | QVarLengthArray<TCHAR, MAX_PATH> buffer(MAX_PATH); | - | ||||||||||||||||||||||||
| 302 | DWORD result = ::GetLongPathName((wchar_t*)inputString.utf16(), | - | ||||||||||||||||||||||||
| 303 | buffer.data(), | - | ||||||||||||||||||||||||
| 304 | buffer.size()); | - | ||||||||||||||||||||||||
| 305 | if (result > DWORD(buffer.size())) { | - | ||||||||||||||||||||||||
| 306 | buffer.resize(result); | - | ||||||||||||||||||||||||
| 307 | result = ::GetLongPathName((wchar_t*)inputString.utf16(), | - | ||||||||||||||||||||||||
| 308 | buffer.data(), | - | ||||||||||||||||||||||||
| 309 | buffer.size()); | - | ||||||||||||||||||||||||
| 310 | } | - | ||||||||||||||||||||||||
| 311 | if (result > 4) { | - | ||||||||||||||||||||||||
| 312 | QString longPath = QString::fromWCharArray(buffer.data() + 4); // ignoring prefix | - | ||||||||||||||||||||||||
| 313 | longPath[0] = longPath.at(0).toUpper(); // capital drive letters | - | ||||||||||||||||||||||||
| 314 | return QDir::fromNativeSeparators(longPath); | - | ||||||||||||||||||||||||
| 315 | } else { | - | ||||||||||||||||||||||||
| 316 | return QDir::fromNativeSeparators(strShortPath); | - | ||||||||||||||||||||||||
| 317 | } | - | ||||||||||||||||||||||||
| 318 | } | - | ||||||||||||||||||||||||
| 319 | #endif | - | ||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | /*! | - | ||||||||||||||||||||||||
| 322 | \internal | - | ||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | Given a path return the matching QFileSystemNode or &root if invalid | - | ||||||||||||||||||||||||
| 325 | */ | - | ||||||||||||||||||||||||
| 326 | QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QString &path, bool fetch) const | - | ||||||||||||||||||||||||
| 327 | { | - | ||||||||||||||||||||||||
| 328 | Q_Q(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 329 | Q_UNUSED(q); | - | ||||||||||||||||||||||||
| 330 |     if (path.isEmpty() || path == myComputer() || path.startsWith(QLatin1Char(':')))
 
 
  | 0 | ||||||||||||||||||||||||
| 331 |         return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); never executed:  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | // Construct the nodes up to the new root path if they need to be built | - | ||||||||||||||||||||||||
| 334 | QString absolutePath; | - | ||||||||||||||||||||||||
| 335 | #ifdef Q_OS_WIN32 | - | ||||||||||||||||||||||||
| 336 | QString longPath = qt_GetLongPathName(path); | - | ||||||||||||||||||||||||
| 337 | #else | - | ||||||||||||||||||||||||
| 338 | QString longPath = path; | - | ||||||||||||||||||||||||
| 339 | #endif | - | ||||||||||||||||||||||||
| 340 |     if (longPath == rootDir.path())
  | 0 | ||||||||||||||||||||||||
| 341 |         absolutePath = rootDir.absolutePath(); never executed:  absolutePath = rootDir.absolutePath(); | 0 | ||||||||||||||||||||||||
| 342 | else | - | ||||||||||||||||||||||||
| 343 |         absolutePath = QDir(longPath).absolutePath(); never executed:  absolutePath = QDir(longPath).absolutePath(); | 0 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | // ### TODO can we use bool QAbstractFileEngine::caseSensitive() const? | - | ||||||||||||||||||||||||
| 346 | QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
| 347 |     if ((pathElements.isEmpty())
  | 0 | ||||||||||||||||||||||||
| 348 | #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 349 |         && QDir::fromNativeSeparators(longPath) != QLatin1String("/")
  | 0 | ||||||||||||||||||||||||
| 350 | #endif | - | ||||||||||||||||||||||||
| 351 | ) | - | ||||||||||||||||||||||||
| 352 |         return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); never executed:  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 | ||||||||||||||||||||||||
| 353 | QModelIndex index = QModelIndex(); // start with "My Computer" | - | ||||||||||||||||||||||||
| 354 | QString elementPath; | - | ||||||||||||||||||||||||
| 355 | QChar separator = QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 356 | QString trailingSeparator; | - | ||||||||||||||||||||||||
| 357 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 358 | if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path | - | ||||||||||||||||||||||||
| 359 | QString host = QLatin1String("\\\\") + pathElements.first(); | - | ||||||||||||||||||||||||
| 360 | if (absolutePath == QDir::fromNativeSeparators(host)) | - | ||||||||||||||||||||||||
| 361 | absolutePath.append(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 362 | if (longPath.endsWith(QLatin1Char('/')) && !absolutePath.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 363 | absolutePath.append(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 364 | if (absolutePath.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 365 | trailingSeparator = QLatin1String("\\"); | - | ||||||||||||||||||||||||
| 366 | int r = 0; | - | ||||||||||||||||||||||||
| 367 | QFileSystemModelPrivate::QFileSystemNode *rootNode = const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | - | ||||||||||||||||||||||||
| 368 | if (!root.children.contains(host.toLower())) { | - | ||||||||||||||||||||||||
| 369 | if (pathElements.count() == 1 && !absolutePath.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 370 | return rootNode; | - | ||||||||||||||||||||||||
| 371 | QFileInfo info(host); | - | ||||||||||||||||||||||||
| 372 | if (!info.exists()) | - | ||||||||||||||||||||||||
| 373 | return rootNode; | - | ||||||||||||||||||||||||
| 374 | QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); | - | ||||||||||||||||||||||||
| 375 | p->addNode(rootNode, host,info); | - | ||||||||||||||||||||||||
| 376 | p->addVisibleFiles(rootNode, QStringList(host)); | - | ||||||||||||||||||||||||
| 377 | } | - | ||||||||||||||||||||||||
| 378 | r = rootNode->visibleLocation(host); | - | ||||||||||||||||||||||||
| 379 | r = translateVisibleLocation(rootNode, r); | - | ||||||||||||||||||||||||
| 380 | index = q->index(r, 0, QModelIndex()); | - | ||||||||||||||||||||||||
| 381 | pathElements.pop_front(); | - | ||||||||||||||||||||||||
| 382 | separator = QLatin1Char('\\'); | - | ||||||||||||||||||||||||
| 383 | elementPath = host; | - | ||||||||||||||||||||||||
| 384 | elementPath.append(separator); | - | ||||||||||||||||||||||||
| 385 | } else { | - | ||||||||||||||||||||||||
| 386 | if (!pathElements.at(0).contains(QLatin1Char(':'))) { | - | ||||||||||||||||||||||||
| 387 | QString rootPath = QDir(longPath).rootPath(); | - | ||||||||||||||||||||||||
| 388 | pathElements.prepend(rootPath); | - | ||||||||||||||||||||||||
| 389 | } | - | ||||||||||||||||||||||||
| 390 | if (pathElements.at(0).endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||||||||
| 391 | pathElements[0].chop(1); | - | ||||||||||||||||||||||||
| 392 | } | - | ||||||||||||||||||||||||
| 393 | #else | - | ||||||||||||||||||||||||
| 394 | // add the "/" item, since it is a valid path element on Unix | - | ||||||||||||||||||||||||
| 395 |     if (absolutePath[0] == QLatin1Char('/'))
  | 0 | ||||||||||||||||||||||||
| 396 |         pathElements.prepend(QLatin1String("/")); never executed:  pathElements.prepend(QLatin1String("/")); | 0 | ||||||||||||||||||||||||
| 397 | #endif | - | ||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||
| 399 | QFileSystemModelPrivate::QFileSystemNode *parent = node(index); | - | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 |     for (int i = 0; i < pathElements.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 402 | QString element = pathElements.at(i); | - | ||||||||||||||||||||||||
| 403 |         if (i != 0)
  | 0 | ||||||||||||||||||||||||
| 404 |             elementPath.append(separator); never executed:  elementPath.append(separator); | 0 | ||||||||||||||||||||||||
| 405 | elementPath.append(element); | - | ||||||||||||||||||||||||
| 406 |         if (i == pathElements.count() - 1)
  | 0 | ||||||||||||||||||||||||
| 407 |             elementPath.append(trailingSeparator); never executed:  elementPath.append(trailingSeparator); | 0 | ||||||||||||||||||||||||
| 408 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 409 | // On Windows, "filename " and "filename" are equivalent and | - | ||||||||||||||||||||||||
| 410 | // "filename . " and "filename" are equivalent | - | ||||||||||||||||||||||||
| 411 | // "filename......." and "filename" are equivalent Task #133928 | - | ||||||||||||||||||||||||
| 412 | // whereas "filename .txt" is still "filename .txt" | - | ||||||||||||||||||||||||
| 413 | // If after stripping the characters there is nothing left then we | - | ||||||||||||||||||||||||
| 414 | // just return the parent directory as it is assumed that the path | - | ||||||||||||||||||||||||
| 415 | // is referring to the parent | - | ||||||||||||||||||||||||
| 416 | while (element.endsWith(QLatin1Char('.')) || element.endsWith(QLatin1Char(' '))) | - | ||||||||||||||||||||||||
| 417 | element.chop(1); | - | ||||||||||||||||||||||||
| 418 | // Only filenames that can't possibly exist will be end up being empty | - | ||||||||||||||||||||||||
| 419 | if (element.isEmpty()) | - | ||||||||||||||||||||||||
| 420 | return parent; | - | ||||||||||||||||||||||||
| 421 | #endif | - | ||||||||||||||||||||||||
| 422 | bool alreadyExisted = parent->children.contains(element); | - | ||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||
| 424 | // we couldn't find the path element, we create a new node since we | - | ||||||||||||||||||||||||
| 425 | // _know_ that the path is valid | - | ||||||||||||||||||||||||
| 426 |         if (alreadyExisted) {
  | 0 | ||||||||||||||||||||||||
| 427 |             if ((parent->children.count() == 0)
  | 0 | ||||||||||||||||||||||||
| 428 |                 || (parent->caseSensitive()
  | 0 | ||||||||||||||||||||||||
| 429 |                     && parent->children.value(element)->fileName != element)
  | 0 | ||||||||||||||||||||||||
| 430 |                 || (!parent->caseSensitive()
  | 0 | ||||||||||||||||||||||||
| 431 |                     && parent->children.value(element)->fileName.toLower() != element.toLower()))
  | 0 | ||||||||||||||||||||||||
| 432 |                 alreadyExisted = false; never executed:  alreadyExisted = false; | 0 | ||||||||||||||||||||||||
| 433 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | QFileSystemModelPrivate::QFileSystemNode *node; | - | ||||||||||||||||||||||||
| 436 |         if (!alreadyExisted) {
  | 0 | ||||||||||||||||||||||||
| 437 | // Someone might call ::index("file://cookie/monster/doesn't/like/veggies"), | - | ||||||||||||||||||||||||
| 438 | // a path that doesn't exists, I.E. don't blindly create directories. | - | ||||||||||||||||||||||||
| 439 | QFileInfo info(elementPath); | - | ||||||||||||||||||||||||
| 440 |             if (!info.exists())
  | 0 | ||||||||||||||||||||||||
| 441 |                 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); never executed:  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 | ||||||||||||||||||||||||
| 442 | QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); | - | ||||||||||||||||||||||||
| 443 | node = p->addNode(parent, element,info); | - | ||||||||||||||||||||||||
| 444 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 445 | node->populate(fileInfoGatherer.getInfo(info)); | - | ||||||||||||||||||||||||
| 446 | #endif | - | ||||||||||||||||||||||||
| 447 |         } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 448 | node = parent->children.value(element); | - | ||||||||||||||||||||||||
| 449 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||
| 451 | Q_ASSERT(node); | - | ||||||||||||||||||||||||
| 452 |         if (!node->isVisible) {
  | 0 | ||||||||||||||||||||||||
| 453 | // It has been filtered out | - | ||||||||||||||||||||||||
| 454 |             if (alreadyExisted && node->hasInformation() && !fetch)
 
 
  | 0 | ||||||||||||||||||||||||
| 455 |                 return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); never executed:  return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); | 0 | ||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); | - | ||||||||||||||||||||||||
| 458 | p->addVisibleFiles(parent, QStringList(element)); | - | ||||||||||||||||||||||||
| 459 |             if (!p->bypassFilters.contains(node))
  | 0 | ||||||||||||||||||||||||
| 460 |                 p->bypassFilters[node] = 1; never executed:  p->bypassFilters[node] = 1; | 0 | ||||||||||||||||||||||||
| 461 | QString dir = q->filePath(this->index(parent)); | - | ||||||||||||||||||||||||
| 462 |             if (!node->hasInformation() && fetch) {
 
  | 0 | ||||||||||||||||||||||||
| 463 | Fetching f; | - | ||||||||||||||||||||||||
| 464 | f.dir = dir; | - | ||||||||||||||||||||||||
| 465 | f.file = element; | - | ||||||||||||||||||||||||
| 466 | f.node = node; | - | ||||||||||||||||||||||||
| 467 | p->toFetch.append(f); | - | ||||||||||||||||||||||||
| 468 | p->fetchingTimer.start(0, const_cast<QFileSystemModel*>(q)); | - | ||||||||||||||||||||||||
| 469 |             } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 470 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 471 | parent = node; | - | ||||||||||||||||||||||||
| 472 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||
| 474 |     return parent; never executed:  return parent; | 0 | ||||||||||||||||||||||||
| 475 | } | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | /*! | - | ||||||||||||||||||||||||
| 478 | \reimp | - | ||||||||||||||||||||||||
| 479 | */ | - | ||||||||||||||||||||||||
| 480 | void QFileSystemModel::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||||||||
| 481 | { | - | ||||||||||||||||||||||||
| 482 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 483 |     if (event->timerId() == d->fetchingTimer.timerId()) {
  | 0 | ||||||||||||||||||||||||
| 484 | d->fetchingTimer.stop(); | - | ||||||||||||||||||||||||
| 485 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 486 |         for (int i = 0; i < d->toFetch.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 487 | const QFileSystemModelPrivate::QFileSystemNode *node = d->toFetch.at(i).node; | - | ||||||||||||||||||||||||
| 488 |             if (!node->hasInformation()) {
  | 0 | ||||||||||||||||||||||||
| 489 | d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir, | - | ||||||||||||||||||||||||
| 490 | QStringList(d->toFetch.at(i).file)); | - | ||||||||||||||||||||||||
| 491 |             } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 492 | // qDebug("yah!, you saved a little gerbil soul"); | - | ||||||||||||||||||||||||
| 493 |             } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 494 | } | - | ||||||||||||||||||||||||
| 495 | #endif | - | ||||||||||||||||||||||||
| 496 | d->toFetch.clear(); | - | ||||||||||||||||||||||||
| 497 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 498 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | /*! | - | ||||||||||||||||||||||||
| 501 | Returns \c true if the model item \a index represents a directory; | - | ||||||||||||||||||||||||
| 502 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 503 | */ | - | ||||||||||||||||||||||||
| 504 | bool QFileSystemModel::isDir(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 505 | { | - | ||||||||||||||||||||||||
| 506 | // This function is for public usage only because it could create a file info | - | ||||||||||||||||||||||||
| 507 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 508 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 509 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 510 | QFileSystemModelPrivate::QFileSystemNode *n = d->node(index); | - | ||||||||||||||||||||||||
| 511 |     if (n->hasInformation())
  | 0 | ||||||||||||||||||||||||
| 512 |         return n->isDir(); never executed:  return n->isDir(); | 0 | ||||||||||||||||||||||||
| 513 |     return fileInfo(index).isDir(); never executed:  return fileInfo(index).isDir(); | 0 | ||||||||||||||||||||||||
| 514 | } | - | ||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||
| 516 | /*! | - | ||||||||||||||||||||||||
| 517 | Returns the size in bytes of \a index. If the file does not exist, 0 is returned. | - | ||||||||||||||||||||||||
| 518 | */ | - | ||||||||||||||||||||||||
| 519 | qint64 QFileSystemModel::size(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 520 | { | - | ||||||||||||||||||||||||
| 521 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 522 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 523 |         return 0; never executed:  return 0; | 0 | ||||||||||||||||||||||||
| 524 |     return d->node(index)->size(); never executed:  return d->node(index)->size(); | 0 | ||||||||||||||||||||||||
| 525 | } | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | /*! | - | ||||||||||||||||||||||||
| 528 | Returns the type of file \a index such as "Directory" or "JPEG file". | - | ||||||||||||||||||||||||
| 529 | */ | - | ||||||||||||||||||||||||
| 530 | QString QFileSystemModel::type(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 531 | { | - | ||||||||||||||||||||||||
| 532 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 533 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 534 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 535 |     return d->node(index)->type(); never executed:  return d->node(index)->type(); | 0 | ||||||||||||||||||||||||
| 536 | } | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | /*! | - | ||||||||||||||||||||||||
| 539 | Returns the date and time when \a index was last modified. | - | ||||||||||||||||||||||||
| 540 | */ | - | ||||||||||||||||||||||||
| 541 | QDateTime QFileSystemModel::lastModified(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 542 | { | - | ||||||||||||||||||||||||
| 543 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 544 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 545 |         return QDateTime(); never executed:  return QDateTime(); | 0 | ||||||||||||||||||||||||
| 546 |     return d->node(index)->lastModified(); never executed:  return d->node(index)->lastModified(); | 0 | ||||||||||||||||||||||||
| 547 | } | - | ||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||
| 549 | /*! | - | ||||||||||||||||||||||||
| 550 | \reimp | - | ||||||||||||||||||||||||
| 551 | */ | - | ||||||||||||||||||||||||
| 552 | QModelIndex QFileSystemModel::parent(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 553 | { | - | ||||||||||||||||||||||||
| 554 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 555 |     if (!d->indexValid(index))
  | 0 | ||||||||||||||||||||||||
| 556 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index); | - | ||||||||||||||||||||||||
| 559 | Q_ASSERT(indexNode != 0); | - | ||||||||||||||||||||||||
| 560 | QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent; | - | ||||||||||||||||||||||||
| 561 |     if (parentNode == 0 || parentNode == &d->root)
 
  | 0 | ||||||||||||||||||||||||
| 562 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||
| 564 | // get the parent's row | - | ||||||||||||||||||||||||
| 565 | QFileSystemModelPrivate::QFileSystemNode *grandParentNode = parentNode->parent; | - | ||||||||||||||||||||||||
| 566 | Q_ASSERT(grandParentNode->children.contains(parentNode->fileName)); | - | ||||||||||||||||||||||||
| 567 | int visualRow = d->translateVisibleLocation(grandParentNode, grandParentNode->visibleLocation(grandParentNode->children.value(parentNode->fileName)->fileName)); | - | ||||||||||||||||||||||||
| 568 |     if (visualRow == -1)
  | 0 | ||||||||||||||||||||||||
| 569 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 570 |     return createIndex(visualRow, 0, parentNode); never executed:  return createIndex(visualRow, 0, parentNode); | 0 | ||||||||||||||||||||||||
| 571 | } | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | /* | - | ||||||||||||||||||||||||
| 574 | \internal | - | ||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | return the index for node | - | ||||||||||||||||||||||||
| 577 | */ | - | ||||||||||||||||||||||||
| 578 | QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node, int column) const | - | ||||||||||||||||||||||||
| 579 | { | - | ||||||||||||||||||||||||
| 580 | Q_Q(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 581 |     QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0);
  | 0 | ||||||||||||||||||||||||
| 582 |     if (node == &root || !parentNode)
 
  | 0 | ||||||||||||||||||||||||
| 583 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 584 | - | |||||||||||||||||||||||||
| 585 | // get the parent's row | - | ||||||||||||||||||||||||
| 586 | Q_ASSERT(node); | - | ||||||||||||||||||||||||
| 587 |     if (!node->isVisible)
  | 0 | ||||||||||||||||||||||||
| 588 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName)); | - | ||||||||||||||||||||||||
| 591 |     return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node)); never executed:  return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node)); | 0 | ||||||||||||||||||||||||
| 592 | } | - | ||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||
| 594 | /*! | - | ||||||||||||||||||||||||
| 595 | \reimp | - | ||||||||||||||||||||||||
| 596 | */ | - | ||||||||||||||||||||||||
| 597 | bool QFileSystemModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 598 | { | - | ||||||||||||||||||||||||
| 599 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 600 |     if (parent.column() > 0)
  | 0 | ||||||||||||||||||||||||
| 601 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 |     if (!parent.isValid()) // drives
  | 0 | ||||||||||||||||||||||||
| 604 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - | ||||||||||||||||||||||||
| 607 | Q_ASSERT(indexNode); | - | ||||||||||||||||||||||||
| 608 |     return (indexNode->isDir()); never executed:  return (indexNode->isDir()); | 0 | ||||||||||||||||||||||||
| 609 | } | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | /*! | - | ||||||||||||||||||||||||
| 612 | \reimp | - | ||||||||||||||||||||||||
| 613 | */ | - | ||||||||||||||||||||||||
| 614 | bool QFileSystemModel::canFetchMore(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 615 | { | - | ||||||||||||||||||||||||
| 616 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 617 | const QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - | ||||||||||||||||||||||||
| 618 |     return (!indexNode->populatedChildren); never executed:  return (!indexNode->populatedChildren); | 0 | ||||||||||||||||||||||||
| 619 | } | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | /*! | - | ||||||||||||||||||||||||
| 622 | \reimp | - | ||||||||||||||||||||||||
| 623 | */ | - | ||||||||||||||||||||||||
| 624 | void QFileSystemModel::fetchMore(const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 625 | { | - | ||||||||||||||||||||||||
| 626 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 627 |     if (!d->setRootPath)
  | 0 | ||||||||||||||||||||||||
| 628 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 629 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(parent); | - | ||||||||||||||||||||||||
| 630 |     if (indexNode->populatedChildren)
  | 0 | ||||||||||||||||||||||||
| 631 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 632 | indexNode->populatedChildren = true; | - | ||||||||||||||||||||||||
| 633 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 634 | d->fileInfoGatherer.list(filePath(parent)); | - | ||||||||||||||||||||||||
| 635 | #endif | - | ||||||||||||||||||||||||
| 636 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | /*! | - | ||||||||||||||||||||||||
| 639 | \reimp | - | ||||||||||||||||||||||||
| 640 | */ | - | ||||||||||||||||||||||||
| 641 | int QFileSystemModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 642 | { | - | ||||||||||||||||||||||||
| 643 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 644 |     if (parent.column() > 0)
  | 0 | ||||||||||||||||||||||||
| 645 |         return 0; never executed:  return 0; | 0 | ||||||||||||||||||||||||
| 646 | - | |||||||||||||||||||||||||
| 647 |     if (!parent.isValid())
  | 0 | ||||||||||||||||||||||||
| 648 |         return d->root.visibleChildren.count(); never executed:  return d->root.visibleChildren.count(); | 0 | ||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||
| 650 | const QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); | - | ||||||||||||||||||||||||
| 651 |     return parentNode->visibleChildren.count(); never executed:  return parentNode->visibleChildren.count(); | 0 | ||||||||||||||||||||||||
| 652 | } | - | ||||||||||||||||||||||||
| 653 | - | |||||||||||||||||||||||||
| 654 | /*! | - | ||||||||||||||||||||||||
| 655 | \reimp | - | ||||||||||||||||||||||||
| 656 | */ | - | ||||||||||||||||||||||||
| 657 | int QFileSystemModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 658 | { | - | ||||||||||||||||||||||||
| 659 |     return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns; never executed:  return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns;
  | 0 | ||||||||||||||||||||||||
| 660 | } | - | ||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||
| 662 | /*! | - | ||||||||||||||||||||||||
| 663 | Returns the data stored under the given \a role for the item "My Computer". | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | \sa Qt::ItemDataRole | - | ||||||||||||||||||||||||
| 666 | */ | - | ||||||||||||||||||||||||
| 667 | QVariant QFileSystemModel::myComputer(int role) const | - | ||||||||||||||||||||||||
| 668 | { | - | ||||||||||||||||||||||||
| 669 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 670 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 671 | #endif | - | ||||||||||||||||||||||||
| 672 | switch (role) { | - | ||||||||||||||||||||||||
| 673 |     case Qt::DisplayRole: never executed:  case Qt::DisplayRole: | 0 | ||||||||||||||||||||||||
| 674 |         return QFileSystemModelPrivate::myComputer(); never executed:  return QFileSystemModelPrivate::myComputer(); | 0 | ||||||||||||||||||||||||
| 675 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 676 |     case Qt::DecorationRole: never executed:  case Qt::DecorationRole: | 0 | ||||||||||||||||||||||||
| 677 |         return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer); never executed:  return d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Computer); | 0 | ||||||||||||||||||||||||
| 678 | #endif | - | ||||||||||||||||||||||||
| 679 | } | - | ||||||||||||||||||||||||
| 680 |     return QVariant(); never executed:  return QVariant(); | 0 | ||||||||||||||||||||||||
| 681 | } | - | ||||||||||||||||||||||||
| 682 | - | |||||||||||||||||||||||||
| 683 | /*! | - | ||||||||||||||||||||||||
| 684 | \reimp | - | ||||||||||||||||||||||||
| 685 | */ | - | ||||||||||||||||||||||||
| 686 | QVariant QFileSystemModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||||||||
| 687 | { | - | ||||||||||||||||||||||||
| 688 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 689 |     if (!index.isValid() || index.model() != this)
 
  | 0 | ||||||||||||||||||||||||
| 690 |         return QVariant(); never executed:  return QVariant(); | 0 | ||||||||||||||||||||||||
| 691 | - | |||||||||||||||||||||||||
| 692 | switch (role) { | - | ||||||||||||||||||||||||
| 693 |     case Qt::EditRole: never executed:  case Qt::EditRole: | 0 | ||||||||||||||||||||||||
| 694 |     case Qt::DisplayRole: never executed:  case Qt::DisplayRole: | 0 | ||||||||||||||||||||||||
| 695 | switch (index.column()) { | - | ||||||||||||||||||||||||
| 696 |         case 0: return d->displayName(index); never executed:  return d->displayName(index);never executed:  case 0: | 0 | ||||||||||||||||||||||||
| 697 |         case 1: return d->size(index); never executed:  return d->size(index);never executed:  case 1: | 0 | ||||||||||||||||||||||||
| 698 |         case 2: return d->type(index); never executed:  return d->type(index);never executed:  case 2: | 0 | ||||||||||||||||||||||||
| 699 |         case 3: return d->time(index); never executed:  return d->time(index);never executed:  case 3: | 0 | ||||||||||||||||||||||||
| 700 |         default: never executed:  default: | 0 | ||||||||||||||||||||||||
| 701 | qWarning("data: invalid display value column %d", index.column()); | - | ||||||||||||||||||||||||
| 702 |             break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 703 | } | - | ||||||||||||||||||||||||
| 704 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 705 |     case FilePathRole: never executed:  case FilePathRole: | 0 | ||||||||||||||||||||||||
| 706 |         return filePath(index); never executed:  return filePath(index); | 0 | ||||||||||||||||||||||||
| 707 |     case FileNameRole: never executed:  case FileNameRole: | 0 | ||||||||||||||||||||||||
| 708 |         return d->name(index); never executed:  return d->name(index); | 0 | ||||||||||||||||||||||||
| 709 |     case Qt::DecorationRole: never executed:  case Qt::DecorationRole: | 0 | ||||||||||||||||||||||||
| 710 |         if (index.column() == 0) {
  | 0 | ||||||||||||||||||||||||
| 711 | QIcon icon = d->icon(index); | - | ||||||||||||||||||||||||
| 712 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 713 |             if (icon.isNull()) {
  | 0 | ||||||||||||||||||||||||
| 714 |                 if (d->node(index)->isDir())
  | 0 | ||||||||||||||||||||||||
| 715 |                     icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder); never executed:  icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::Folder); | 0 | ||||||||||||||||||||||||
| 716 | else | - | ||||||||||||||||||||||||
| 717 |                     icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File); never executed:  icon = d->fileInfoGatherer.iconProvider()->icon(QFileIconProvider::File); | 0 | ||||||||||||||||||||||||
| 718 | } | - | ||||||||||||||||||||||||
| 719 | #endif // QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 720 |             return icon; never executed:  return icon; | 0 | ||||||||||||||||||||||||
| 721 | } | - | ||||||||||||||||||||||||
| 722 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 723 |     case Qt::TextAlignmentRole: never executed:  case Qt::TextAlignmentRole: | 0 | ||||||||||||||||||||||||
| 724 |         if (index.column() == 1)
  | 0 | ||||||||||||||||||||||||
| 725 |             return Qt::AlignRight; never executed:  return Qt::AlignRight; | 0 | ||||||||||||||||||||||||
| 726 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 727 |     case FilePermissions: never executed:  case FilePermissions: | 0 | ||||||||||||||||||||||||
| 728 | int p = permissions(index); | - | ||||||||||||||||||||||||
| 729 |         return p; never executed:  return p; | 0 | ||||||||||||||||||||||||
| 730 | } | - | ||||||||||||||||||||||||
| 731 | - | |||||||||||||||||||||||||
| 732 |     return QVariant(); never executed:  return QVariant(); | 0 | ||||||||||||||||||||||||
| 733 | } | - | ||||||||||||||||||||||||
| 734 | - | |||||||||||||||||||||||||
| 735 | /*! | - | ||||||||||||||||||||||||
| 736 | \internal | - | ||||||||||||||||||||||||
| 737 | */ | - | ||||||||||||||||||||||||
| 738 | QString QFileSystemModelPrivate::size(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 739 | { | - | ||||||||||||||||||||||||
| 740 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 741 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 742 | const QFileSystemNode *n = node(index); | - | ||||||||||||||||||||||||
| 743 |     if (n->isDir()) {
  | 0 | ||||||||||||||||||||||||
| 744 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 745 | return QLatin1String("--"); | - | ||||||||||||||||||||||||
| 746 | #else | - | ||||||||||||||||||||||||
| 747 |         return QLatin1String(""); never executed:  return QLatin1String(""); | 0 | ||||||||||||||||||||||||
| 748 | #endif | - | ||||||||||||||||||||||||
| 749 | // Windows - "" | - | ||||||||||||||||||||||||
| 750 | // OS X - "--" | - | ||||||||||||||||||||||||
| 751 | // Konqueror - "4 KB" | - | ||||||||||||||||||||||||
| 752 | // Nautilus - "9 items" (the number of children) | - | ||||||||||||||||||||||||
| 753 | } | - | ||||||||||||||||||||||||
| 754 |     return size(n->size()); never executed:  return size(n->size()); | 0 | ||||||||||||||||||||||||
| 755 | } | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | QString QFileSystemModelPrivate::size(qint64 bytes) | - | ||||||||||||||||||||||||
| 758 | { | - | ||||||||||||||||||||||||
| 759 | // According to the Si standard KB is 1000 bytes, KiB is 1024 | - | ||||||||||||||||||||||||
| 760 | // but on windows sizes are calculated by dividing by 1024 so we do what they do. | - | ||||||||||||||||||||||||
| 761 | const qint64 kb = 1024; | - | ||||||||||||||||||||||||
| 762 | const qint64 mb = 1024 * kb; | - | ||||||||||||||||||||||||
| 763 | const qint64 gb = 1024 * mb; | - | ||||||||||||||||||||||||
| 764 | const qint64 tb = 1024 * gb; | - | ||||||||||||||||||||||||
| 765 |     if (bytes >= tb)
  | 0 | ||||||||||||||||||||||||
| 766 |         return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); never executed:  return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); | 0 | ||||||||||||||||||||||||
| 767 |     if (bytes >= gb)
  | 0 | ||||||||||||||||||||||||
| 768 |         return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); never executed:  return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); | 0 | ||||||||||||||||||||||||
| 769 |     if (bytes >= mb)
  | 0 | ||||||||||||||||||||||||
| 770 |         return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); never executed:  return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); | 0 | ||||||||||||||||||||||||
| 771 |     if (bytes >= kb)
  | 0 | ||||||||||||||||||||||||
| 772 |         return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); never executed:  return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); | 0 | ||||||||||||||||||||||||
| 773 |     return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes)); never executed:  return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes)); | 0 | ||||||||||||||||||||||||
| 774 | } | - | ||||||||||||||||||||||||
| 775 | - | |||||||||||||||||||||||||
| 776 | /*! | - | ||||||||||||||||||||||||
| 777 | \internal | - | ||||||||||||||||||||||||
| 778 | */ | - | ||||||||||||||||||||||||
| 779 | QString QFileSystemModelPrivate::time(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 780 | { | - | ||||||||||||||||||||||||
| 781 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 782 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 783 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||
| 784 |     return node(index)->lastModified().toString(Qt::SystemLocaleDate); never executed:  return node(index)->lastModified().toString(Qt::SystemLocaleDate); | 0 | ||||||||||||||||||||||||
| 785 | #else | - | ||||||||||||||||||||||||
| 786 | Q_UNUSED(index); | - | ||||||||||||||||||||||||
| 787 | return QString(); | - | ||||||||||||||||||||||||
| 788 | #endif | - | ||||||||||||||||||||||||
| 789 | } | - | ||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | /* | - | ||||||||||||||||||||||||
| 792 | \internal | - | ||||||||||||||||||||||||
| 793 | */ | - | ||||||||||||||||||||||||
| 794 | QString QFileSystemModelPrivate::type(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 795 | { | - | ||||||||||||||||||||||||
| 796 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 797 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 798 |     return node(index)->type(); never executed:  return node(index)->type(); | 0 | ||||||||||||||||||||||||
| 799 | } | - | ||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||
| 801 | /*! | - | ||||||||||||||||||||||||
| 802 | \internal | - | ||||||||||||||||||||||||
| 803 | */ | - | ||||||||||||||||||||||||
| 804 | QString QFileSystemModelPrivate::name(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 805 | { | - | ||||||||||||||||||||||||
| 806 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 807 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 808 | QFileSystemNode *dirNode = node(index); | - | ||||||||||||||||||||||||
| 809 | if ( | - | ||||||||||||||||||||||||
| 810 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 811 |         fileInfoGatherer.resolveSymlinks() &&
  | 0 | ||||||||||||||||||||||||
| 812 | #endif | - | ||||||||||||||||||||||||
| 813 |         !resolvedSymLinks.isEmpty() && dirNode->isSymLink(/* ignoreNtfsSymLinks = */ true)) {
 
  | 0 | ||||||||||||||||||||||||
| 814 | QString fullPath = QDir::fromNativeSeparators(filePath(index)); | - | ||||||||||||||||||||||||
| 815 |         return resolvedSymLinks.value(fullPath, dirNode->fileName); never executed:  return resolvedSymLinks.value(fullPath, dirNode->fileName); | 0 | ||||||||||||||||||||||||
| 816 | } | - | ||||||||||||||||||||||||
| 817 |     return dirNode->fileName; never executed:  return dirNode->fileName; | 0 | ||||||||||||||||||||||||
| 818 | } | - | ||||||||||||||||||||||||
| 819 | - | |||||||||||||||||||||||||
| 820 | /*! | - | ||||||||||||||||||||||||
| 821 | \internal | - | ||||||||||||||||||||||||
| 822 | */ | - | ||||||||||||||||||||||||
| 823 | QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 824 | { | - | ||||||||||||||||||||||||
| 825 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 826 | QFileSystemNode *dirNode = node(index); | - | ||||||||||||||||||||||||
| 827 | if (!dirNode->volumeName.isNull()) | - | ||||||||||||||||||||||||
| 828 | return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')'); | - | ||||||||||||||||||||||||
| 829 | #endif | - | ||||||||||||||||||||||||
| 830 |     return name(index); never executed:  return name(index); | 0 | ||||||||||||||||||||||||
| 831 | } | - | ||||||||||||||||||||||||
| 832 | - | |||||||||||||||||||||||||
| 833 | /*! | - | ||||||||||||||||||||||||
| 834 | \internal | - | ||||||||||||||||||||||||
| 835 | */ | - | ||||||||||||||||||||||||
| 836 | QIcon QFileSystemModelPrivate::icon(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 837 | { | - | ||||||||||||||||||||||||
| 838 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 839 |         return QIcon(); never executed:  return QIcon(); | 0 | ||||||||||||||||||||||||
| 840 |     return node(index)->icon(); never executed:  return node(index)->icon(); | 0 | ||||||||||||||||||||||||
| 841 | } | - | ||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||
| 843 | /*! | - | ||||||||||||||||||||||||
| 844 | \reimp | - | ||||||||||||||||||||||||
| 845 | */ | - | ||||||||||||||||||||||||
| 846 | bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, int role) | - | ||||||||||||||||||||||||
| 847 | { | - | ||||||||||||||||||||||||
| 848 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 849 |     if (!idx.isValid()
  | 0 | ||||||||||||||||||||||||
| 850 |         || idx.column() != 0
  | 0 | ||||||||||||||||||||||||
| 851 |         || role != Qt::EditRole
  | 0 | ||||||||||||||||||||||||
| 852 |         || (flags(idx) & Qt::ItemIsEditable) == 0) {
  | 0 | ||||||||||||||||||||||||
| 853 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 854 | } | - | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | QString newName = value.toString(); | - | ||||||||||||||||||||||||
| 857 | QString oldName = idx.data().toString(); | - | ||||||||||||||||||||||||
| 858 |     if (newName == idx.data().toString())
  | 0 | ||||||||||||||||||||||||
| 859 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 860 | - | |||||||||||||||||||||||||
| 861 | const QString parentPath = filePath(parent(idx)); | - | ||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 |     if (newName.isEmpty()
  | 0 | ||||||||||||||||||||||||
| 864 |         || QDir::toNativeSeparators(newName).contains(QDir::separator())
  | 0 | ||||||||||||||||||||||||
| 865 |         || !QDir(parentPath).rename(oldName, newName)) {
  | 0 | ||||||||||||||||||||||||
| 866 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||||||||
| 867 | QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"), | - | ||||||||||||||||||||||||
| 868 | QFileSystemModel::tr("<b>The name \"%1\" can not be used.</b><p>Try using another name, with fewer characters or no punctuations marks.") | - | ||||||||||||||||||||||||
| 869 | .arg(newName), | - | ||||||||||||||||||||||||
| 870 | QMessageBox::Ok); | - | ||||||||||||||||||||||||
| 871 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||||||||||||||
| 872 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 873 | } else { | - | ||||||||||||||||||||||||
| 874 | /* | - | ||||||||||||||||||||||||
| 875 | *After re-naming something we don't want the selection to change* | - | ||||||||||||||||||||||||
| 876 | - can't remove rows and later insert | - | ||||||||||||||||||||||||
| 877 | - can't quickly remove and insert | - | ||||||||||||||||||||||||
| 878 | - index pointer can't change because treeview doesn't use persistant index's | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | - if this get any more complicated think of changing it to just | - | ||||||||||||||||||||||||
| 881 | use layoutChanged | - | ||||||||||||||||||||||||
| 882 | */ | - | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(idx); | - | ||||||||||||||||||||||||
| 885 | QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent; | - | ||||||||||||||||||||||||
| 886 | int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName); | - | ||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | parentNode->visibleChildren.removeAt(visibleLocation); | - | ||||||||||||||||||||||||
| 889 | QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName); | - | ||||||||||||||||||||||||
| 890 | parentNode->children[newName] = oldValue; | - | ||||||||||||||||||||||||
| 891 | oldValue->fileName = newName; | - | ||||||||||||||||||||||||
| 892 | oldValue->parent = parentNode; | - | ||||||||||||||||||||||||
| 893 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 894 | oldValue->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName))); | - | ||||||||||||||||||||||||
| 895 | #endif | - | ||||||||||||||||||||||||
| 896 | oldValue->isVisible = true; | - | ||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||
| 898 | parentNode->children.remove(oldName); | - | ||||||||||||||||||||||||
| 899 | parentNode->visibleChildren.insert(visibleLocation, newName); | - | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | d->delayedSort(); | - | ||||||||||||||||||||||||
| 902 | emit fileRenamed(parentPath, oldName, newName); | - | ||||||||||||||||||||||||
| 903 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 904 |     return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 905 | } | - | ||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||
| 907 | /*! | - | ||||||||||||||||||||||||
| 908 | \reimp | - | ||||||||||||||||||||||||
| 909 | */ | - | ||||||||||||||||||||||||
| 910 | QVariant QFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||||||||
| 911 | { | - | ||||||||||||||||||||||||
| 912 | switch (role) { | - | ||||||||||||||||||||||||
| 913 |     case Qt::DecorationRole: never executed:  case Qt::DecorationRole: | 0 | ||||||||||||||||||||||||
| 914 |         if (section == 0) {
  | 0 | ||||||||||||||||||||||||
| 915 | // ### TODO oh man this is ugly and doesn't even work all the way! | - | ||||||||||||||||||||||||
| 916 | // it is still 2 pixels off | - | ||||||||||||||||||||||||
| 917 | QImage pixmap(16, 1, QImage::Format_Mono); | - | ||||||||||||||||||||||||
| 918 | pixmap.fill(0); | - | ||||||||||||||||||||||||
| 919 | pixmap.setAlphaChannel(pixmap.createAlphaMask()); | - | ||||||||||||||||||||||||
| 920 |             return pixmap; never executed:  return pixmap; | 0 | ||||||||||||||||||||||||
| 921 | } | - | ||||||||||||||||||||||||
| 922 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 923 |     case Qt::TextAlignmentRole: never executed:  case Qt::TextAlignmentRole: | 0 | ||||||||||||||||||||||||
| 924 |         return Qt::AlignLeft; never executed:  return Qt::AlignLeft; | 0 | ||||||||||||||||||||||||
| 925 | } | - | ||||||||||||||||||||||||
| 926 | - | |||||||||||||||||||||||||
| 927 |     if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
 
  | 0 | ||||||||||||||||||||||||
| 928 |         return QAbstractItemModel::headerData(section, orientation, role); never executed:  return QAbstractItemModel::headerData(section, orientation, role); | 0 | ||||||||||||||||||||||||
| 929 | - | |||||||||||||||||||||||||
| 930 | QString returnValue; | - | ||||||||||||||||||||||||
| 931 | switch (section) { | - | ||||||||||||||||||||||||
| 932 |     case 0: returnValue = tr("Name"); never executed:  case 0: | 0 | ||||||||||||||||||||||||
| 933 |             break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 934 |     case 1: returnValue = tr("Size"); never executed:  case 1: | 0 | ||||||||||||||||||||||||
| 935 |             break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 936 |     case 2: returnValue = never executed:  case 2: | 0 | ||||||||||||||||||||||||
| 937 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 938 | tr("Kind", "Match OS X Finder"); | - | ||||||||||||||||||||||||
| 939 | #else | - | ||||||||||||||||||||||||
| 940 | tr("Type", "All other platforms"); | - | ||||||||||||||||||||||||
| 941 | #endif | - | ||||||||||||||||||||||||
| 942 |            break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 943 | // Windows - Type | - | ||||||||||||||||||||||||
| 944 | // OS X - Kind | - | ||||||||||||||||||||||||
| 945 | // Konqueror - File Type | - | ||||||||||||||||||||||||
| 946 | // Nautilus - Type | - | ||||||||||||||||||||||||
| 947 |     case 3: returnValue = tr("Date Modified"); never executed:  case 3: | 0 | ||||||||||||||||||||||||
| 948 |             break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 949 |     default: return QVariant(); never executed:  return QVariant();never executed:  default: | 0 | ||||||||||||||||||||||||
| 950 | } | - | ||||||||||||||||||||||||
| 951 |     return returnValue; never executed:  return returnValue; | 0 | ||||||||||||||||||||||||
| 952 | } | - | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | /*! | - | ||||||||||||||||||||||||
| 955 | \reimp | - | ||||||||||||||||||||||||
| 956 | */ | - | ||||||||||||||||||||||||
| 957 | Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 958 | { | - | ||||||||||||||||||||||||
| 959 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 960 | Qt::ItemFlags flags = QAbstractItemModel::flags(index); | - | ||||||||||||||||||||||||
| 961 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 962 |         return flags; never executed:  return flags; | 0 | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | QFileSystemModelPrivate::QFileSystemNode *indexNode = d->node(index); | - | ||||||||||||||||||||||||
| 965 |     if (d->nameFilterDisables && !d->passNameFilters(indexNode)) {
 
  | 0 | ||||||||||||||||||||||||
| 966 | flags &= ~Qt::ItemIsEnabled; | - | ||||||||||||||||||||||||
| 967 | // ### TODO you shouldn't be able to set this as the current item, task 119433 | - | ||||||||||||||||||||||||
| 968 |         return flags; never executed:  return flags; | 0 | ||||||||||||||||||||||||
| 969 | } | - | ||||||||||||||||||||||||
| 970 | - | |||||||||||||||||||||||||
| 971 | flags |= Qt::ItemIsDragEnabled; | - | ||||||||||||||||||||||||
| 972 |     if (d->readOnly)
  | 0 | ||||||||||||||||||||||||
| 973 |         return flags; never executed:  return flags; | 0 | ||||||||||||||||||||||||
| 974 |     if ((index.column() == 0) && indexNode->permissions() & QFile::WriteUser) {
 
  | 0 | ||||||||||||||||||||||||
| 975 | flags |= Qt::ItemIsEditable; | - | ||||||||||||||||||||||||
| 976 |         if (indexNode->isDir())
  | 0 | ||||||||||||||||||||||||
| 977 |             flags |= Qt::ItemIsDropEnabled; never executed:  flags |= Qt::ItemIsDropEnabled; | 0 | ||||||||||||||||||||||||
| 978 | else | - | ||||||||||||||||||||||||
| 979 |             flags |= Qt::ItemNeverHasChildren; never executed:  flags |= Qt::ItemNeverHasChildren; | 0 | ||||||||||||||||||||||||
| 980 | } | - | ||||||||||||||||||||||||
| 981 |     return flags; never executed:  return flags; | 0 | ||||||||||||||||||||||||
| 982 | } | - | ||||||||||||||||||||||||
| 983 | - | |||||||||||||||||||||||||
| 984 | /*! | - | ||||||||||||||||||||||||
| 985 | \internal | - | ||||||||||||||||||||||||
| 986 | */ | - | ||||||||||||||||||||||||
| 987 | void QFileSystemModelPrivate::_q_performDelayedSort() | - | ||||||||||||||||||||||||
| 988 | { | - | ||||||||||||||||||||||||
| 989 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 990 | q->sort(sortColumn, sortOrder); | - | ||||||||||||||||||||||||
| 991 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 992 | - | |||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | /* | - | ||||||||||||||||||||||||
| 995 | \internal | - | ||||||||||||||||||||||||
| 996 | Helper functor used by sort() | - | ||||||||||||||||||||||||
| 997 | */ | - | ||||||||||||||||||||||||
| 998 | class QFileSystemModelSorter | - | ||||||||||||||||||||||||
| 999 | { | - | ||||||||||||||||||||||||
| 1000 | public: | - | ||||||||||||||||||||||||
| 1001 | inline QFileSystemModelSorter(int column) : sortColumn(column) | - | ||||||||||||||||||||||||
| 1002 | { | - | ||||||||||||||||||||||||
| 1003 | naturalCompare.setNumericMode(true); | - | ||||||||||||||||||||||||
| 1004 | naturalCompare.setCaseSensitivity(Qt::CaseInsensitive); | - | ||||||||||||||||||||||||
| 1005 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1006 | - | |||||||||||||||||||||||||
| 1007 | bool compareNodes(const QFileSystemModelPrivate::QFileSystemNode *l, | - | ||||||||||||||||||||||||
| 1008 | const QFileSystemModelPrivate::QFileSystemNode *r) const | - | ||||||||||||||||||||||||
| 1009 | { | - | ||||||||||||||||||||||||
| 1010 | switch (sortColumn) { | - | ||||||||||||||||||||||||
| 1011 |         case 0: { never executed:  case 0: | 0 | ||||||||||||||||||||||||
| 1012 | #ifndef Q_OS_MAC | - | ||||||||||||||||||||||||
| 1013 | // place directories before files | - | ||||||||||||||||||||||||
| 1014 | bool left = l->isDir(); | - | ||||||||||||||||||||||||
| 1015 | bool right = r->isDir(); | - | ||||||||||||||||||||||||
| 1016 |             if (left ^ right)
  | 0 | ||||||||||||||||||||||||
| 1017 |                 return left; never executed:  return left; | 0 | ||||||||||||||||||||||||
| 1018 | #endif | - | ||||||||||||||||||||||||
| 1019 |             return naturalCompare.compare(l->fileName, r->fileName) < 0; never executed:  return naturalCompare.compare(l->fileName, r->fileName) < 0; | 0 | ||||||||||||||||||||||||
| 1020 | } | - | ||||||||||||||||||||||||
| 1021 |         case 1: never executed:  case 1: | 0 | ||||||||||||||||||||||||
| 1022 | { | - | ||||||||||||||||||||||||
| 1023 | // Directories go first | - | ||||||||||||||||||||||||
| 1024 | bool left = l->isDir(); | - | ||||||||||||||||||||||||
| 1025 | bool right = r->isDir(); | - | ||||||||||||||||||||||||
| 1026 |             if (left ^ right)
  | 0 | ||||||||||||||||||||||||
| 1027 |                 return left; never executed:  return left; | 0 | ||||||||||||||||||||||||
| 1028 | - | |||||||||||||||||||||||||
| 1029 | qint64 sizeDifference = l->size() - r->size(); | - | ||||||||||||||||||||||||
| 1030 |             if (sizeDifference == 0)
  | 0 | ||||||||||||||||||||||||
| 1031 |                 return naturalCompare.compare(l->fileName, r->fileName) < 0; never executed:  return naturalCompare.compare(l->fileName, r->fileName) < 0; | 0 | ||||||||||||||||||||||||
| 1032 | - | |||||||||||||||||||||||||
| 1033 |             return sizeDifference < 0; never executed:  return sizeDifference < 0; | 0 | ||||||||||||||||||||||||
| 1034 | } | - | ||||||||||||||||||||||||
| 1035 |         case 2: never executed:  case 2: | 0 | ||||||||||||||||||||||||
| 1036 | { | - | ||||||||||||||||||||||||
| 1037 | int compare = naturalCompare.compare(l->type(), r->type()); | - | ||||||||||||||||||||||||
| 1038 |             if (compare == 0)
  | 0 | ||||||||||||||||||||||||
| 1039 |                 return naturalCompare.compare(l->fileName, r->fileName) < 0; never executed:  return naturalCompare.compare(l->fileName, r->fileName) < 0; | 0 | ||||||||||||||||||||||||
| 1040 | - | |||||||||||||||||||||||||
| 1041 |             return compare < 0; never executed:  return compare < 0; | 0 | ||||||||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||||||||
| 1043 |         case 3: never executed:  case 3: | 0 | ||||||||||||||||||||||||
| 1044 | { | - | ||||||||||||||||||||||||
| 1045 |             if (l->lastModified() == r->lastModified())
  | 0 | ||||||||||||||||||||||||
| 1046 |                 return naturalCompare.compare(l->fileName, r->fileName) < 0; never executed:  return naturalCompare.compare(l->fileName, r->fileName) < 0; | 0 | ||||||||||||||||||||||||
| 1047 | - | |||||||||||||||||||||||||
| 1048 |             return l->lastModified() < r->lastModified(); never executed:  return l->lastModified() < r->lastModified(); | 0 | ||||||||||||||||||||||||
| 1049 | } | - | ||||||||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||||||||
| 1051 | Q_ASSERT(false); | - | ||||||||||||||||||||||||
| 1052 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1053 | } | - | ||||||||||||||||||||||||
| 1054 | - | |||||||||||||||||||||||||
| 1055 | bool operator()(const QFileSystemModelPrivate::QFileSystemNode *l, | - | ||||||||||||||||||||||||
| 1056 | const QFileSystemModelPrivate::QFileSystemNode *r) const | - | ||||||||||||||||||||||||
| 1057 | { | - | ||||||||||||||||||||||||
| 1058 |         return compareNodes(l, r); never executed:  return compareNodes(l, r); | 0 | ||||||||||||||||||||||||
| 1059 | } | - | ||||||||||||||||||||||||
| 1060 | - | |||||||||||||||||||||||||
| 1061 | - | |||||||||||||||||||||||||
| 1062 | private: | - | ||||||||||||||||||||||||
| 1063 | QCollator naturalCompare; | - | ||||||||||||||||||||||||
| 1064 | int sortColumn; | - | ||||||||||||||||||||||||
| 1065 | }; | - | ||||||||||||||||||||||||
| 1066 | - | |||||||||||||||||||||||||
| 1067 | /* | - | ||||||||||||||||||||||||
| 1068 | \internal | - | ||||||||||||||||||||||||
| 1069 | - | |||||||||||||||||||||||||
| 1070 | Sort all of the children of parent | - | ||||||||||||||||||||||||
| 1071 | */ | - | ||||||||||||||||||||||||
| 1072 | void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1073 | { | - | ||||||||||||||||||||||||
| 1074 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1075 | QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent); | - | ||||||||||||||||||||||||
| 1076 |     if (indexNode->children.count() == 0)
  | 0 | ||||||||||||||||||||||||
| 1077 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | QVector<QFileSystemModelPrivate::QFileSystemNode*> values; | - | ||||||||||||||||||||||||
| 1080 | QHash<QString, QFileSystemNode *>::const_iterator iterator; | - | ||||||||||||||||||||||||
| 1081 |     for(iterator = indexNode->children.constBegin() ; iterator != indexNode->children.constEnd() ; ++iterator) {
  | 0 | ||||||||||||||||||||||||
| 1082 |         if (filtersAcceptsNode(iterator.value())) {
  | 0 | ||||||||||||||||||||||||
| 1083 | values.append(iterator.value()); | - | ||||||||||||||||||||||||
| 1084 |         } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1085 | iterator.value()->isVisible = false; | - | ||||||||||||||||||||||||
| 1086 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1087 | } | - | ||||||||||||||||||||||||
| 1088 | QFileSystemModelSorter ms(column); | - | ||||||||||||||||||||||||
| 1089 | std::sort(values.begin(), values.end(), ms); | - | ||||||||||||||||||||||||
| 1090 | // First update the new visible list | - | ||||||||||||||||||||||||
| 1091 | indexNode->visibleChildren.clear(); | - | ||||||||||||||||||||||||
| 1092 | //No more dirty item we reset our internal dirty index | - | ||||||||||||||||||||||||
| 1093 | indexNode->dirtyChildrenIndex = -1; | - | ||||||||||||||||||||||||
| 1094 | const int numValues = values.count(); | - | ||||||||||||||||||||||||
| 1095 | indexNode->visibleChildren.reserve(numValues); | - | ||||||||||||||||||||||||
| 1096 |     for (int i = 0; i < numValues; ++i) {
  | 0 | ||||||||||||||||||||||||
| 1097 | indexNode->visibleChildren.append(values.at(i)->fileName); | - | ||||||||||||||||||||||||
| 1098 | values.at(i)->isVisible = true; | - | ||||||||||||||||||||||||
| 1099 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1100 | - | |||||||||||||||||||||||||
| 1101 |     if (!disableRecursiveSort) {
  | 0 | ||||||||||||||||||||||||
| 1102 |         for (int i = 0; i < q->rowCount(parent); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1103 | const QModelIndex childIndex = q->index(i, 0, parent); | - | ||||||||||||||||||||||||
| 1104 | QFileSystemModelPrivate::QFileSystemNode *indexNode = node(childIndex); | - | ||||||||||||||||||||||||
| 1105 | //Only do a recursive sort on visible nodes | - | ||||||||||||||||||||||||
| 1106 |             if (indexNode->isVisible)
  | 0 | ||||||||||||||||||||||||
| 1107 |                 sortChildren(column, childIndex); never executed:  sortChildren(column, childIndex); | 0 | ||||||||||||||||||||||||
| 1108 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1109 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1110 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | /*! | - | ||||||||||||||||||||||||
| 1113 | \reimp | - | ||||||||||||||||||||||||
| 1114 | */ | - | ||||||||||||||||||||||||
| 1115 | void QFileSystemModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||
| 1116 | { | - | ||||||||||||||||||||||||
| 1117 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1118 |     if (d->sortOrder == order && d->sortColumn == column && !d->forceSort)
 
 
  | 0 | ||||||||||||||||||||||||
| 1119 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1120 | - | |||||||||||||||||||||||||
| 1121 | emit layoutAboutToBeChanged(); | - | ||||||||||||||||||||||||
| 1122 | QModelIndexList oldList = persistentIndexList(); | - | ||||||||||||||||||||||||
| 1123 | QVector<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > oldNodes; | - | ||||||||||||||||||||||||
| 1124 | const int nodeCount = oldList.count(); | - | ||||||||||||||||||||||||
| 1125 | oldNodes.reserve(nodeCount); | - | ||||||||||||||||||||||||
| 1126 |     for (int i = 0; i < nodeCount; ++i) {
  | 0 | ||||||||||||||||||||||||
| 1127 | const QModelIndex &oldNode = oldList.at(i); | - | ||||||||||||||||||||||||
| 1128 | QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldNode), oldNode.column()); | - | ||||||||||||||||||||||||
| 1129 | oldNodes.append(pair); | - | ||||||||||||||||||||||||
| 1130 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1131 | - | |||||||||||||||||||||||||
| 1132 |     if (!(d->sortColumn == column && d->sortOrder != order && !d->forceSort)) {
 
 
  | 0 | ||||||||||||||||||||||||
| 1133 | //we sort only from where we are, don't need to sort all the model | - | ||||||||||||||||||||||||
| 1134 | d->sortChildren(column, index(rootPath())); | - | ||||||||||||||||||||||||
| 1135 | d->sortColumn = column; | - | ||||||||||||||||||||||||
| 1136 | d->forceSort = false; | - | ||||||||||||||||||||||||
| 1137 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1138 | d->sortOrder = order; | - | ||||||||||||||||||||||||
| 1139 | - | |||||||||||||||||||||||||
| 1140 | QModelIndexList newList; | - | ||||||||||||||||||||||||
| 1141 | const int numOldNodes = oldNodes.size(); | - | ||||||||||||||||||||||||
| 1142 | newList.reserve(numOldNodes); | - | ||||||||||||||||||||||||
| 1143 |     for (int i = 0; i < numOldNodes; ++i) {
  | 0 | ||||||||||||||||||||||||
| 1144 | const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i); | - | ||||||||||||||||||||||||
| 1145 | newList.append(d->index(oldNode.first, oldNode.second)); | - | ||||||||||||||||||||||||
| 1146 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1147 | changePersistentIndexList(oldList, newList); | - | ||||||||||||||||||||||||
| 1148 | emit layoutChanged(); | - | ||||||||||||||||||||||||
| 1149 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1150 | - | |||||||||||||||||||||||||
| 1151 | /*! | - | ||||||||||||||||||||||||
| 1152 | Returns a list of MIME types that can be used to describe a list of items | - | ||||||||||||||||||||||||
| 1153 | in the model. | - | ||||||||||||||||||||||||
| 1154 | */ | - | ||||||||||||||||||||||||
| 1155 | QStringList QFileSystemModel::mimeTypes() const | - | ||||||||||||||||||||||||
| 1156 | { | - | ||||||||||||||||||||||||
| 1157 |     return QStringList(QLatin1String("text/uri-list")); never executed:  return QStringList(QLatin1String("text/uri-list")); | 0 | ||||||||||||||||||||||||
| 1158 | } | - | ||||||||||||||||||||||||
| 1159 | - | |||||||||||||||||||||||||
| 1160 | /*! | - | ||||||||||||||||||||||||
| 1161 | Returns an object that contains a serialized description of the specified | - | ||||||||||||||||||||||||
| 1162 | \a indexes. The format used to describe the items corresponding to the | - | ||||||||||||||||||||||||
| 1163 | indexes is obtained from the mimeTypes() function. | - | ||||||||||||||||||||||||
| 1164 | - | |||||||||||||||||||||||||
| 1165 | If the list of indexes is empty, 0 is returned rather than a serialized | - | ||||||||||||||||||||||||
| 1166 | empty list. | - | ||||||||||||||||||||||||
| 1167 | */ | - | ||||||||||||||||||||||||
| 1168 | QMimeData *QFileSystemModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||||||||
| 1169 | { | - | ||||||||||||||||||||||||
| 1170 | QList<QUrl> urls; | - | ||||||||||||||||||||||||
| 1171 | QList<QModelIndex>::const_iterator it = indexes.begin(); | - | ||||||||||||||||||||||||
| 1172 |     for (; it != indexes.end(); ++it)
  | 0 | ||||||||||||||||||||||||
| 1173 |         if ((*it).column() == 0)
  | 0 | ||||||||||||||||||||||||
| 1174 |             urls << QUrl::fromLocalFile(filePath(*it)); never executed:  urls << QUrl::fromLocalFile(filePath(*it)); | 0 | ||||||||||||||||||||||||
| 1175 | QMimeData *data = new QMimeData(); | - | ||||||||||||||||||||||||
| 1176 | data->setUrls(urls); | - | ||||||||||||||||||||||||
| 1177 |     return data; never executed:  return data; | 0 | ||||||||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||
| 1180 | /*! | - | ||||||||||||||||||||||||
| 1181 | Handles the \a data supplied by a drag and drop operation that ended with | - | ||||||||||||||||||||||||
| 1182 | the given \a action over the row in the model specified by the \a row and | - | ||||||||||||||||||||||||
| 1183 | \a column and by the \a parent index. | - | ||||||||||||||||||||||||
| 1184 | - | |||||||||||||||||||||||||
| 1185 | \sa supportedDropActions() | - | ||||||||||||||||||||||||
| 1186 | */ | - | ||||||||||||||||||||||||
| 1187 | bool QFileSystemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
| 1188 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 1189 | { | - | ||||||||||||||||||||||||
| 1190 | Q_UNUSED(row); | - | ||||||||||||||||||||||||
| 1191 | Q_UNUSED(column); | - | ||||||||||||||||||||||||
| 1192 |     if (!parent.isValid() || isReadOnly())
 
  | 0 | ||||||||||||||||||||||||
| 1193 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1194 | - | |||||||||||||||||||||||||
| 1195 | bool success = true; | - | ||||||||||||||||||||||||
| 1196 | QString to = filePath(parent) + QDir::separator(); | - | ||||||||||||||||||||||||
| 1197 | - | |||||||||||||||||||||||||
| 1198 | QList<QUrl> urls = data->urls(); | - | ||||||||||||||||||||||||
| 1199 | QList<QUrl>::const_iterator it = urls.constBegin(); | - | ||||||||||||||||||||||||
| 1200 | - | |||||||||||||||||||||||||
| 1201 | switch (action) { | - | ||||||||||||||||||||||||
| 1202 |     case Qt::CopyAction: never executed:  case Qt::CopyAction: | 0 | ||||||||||||||||||||||||
| 1203 |         for (; it != urls.constEnd(); ++it) {
  | 0 | ||||||||||||||||||||||||
| 1204 | QString path = (*it).toLocalFile(); | - | ||||||||||||||||||||||||
| 1205 |             success = QFile::copy(path, to + QFileInfo(path).fileName()) && success;
 
  | 0 | ||||||||||||||||||||||||
| 1206 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1207 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 1208 |     case Qt::LinkAction: never executed:  case Qt::LinkAction: | 0 | ||||||||||||||||||||||||
| 1209 |         for (; it != urls.constEnd(); ++it) {
  | 0 | ||||||||||||||||||||||||
| 1210 | QString path = (*it).toLocalFile(); | - | ||||||||||||||||||||||||
| 1211 |             success = QFile::link(path, to + QFileInfo(path).fileName()) && success;
 
  | 0 | ||||||||||||||||||||||||
| 1212 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1213 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 1214 |     case Qt::MoveAction: never executed:  case Qt::MoveAction: | 0 | ||||||||||||||||||||||||
| 1215 |         for (; it != urls.constEnd(); ++it) {
  | 0 | ||||||||||||||||||||||||
| 1216 | QString path = (*it).toLocalFile(); | - | ||||||||||||||||||||||||
| 1217 |             success = QFile::rename(path, to + QFileInfo(path).fileName()) && success;
 
  | 0 | ||||||||||||||||||||||||
| 1218 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1219 |         break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 1220 |     default: never executed:  default: | 0 | ||||||||||||||||||||||||
| 1221 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1222 | } | - | ||||||||||||||||||||||||
| 1223 | - | |||||||||||||||||||||||||
| 1224 |     return success; never executed:  return success; | 0 | ||||||||||||||||||||||||
| 1225 | } | - | ||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | /*! | - | ||||||||||||||||||||||||
| 1228 | \reimp | - | ||||||||||||||||||||||||
| 1229 | */ | - | ||||||||||||||||||||||||
| 1230 | Qt::DropActions QFileSystemModel::supportedDropActions() const | - | ||||||||||||||||||||||||
| 1231 | { | - | ||||||||||||||||||||||||
| 1232 |     return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; never executed:  return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; | 0 | ||||||||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | /*! | - | ||||||||||||||||||||||||
| 1236 | Returns the path of the item stored in the model under the | - | ||||||||||||||||||||||||
| 1237 | \a index given. | - | ||||||||||||||||||||||||
| 1238 | */ | - | ||||||||||||||||||||||||
| 1239 | QString QFileSystemModel::filePath(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1240 | { | - | ||||||||||||||||||||||||
| 1241 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1242 | QString fullPath = d->filePath(index); | - | ||||||||||||||||||||||||
| 1243 | QFileSystemModelPrivate::QFileSystemNode *dirNode = d->node(index); | - | ||||||||||||||||||||||||
| 1244 |     if (dirNode->isSymLink()
  | 0 | ||||||||||||||||||||||||
| 1245 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1246 |         && d->fileInfoGatherer.resolveSymlinks()
  | 0 | ||||||||||||||||||||||||
| 1247 | #endif | - | ||||||||||||||||||||||||
| 1248 |         && d->resolvedSymLinks.contains(fullPath)
  | 0 | ||||||||||||||||||||||||
| 1249 |         && dirNode->isDir()) {
  | 0 | ||||||||||||||||||||||||
| 1250 | QFileInfo resolvedInfo(fullPath); | - | ||||||||||||||||||||||||
| 1251 | resolvedInfo = resolvedInfo.canonicalFilePath(); | - | ||||||||||||||||||||||||
| 1252 |         if (resolvedInfo.exists())
  | 0 | ||||||||||||||||||||||||
| 1253 |             return resolvedInfo.filePath(); never executed:  return resolvedInfo.filePath(); | 0 | ||||||||||||||||||||||||
| 1254 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1255 |     return fullPath; never executed:  return fullPath; | 0 | ||||||||||||||||||||||||
| 1256 | } | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | QString QFileSystemModelPrivate::filePath(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1259 | { | - | ||||||||||||||||||||||||
| 1260 | Q_Q(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1261 | Q_UNUSED(q); | - | ||||||||||||||||||||||||
| 1262 |     if (!index.isValid())
  | 0 | ||||||||||||||||||||||||
| 1263 |         return QString(); never executed:  return QString(); | 0 | ||||||||||||||||||||||||
| 1264 | Q_ASSERT(index.model() == q); | - | ||||||||||||||||||||||||
| 1265 | - | |||||||||||||||||||||||||
| 1266 | QStringList path; | - | ||||||||||||||||||||||||
| 1267 | QModelIndex idx = index; | - | ||||||||||||||||||||||||
| 1268 |     while (idx.isValid()) {
  | 0 | ||||||||||||||||||||||||
| 1269 | QFileSystemModelPrivate::QFileSystemNode *dirNode = node(idx); | - | ||||||||||||||||||||||||
| 1270 |         if (dirNode)
  | 0 | ||||||||||||||||||||||||
| 1271 |             path.prepend(dirNode->fileName); never executed:  path.prepend(dirNode->fileName); | 0 | ||||||||||||||||||||||||
| 1272 | idx = idx.parent(); | - | ||||||||||||||||||||||||
| 1273 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1274 | QString fullPath = QDir::fromNativeSeparators(path.join(QDir::separator())); | - | ||||||||||||||||||||||||
| 1275 | #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1276 |     if ((fullPath.length() > 2) && fullPath[0] == QLatin1Char('/') && fullPath[1] == QLatin1Char('/'))
 
 
  | 0 | ||||||||||||||||||||||||
| 1277 |         fullPath = fullPath.mid(1); never executed:  fullPath = fullPath.mid(1); | 0 | ||||||||||||||||||||||||
| 1278 | #endif | - | ||||||||||||||||||||||||
| 1279 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 1280 | if (fullPath.length() == 2 && fullPath.endsWith(QLatin1Char(':'))) | - | ||||||||||||||||||||||||
| 1281 | fullPath.append(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 1282 | #endif | - | ||||||||||||||||||||||||
| 1283 |     return fullPath; never executed:  return fullPath; | 0 | ||||||||||||||||||||||||
| 1284 | } | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | /*! | - | ||||||||||||||||||||||||
| 1287 | Create a directory with the \a name in the \a parent model index. | - | ||||||||||||||||||||||||
| 1288 | */ | - | ||||||||||||||||||||||||
| 1289 | QModelIndex QFileSystemModel::mkdir(const QModelIndex &parent, const QString &name) | - | ||||||||||||||||||||||||
| 1290 | { | - | ||||||||||||||||||||||||
| 1291 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1292 |     if (!parent.isValid())
  | 0 | ||||||||||||||||||||||||
| 1293 |         return parent; never executed:  return parent; | 0 | ||||||||||||||||||||||||
| 1294 | - | |||||||||||||||||||||||||
| 1295 | QDir dir(filePath(parent)); | - | ||||||||||||||||||||||||
| 1296 |     if (!dir.mkdir(name))
  | 0 | ||||||||||||||||||||||||
| 1297 |         return QModelIndex(); never executed:  return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 1298 | QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); | - | ||||||||||||||||||||||||
| 1299 | d->addNode(parentNode, name, QFileInfo()); | - | ||||||||||||||||||||||||
| 1300 | Q_ASSERT(parentNode->children.contains(name)); | - | ||||||||||||||||||||||||
| 1301 | QFileSystemModelPrivate::QFileSystemNode *node = parentNode->children[name]; | - | ||||||||||||||||||||||||
| 1302 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1303 | node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name))); | - | ||||||||||||||||||||||||
| 1304 | #endif | - | ||||||||||||||||||||||||
| 1305 | d->addVisibleFiles(parentNode, QStringList(name)); | - | ||||||||||||||||||||||||
| 1306 |     return d->index(node); never executed:  return d->index(node); | 0 | ||||||||||||||||||||||||
| 1307 | } | - | ||||||||||||||||||||||||
| 1308 | - | |||||||||||||||||||||||||
| 1309 | /*! | - | ||||||||||||||||||||||||
| 1310 | Returns the complete OR-ed together combination of QFile::Permission for the \a index. | - | ||||||||||||||||||||||||
| 1311 | */ | - | ||||||||||||||||||||||||
| 1312 | QFile::Permissions QFileSystemModel::permissions(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1313 | { | - | ||||||||||||||||||||||||
| 1314 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1315 |     return d->node(index)->permissions(); never executed:  return d->node(index)->permissions(); | 0 | ||||||||||||||||||||||||
| 1316 | } | - | ||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||
| 1318 | /*! | - | ||||||||||||||||||||||||
| 1319 | Sets the directory that is being watched by the model to \a newPath by | - | ||||||||||||||||||||||||
| 1320 | installing a \l{QFileSystemWatcher}{file system watcher} on it. Any | - | ||||||||||||||||||||||||
| 1321 | changes to files and directories within this directory will be | - | ||||||||||||||||||||||||
| 1322 | reflected in the model. | - | ||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||
| 1324 | If the path is changed, the rootPathChanged() signal will be emitted. | - | ||||||||||||||||||||||||
| 1325 | - | |||||||||||||||||||||||||
| 1326 | \note This function does not change the structure of the model or | - | ||||||||||||||||||||||||
| 1327 | modify the data available to views. In other words, the "root" of | - | ||||||||||||||||||||||||
| 1328 | the model is \e not changed to include only files and directories | - | ||||||||||||||||||||||||
| 1329 | within the directory specified by \a newPath in the file system. | - | ||||||||||||||||||||||||
| 1330 | */ | - | ||||||||||||||||||||||||
| 1331 | QModelIndex QFileSystemModel::setRootPath(const QString &newPath) | - | ||||||||||||||||||||||||
| 1332 | { | - | ||||||||||||||||||||||||
| 1333 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1334 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 1335 | #ifdef Q_OS_WIN32 | - | ||||||||||||||||||||||||
| 1336 | QString longNewPath = qt_GetLongPathName(newPath); | - | ||||||||||||||||||||||||
| 1337 | #else | - | ||||||||||||||||||||||||
| 1338 | QString longNewPath = QDir::fromNativeSeparators(newPath); | - | ||||||||||||||||||||||||
| 1339 | #endif | - | ||||||||||||||||||||||||
| 1340 | #else | - | ||||||||||||||||||||||||
| 1341 | QString longNewPath = newPath; | - | ||||||||||||||||||||||||
| 1342 | #endif | - | ||||||||||||||||||||||||
| 1343 | QDir newPathDir(longNewPath); | - | ||||||||||||||||||||||||
| 1344 | //we remove .. and . from the given path if exist | - | ||||||||||||||||||||||||
| 1345 |     if (!newPath.isEmpty()) {
  | 0 | ||||||||||||||||||||||||
| 1346 | longNewPath = QDir::cleanPath(longNewPath); | - | ||||||||||||||||||||||||
| 1347 | newPathDir.setPath(longNewPath); | - | ||||||||||||||||||||||||
| 1348 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1349 | - | |||||||||||||||||||||||||
| 1350 | d->setRootPath = true; | - | ||||||||||||||||||||||||
| 1351 | - | |||||||||||||||||||||||||
| 1352 | //user don't ask for the root path ("") but the conversion failed | - | ||||||||||||||||||||||||
| 1353 |     if (!newPath.isEmpty() && longNewPath.isEmpty())
 
  | 0 | ||||||||||||||||||||||||
| 1354 |         return d->index(rootPath()); never executed:  return d->index(rootPath()); | 0 | ||||||||||||||||||||||||
| 1355 | - | |||||||||||||||||||||||||
| 1356 |     if (d->rootDir.path() == longNewPath)
  | 0 | ||||||||||||||||||||||||
| 1357 |         return d->index(rootPath()); never executed:  return d->index(rootPath()); | 0 | ||||||||||||||||||||||||
| 1358 | - | |||||||||||||||||||||||||
| 1359 |     bool showDrives = (longNewPath.isEmpty() || longNewPath == d->myComputer());
 
  | 0 | ||||||||||||||||||||||||
| 1360 |     if (!showDrives && !newPathDir.exists())
 
  | 0 | ||||||||||||||||||||||||
| 1361 |         return d->index(rootPath()); never executed:  return d->index(rootPath()); | 0 | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | //We remove the watcher on the previous path | - | ||||||||||||||||||||||||
| 1364 |     if (!rootPath().isEmpty() && rootPath() != QLatin1String(".")) {
 
  | 0 | ||||||||||||||||||||||||
| 1365 | //This remove the watcher for the old rootPath | - | ||||||||||||||||||||||||
| 1366 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1367 | d->fileInfoGatherer.removePath(rootPath()); | - | ||||||||||||||||||||||||
| 1368 | #endif | - | ||||||||||||||||||||||||
| 1369 | //This line "marks" the node as dirty, so the next fetchMore | - | ||||||||||||||||||||||||
| 1370 | //call on the path will ask the gatherer to install a watcher again | - | ||||||||||||||||||||||||
| 1371 | //But it doesn't re-fetch everything | - | ||||||||||||||||||||||||
| 1372 | d->node(rootPath())->populatedChildren = false; | - | ||||||||||||||||||||||||
| 1373 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1374 | - | |||||||||||||||||||||||||
| 1375 | // We have a new valid root path | - | ||||||||||||||||||||||||
| 1376 | d->rootDir = newPathDir; | - | ||||||||||||||||||||||||
| 1377 | QModelIndex newRootIndex; | - | ||||||||||||||||||||||||
| 1378 |     if (showDrives) {
  | 0 | ||||||||||||||||||||||||
| 1379 | // otherwise dir will become '.' | - | ||||||||||||||||||||||||
| 1380 | d->rootDir.setPath(QLatin1String("")); | - | ||||||||||||||||||||||||
| 1381 |     } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1382 | newRootIndex = d->index(newPathDir.path()); | - | ||||||||||||||||||||||||
| 1383 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1384 | fetchMore(newRootIndex); | - | ||||||||||||||||||||||||
| 1385 | emit rootPathChanged(longNewPath); | - | ||||||||||||||||||||||||
| 1386 | d->forceSort = true; | - | ||||||||||||||||||||||||
| 1387 | d->delayedSort(); | - | ||||||||||||||||||||||||
| 1388 |     return newRootIndex; never executed:  return newRootIndex; | 0 | ||||||||||||||||||||||||
| 1389 | } | - | ||||||||||||||||||||||||
| 1390 | - | |||||||||||||||||||||||||
| 1391 | /*! | - | ||||||||||||||||||||||||
| 1392 | The currently set root path | - | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | \sa rootDirectory() | - | ||||||||||||||||||||||||
| 1395 | */ | - | ||||||||||||||||||||||||
| 1396 | QString QFileSystemModel::rootPath() const | - | ||||||||||||||||||||||||
| 1397 | { | - | ||||||||||||||||||||||||
| 1398 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1399 |     return d->rootDir.path(); never executed:  return d->rootDir.path(); | 0 | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | /*! | - | ||||||||||||||||||||||||
| 1403 | The currently set directory | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | \sa rootPath() | - | ||||||||||||||||||||||||
| 1406 | */ | - | ||||||||||||||||||||||||
| 1407 | QDir QFileSystemModel::rootDirectory() const | - | ||||||||||||||||||||||||
| 1408 | { | - | ||||||||||||||||||||||||
| 1409 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1410 | QDir dir(d->rootDir); | - | ||||||||||||||||||||||||
| 1411 | dir.setNameFilters(nameFilters()); | - | ||||||||||||||||||||||||
| 1412 | dir.setFilter(filter()); | - | ||||||||||||||||||||||||
| 1413 |     return dir; never executed:  return dir; | 0 | ||||||||||||||||||||||||
| 1414 | } | - | ||||||||||||||||||||||||
| 1415 | - | |||||||||||||||||||||||||
| 1416 | /*! | - | ||||||||||||||||||||||||
| 1417 | Sets the \a provider of file icons for the directory model. | - | ||||||||||||||||||||||||
| 1418 | */ | - | ||||||||||||||||||||||||
| 1419 | void QFileSystemModel::setIconProvider(QFileIconProvider *provider) | - | ||||||||||||||||||||||||
| 1420 | { | - | ||||||||||||||||||||||||
| 1421 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1422 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1423 | d->fileInfoGatherer.setIconProvider(provider); | - | ||||||||||||||||||||||||
| 1424 | #endif | - | ||||||||||||||||||||||||
| 1425 | d->root.updateIcon(provider, QString()); | - | ||||||||||||||||||||||||
| 1426 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1427 | - | |||||||||||||||||||||||||
| 1428 | /*! | - | ||||||||||||||||||||||||
| 1429 | Returns the file icon provider for this directory model. | - | ||||||||||||||||||||||||
| 1430 | */ | - | ||||||||||||||||||||||||
| 1431 | QFileIconProvider *QFileSystemModel::iconProvider() const | - | ||||||||||||||||||||||||
| 1432 | { | - | ||||||||||||||||||||||||
| 1433 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1434 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1435 |     return d->fileInfoGatherer.iconProvider(); never executed:  return d->fileInfoGatherer.iconProvider(); | 0 | ||||||||||||||||||||||||
| 1436 | #else | - | ||||||||||||||||||||||||
| 1437 | return 0; | - | ||||||||||||||||||||||||
| 1438 | #endif | - | ||||||||||||||||||||||||
| 1439 | } | - | ||||||||||||||||||||||||
| 1440 | - | |||||||||||||||||||||||||
| 1441 | /*! | - | ||||||||||||||||||||||||
| 1442 | Sets the directory model's filter to that specified by \a filters. | - | ||||||||||||||||||||||||
| 1443 | - | |||||||||||||||||||||||||
| 1444 | Note that the filter you set should always include the QDir::AllDirs enum value, | - | ||||||||||||||||||||||||
| 1445 | otherwise QFileSystemModel won't be able to read the directory structure. | - | ||||||||||||||||||||||||
| 1446 | - | |||||||||||||||||||||||||
| 1447 | \sa QDir::Filters | - | ||||||||||||||||||||||||
| 1448 | */ | - | ||||||||||||||||||||||||
| 1449 | void QFileSystemModel::setFilter(QDir::Filters filters) | - | ||||||||||||||||||||||||
| 1450 | { | - | ||||||||||||||||||||||||
| 1451 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1452 |     if (d->filters == filters)
  | 0 | ||||||||||||||||||||||||
| 1453 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1454 | d->filters = filters; | - | ||||||||||||||||||||||||
| 1455 | // CaseSensitivity might have changed | - | ||||||||||||||||||||||||
| 1456 | setNameFilters(nameFilters()); | - | ||||||||||||||||||||||||
| 1457 | d->forceSort = true; | - | ||||||||||||||||||||||||
| 1458 | d->delayedSort(); | - | ||||||||||||||||||||||||
| 1459 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1460 | - | |||||||||||||||||||||||||
| 1461 | /*! | - | ||||||||||||||||||||||||
| 1462 | Returns the filter specified for the directory model. | - | ||||||||||||||||||||||||
| 1463 | - | |||||||||||||||||||||||||
| 1464 | If a filter has not been set, the default filter is QDir::AllEntries | | - | ||||||||||||||||||||||||
| 1465 | QDir::NoDotAndDotDot | QDir::AllDirs. | - | ||||||||||||||||||||||||
| 1466 | - | |||||||||||||||||||||||||
| 1467 | \sa QDir::Filters | - | ||||||||||||||||||||||||
| 1468 | */ | - | ||||||||||||||||||||||||
| 1469 | QDir::Filters QFileSystemModel::filter() const | - | ||||||||||||||||||||||||
| 1470 | { | - | ||||||||||||||||||||||||
| 1471 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1472 |     return d->filters; never executed:  return d->filters; | 0 | ||||||||||||||||||||||||
| 1473 | } | - | ||||||||||||||||||||||||
| 1474 | - | |||||||||||||||||||||||||
| 1475 | /*! | - | ||||||||||||||||||||||||
| 1476 | \property QFileSystemModel::resolveSymlinks | - | ||||||||||||||||||||||||
| 1477 | \brief Whether the directory model should resolve symbolic links | - | ||||||||||||||||||||||||
| 1478 | - | |||||||||||||||||||||||||
| 1479 | This is only relevant on Windows. | - | ||||||||||||||||||||||||
| 1480 | - | |||||||||||||||||||||||||
| 1481 | By default, this property is \c true. | - | ||||||||||||||||||||||||
| 1482 | */ | - | ||||||||||||||||||||||||
| 1483 | void QFileSystemModel::setResolveSymlinks(bool enable) | - | ||||||||||||||||||||||||
| 1484 | { | - | ||||||||||||||||||||||||
| 1485 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1486 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1487 | d->fileInfoGatherer.setResolveSymlinks(enable); | - | ||||||||||||||||||||||||
| 1488 | #else | - | ||||||||||||||||||||||||
| 1489 | Q_UNUSED(enable) | - | ||||||||||||||||||||||||
| 1490 | #endif | - | ||||||||||||||||||||||||
| 1491 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | bool QFileSystemModel::resolveSymlinks() const | - | ||||||||||||||||||||||||
| 1494 | { | - | ||||||||||||||||||||||||
| 1495 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1496 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1497 |     return d->fileInfoGatherer.resolveSymlinks(); never executed:  return d->fileInfoGatherer.resolveSymlinks(); | 0 | ||||||||||||||||||||||||
| 1498 | #else | - | ||||||||||||||||||||||||
| 1499 | return false; | - | ||||||||||||||||||||||||
| 1500 | #endif | - | ||||||||||||||||||||||||
| 1501 | } | - | ||||||||||||||||||||||||
| 1502 | - | |||||||||||||||||||||||||
| 1503 | /*! | - | ||||||||||||||||||||||||
| 1504 | \property QFileSystemModel::readOnly | - | ||||||||||||||||||||||||
| 1505 | \brief Whether the directory model allows writing to the file system | - | ||||||||||||||||||||||||
| 1506 | - | |||||||||||||||||||||||||
| 1507 | If this property is set to false, the directory model will allow renaming, copying | - | ||||||||||||||||||||||||
| 1508 | and deleting of files and directories. | - | ||||||||||||||||||||||||
| 1509 | - | |||||||||||||||||||||||||
| 1510 | This property is \c true by default | - | ||||||||||||||||||||||||
| 1511 | */ | - | ||||||||||||||||||||||||
| 1512 | void QFileSystemModel::setReadOnly(bool enable) | - | ||||||||||||||||||||||||
| 1513 | { | - | ||||||||||||||||||||||||
| 1514 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1515 | d->readOnly = enable; | - | ||||||||||||||||||||||||
| 1516 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1517 | - | |||||||||||||||||||||||||
| 1518 | bool QFileSystemModel::isReadOnly() const | - | ||||||||||||||||||||||||
| 1519 | { | - | ||||||||||||||||||||||||
| 1520 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1521 |     return d->readOnly; never executed:  return d->readOnly; | 0 | ||||||||||||||||||||||||
| 1522 | } | - | ||||||||||||||||||||||||
| 1523 | - | |||||||||||||||||||||||||
| 1524 | /*! | - | ||||||||||||||||||||||||
| 1525 | \property QFileSystemModel::nameFilterDisables | - | ||||||||||||||||||||||||
| 1526 | \brief Whether files that don't pass the name filter are hidden or disabled | - | ||||||||||||||||||||||||
| 1527 | - | |||||||||||||||||||||||||
| 1528 | This property is \c true by default | - | ||||||||||||||||||||||||
| 1529 | */ | - | ||||||||||||||||||||||||
| 1530 | void QFileSystemModel::setNameFilterDisables(bool enable) | - | ||||||||||||||||||||||||
| 1531 | { | - | ||||||||||||||||||||||||
| 1532 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1533 |     if (d->nameFilterDisables == enable)
  | 0 | ||||||||||||||||||||||||
| 1534 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1535 | d->nameFilterDisables = enable; | - | ||||||||||||||||||||||||
| 1536 | d->forceSort = true; | - | ||||||||||||||||||||||||
| 1537 | d->delayedSort(); | - | ||||||||||||||||||||||||
| 1538 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1539 | - | |||||||||||||||||||||||||
| 1540 | bool QFileSystemModel::nameFilterDisables() const | - | ||||||||||||||||||||||||
| 1541 | { | - | ||||||||||||||||||||||||
| 1542 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1543 |     return d->nameFilterDisables; never executed:  return d->nameFilterDisables; | 0 | ||||||||||||||||||||||||
| 1544 | } | - | ||||||||||||||||||||||||
| 1545 | - | |||||||||||||||||||||||||
| 1546 | /*! | - | ||||||||||||||||||||||||
| 1547 | Sets the name \a filters to apply against the existing files. | - | ||||||||||||||||||||||||
| 1548 | */ | - | ||||||||||||||||||||||||
| 1549 | void QFileSystemModel::setNameFilters(const QStringList &filters) | - | ||||||||||||||||||||||||
| 1550 | { | - | ||||||||||||||||||||||||
| 1551 | // Prep the regexp's ahead of time | - | ||||||||||||||||||||||||
| 1552 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 1553 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1554 | - | |||||||||||||||||||||||||
| 1555 |     if (!d->bypassFilters.isEmpty()) {
  | 0 | ||||||||||||||||||||||||
| 1556 | // update the bypass filter to only bypass the stuff that must be kept around | - | ||||||||||||||||||||||||
| 1557 | d->bypassFilters.clear(); | - | ||||||||||||||||||||||||
| 1558 | // We guarantee that rootPath will stick around | - | ||||||||||||||||||||||||
| 1559 | QPersistentModelIndex root(index(rootPath())); | - | ||||||||||||||||||||||||
| 1560 | QModelIndexList persistantList = persistentIndexList(); | - | ||||||||||||||||||||||||
| 1561 |         for (int i = 0; i < persistantList.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1562 | QFileSystemModelPrivate::QFileSystemNode *node; | - | ||||||||||||||||||||||||
| 1563 | node = d->node(persistantList.at(i)); | - | ||||||||||||||||||||||||
| 1564 |             while (node) {
  | 0 | ||||||||||||||||||||||||
| 1565 |                 if (d->bypassFilters.contains(node))
  | 0 | ||||||||||||||||||||||||
| 1566 |                     break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 1567 |                 if (node->isDir())
  | 0 | ||||||||||||||||||||||||
| 1568 |                     d->bypassFilters[node] = true; never executed:  d->bypassFilters[node] = true; | 0 | ||||||||||||||||||||||||
| 1569 | node = node->parent; | - | ||||||||||||||||||||||||
| 1570 |             } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1571 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1572 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1573 | - | |||||||||||||||||||||||||
| 1574 | d->nameFilters.clear(); | - | ||||||||||||||||||||||||
| 1575 | const Qt::CaseSensitivity caseSensitive = | - | ||||||||||||||||||||||||
| 1576 |         (filter() & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive;
  | 0 | ||||||||||||||||||||||||
| 1577 |     for (int i = 0; i < filters.size(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1578 | d->nameFilters << QRegExp(filters.at(i), caseSensitive, QRegExp::Wildcard); | - | ||||||||||||||||||||||||
| 1579 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1580 | d->forceSort = true; | - | ||||||||||||||||||||||||
| 1581 | d->delayedSort(); | - | ||||||||||||||||||||||||
| 1582 | #endif | - | ||||||||||||||||||||||||
| 1583 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1584 | - | |||||||||||||||||||||||||
| 1585 | /*! | - | ||||||||||||||||||||||||
| 1586 | Returns a list of filters applied to the names in the model. | - | ||||||||||||||||||||||||
| 1587 | */ | - | ||||||||||||||||||||||||
| 1588 | QStringList QFileSystemModel::nameFilters() const | - | ||||||||||||||||||||||||
| 1589 | { | - | ||||||||||||||||||||||||
| 1590 | Q_D(const QFileSystemModel); | - | ||||||||||||||||||||||||
| 1591 | QStringList filters; | - | ||||||||||||||||||||||||
| 1592 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 1593 | const int numNameFilters = d->nameFilters.size(); | - | ||||||||||||||||||||||||
| 1594 | filters.reserve(numNameFilters); | - | ||||||||||||||||||||||||
| 1595 |     for (int i = 0; i < numNameFilters; ++i) {
  | 0 | ||||||||||||||||||||||||
| 1596 | filters << d->nameFilters.at(i).pattern(); | - | ||||||||||||||||||||||||
| 1597 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1598 | #endif | - | ||||||||||||||||||||||||
| 1599 |     return filters; never executed:  return filters; | 0 | ||||||||||||||||||||||||
| 1600 | } | - | ||||||||||||||||||||||||
| 1601 | - | |||||||||||||||||||||||||
| 1602 | /*! | - | ||||||||||||||||||||||||
| 1603 | \reimp | - | ||||||||||||||||||||||||
| 1604 | */ | - | ||||||||||||||||||||||||
| 1605 | bool QFileSystemModel::event(QEvent *event) | - | ||||||||||||||||||||||||
| 1606 | { | - | ||||||||||||||||||||||||
| 1607 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1608 | Q_D(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1609 |     if (event->type() == QEvent::LanguageChange) {
  | 0 | ||||||||||||||||||||||||
| 1610 | d->root.retranslateStrings(d->fileInfoGatherer.iconProvider(), QString()); | - | ||||||||||||||||||||||||
| 1611 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 1612 | } | - | ||||||||||||||||||||||||
| 1613 | #endif | - | ||||||||||||||||||||||||
| 1614 |     return QAbstractItemModel::event(event); never executed:  return QAbstractItemModel::event(event); | 0 | ||||||||||||||||||||||||
| 1615 | } | - | ||||||||||||||||||||||||
| 1616 | - | |||||||||||||||||||||||||
| 1617 | bool QFileSystemModel::rmdir(const QModelIndex &aindex) | - | ||||||||||||||||||||||||
| 1618 | { | - | ||||||||||||||||||||||||
| 1619 | QString path = filePath(aindex); | - | ||||||||||||||||||||||||
| 1620 | const bool success = QDir().rmdir(path); | - | ||||||||||||||||||||||||
| 1621 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1622 |     if (success) {
  | 0 | ||||||||||||||||||||||||
| 1623 | QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); | - | ||||||||||||||||||||||||
| 1624 | d->fileInfoGatherer.removePath(path); | - | ||||||||||||||||||||||||
| 1625 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1626 | #endif | - | ||||||||||||||||||||||||
| 1627 |     return success; never executed:  return success; | 0 | ||||||||||||||||||||||||
| 1628 | } | - | ||||||||||||||||||||||||
| 1629 | - | |||||||||||||||||||||||||
| 1630 | /*! | - | ||||||||||||||||||||||||
| 1631 | \internal | - | ||||||||||||||||||||||||
| 1632 | - | |||||||||||||||||||||||||
| 1633 | Performed quick listing and see if any files have been added or removed, | - | ||||||||||||||||||||||||
| 1634 | then fetch more information on visible files. | - | ||||||||||||||||||||||||
| 1635 | */ | - | ||||||||||||||||||||||||
| 1636 | void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, const QStringList &files) | - | ||||||||||||||||||||||||
| 1637 | { | - | ||||||||||||||||||||||||
| 1638 | QFileSystemModelPrivate::QFileSystemNode *parentNode = node(directory, false); | - | ||||||||||||||||||||||||
| 1639 |     if (parentNode->children.count() == 0)
  | 0 | ||||||||||||||||||||||||
| 1640 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1641 | QStringList toRemove; | - | ||||||||||||||||||||||||
| 1642 | QStringList newFiles = files; | - | ||||||||||||||||||||||||
| 1643 | std::sort(newFiles.begin(), newFiles.end()); | - | ||||||||||||||||||||||||
| 1644 | QHash<QString, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin(); | - | ||||||||||||||||||||||||
| 1645 |     while (i != parentNode->children.constEnd()) {
  | 0 | ||||||||||||||||||||||||
| 1646 | QStringList::iterator iterator = std::lower_bound(newFiles.begin(), newFiles.end(), i.value()->fileName); | - | ||||||||||||||||||||||||
| 1647 |         if ((iterator == newFiles.end()) || (i.value()->fileName < *iterator))
 
  | 0 | ||||||||||||||||||||||||
| 1648 |             toRemove.append(i.value()->fileName); never executed:  toRemove.append(i.value()->fileName); | 0 | ||||||||||||||||||||||||
| 1649 | - | |||||||||||||||||||||||||
| 1650 | ++i; | - | ||||||||||||||||||||||||
| 1651 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1652 |     for (int i = 0 ; i < toRemove.count() ; ++i )
  | 0 | ||||||||||||||||||||||||
| 1653 |         removeNode(parentNode, toRemove[i]); never executed:  removeNode(parentNode, toRemove[i]); | 0 | ||||||||||||||||||||||||
| 1654 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1655 | - | |||||||||||||||||||||||||
| 1656 | /*! | - | ||||||||||||||||||||||||
| 1657 | \internal | - | ||||||||||||||||||||||||
| 1658 | - | |||||||||||||||||||||||||
| 1659 | Adds a new file to the children of parentNode | - | ||||||||||||||||||||||||
| 1660 | - | |||||||||||||||||||||||||
| 1661 | *WARNING* this will change the count of children | - | ||||||||||||||||||||||||
| 1662 | */ | - | ||||||||||||||||||||||||
| 1663 | QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo& info) | - | ||||||||||||||||||||||||
| 1664 | { | - | ||||||||||||||||||||||||
| 1665 | // In the common case, itemLocation == count() so check there first | - | ||||||||||||||||||||||||
| 1666 | QFileSystemModelPrivate::QFileSystemNode *node = new QFileSystemModelPrivate::QFileSystemNode(fileName, parentNode); | - | ||||||||||||||||||||||||
| 1667 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1668 | node->populate(info); | - | ||||||||||||||||||||||||
| 1669 | #else | - | ||||||||||||||||||||||||
| 1670 | Q_UNUSED(info) | - | ||||||||||||||||||||||||
| 1671 | #endif | - | ||||||||||||||||||||||||
| 1672 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 1673 | //The parentNode is "" so we are listing the drives | - | ||||||||||||||||||||||||
| 1674 | if (parentNode->fileName.isEmpty()) { | - | ||||||||||||||||||||||||
| 1675 | wchar_t name[MAX_PATH + 1]; | - | ||||||||||||||||||||||||
| 1676 | //GetVolumeInformation requires to add trailing backslash | - | ||||||||||||||||||||||||
| 1677 | const QString nodeName = fileName + QLatin1String("\\"); | - | ||||||||||||||||||||||||
| 1678 | BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()), | - | ||||||||||||||||||||||||
| 1679 | name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0); | - | ||||||||||||||||||||||||
| 1680 | if (success && name[0]) | - | ||||||||||||||||||||||||
| 1681 | node->volumeName = QString::fromWCharArray(name); | - | ||||||||||||||||||||||||
| 1682 | } | - | ||||||||||||||||||||||||
| 1683 | #endif | - | ||||||||||||||||||||||||
| 1684 | parentNode->children.insert(fileName, node); | - | ||||||||||||||||||||||||
| 1685 |     return node; never executed:  return node; | 0 | ||||||||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||||||||
| 1687 | - | |||||||||||||||||||||||||
| 1688 | /*! | - | ||||||||||||||||||||||||
| 1689 | \internal | - | ||||||||||||||||||||||||
| 1690 | - | |||||||||||||||||||||||||
| 1691 | File at parentNode->children(itemLocation) has been removed, remove from the lists | - | ||||||||||||||||||||||||
| 1692 | and emit signals if necessary | - | ||||||||||||||||||||||||
| 1693 | - | |||||||||||||||||||||||||
| 1694 | *WARNING* this will change the count of children and could change visibleChildren | - | ||||||||||||||||||||||||
| 1695 | */ | - | ||||||||||||||||||||||||
| 1696 | void QFileSystemModelPrivate::removeNode(QFileSystemModelPrivate::QFileSystemNode *parentNode, const QString& name) | - | ||||||||||||||||||||||||
| 1697 | { | - | ||||||||||||||||||||||||
| 1698 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1699 | QModelIndex parent = index(parentNode); | - | ||||||||||||||||||||||||
| 1700 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - | ||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||
| 1702 | int vLocation = parentNode->visibleLocation(name); | - | ||||||||||||||||||||||||
| 1703 |     if (vLocation >= 0 && !indexHidden)
 
  | 0 | ||||||||||||||||||||||||
| 1704 |         q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), never executed:  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation)); | 0 | ||||||||||||||||||||||||
| 1705 |                                        translateVisibleLocation(parentNode, vLocation)); never executed:  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation)); | 0 | ||||||||||||||||||||||||
| 1706 | QFileSystemNode * node = parentNode->children.take(name); | - | ||||||||||||||||||||||||
| 1707 | delete node; | - | ||||||||||||||||||||||||
| 1708 | // cleanup sort files after removing rather then re-sorting which is O(n) | - | ||||||||||||||||||||||||
| 1709 |     if (vLocation >= 0)
  | 0 | ||||||||||||||||||||||||
| 1710 |         parentNode->visibleChildren.removeAt(vLocation); never executed:  parentNode->visibleChildren.removeAt(vLocation); | 0 | ||||||||||||||||||||||||
| 1711 |     if (vLocation >= 0 && !indexHidden)
 
  | 0 | ||||||||||||||||||||||||
| 1712 |         q->endRemoveRows(); never executed:  q->endRemoveRows(); | 0 | ||||||||||||||||||||||||
| 1713 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | /*! | - | ||||||||||||||||||||||||
| 1716 | \internal | - | ||||||||||||||||||||||||
| 1717 | - | |||||||||||||||||||||||||
| 1718 | File at parentNode->children(itemLocation) was not visible before, but now should be | - | ||||||||||||||||||||||||
| 1719 | and emit signals if necessary. | - | ||||||||||||||||||||||||
| 1720 | - | |||||||||||||||||||||||||
| 1721 | *WARNING* this will change the visible count | - | ||||||||||||||||||||||||
| 1722 | */ | - | ||||||||||||||||||||||||
| 1723 | void QFileSystemModelPrivate::addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles) | - | ||||||||||||||||||||||||
| 1724 | { | - | ||||||||||||||||||||||||
| 1725 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1726 | QModelIndex parent = index(parentNode); | - | ||||||||||||||||||||||||
| 1727 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - | ||||||||||||||||||||||||
| 1728 |     if (!indexHidden) {
  | 0 | ||||||||||||||||||||||||
| 1729 | q->beginInsertRows(parent, parentNode->visibleChildren.count() , parentNode->visibleChildren.count() + newFiles.count() - 1); | - | ||||||||||||||||||||||||
| 1730 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1731 | - | |||||||||||||||||||||||||
| 1732 |     if (parentNode->dirtyChildrenIndex == -1)
  | 0 | ||||||||||||||||||||||||
| 1733 |         parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count(); never executed:  parentNode->dirtyChildrenIndex = parentNode->visibleChildren.count(); | 0 | ||||||||||||||||||||||||
| 1734 | - | |||||||||||||||||||||||||
| 1735 |     for (int i = 0; i < newFiles.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1736 | parentNode->visibleChildren.append(newFiles.at(i)); | - | ||||||||||||||||||||||||
| 1737 | parentNode->children.value(newFiles.at(i))->isVisible = true; | - | ||||||||||||||||||||||||
| 1738 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1739 |     if (!indexHidden)
  | 0 | ||||||||||||||||||||||||
| 1740 |       q->endInsertRows(); never executed:  q->endInsertRows(); | 0 | ||||||||||||||||||||||||
| 1741 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1742 | - | |||||||||||||||||||||||||
| 1743 | /*! | - | ||||||||||||||||||||||||
| 1744 | \internal | - | ||||||||||||||||||||||||
| 1745 | - | |||||||||||||||||||||||||
| 1746 | File was visible before, but now should NOT be | - | ||||||||||||||||||||||||
| 1747 | - | |||||||||||||||||||||||||
| 1748 | *WARNING* this will change the visible count | - | ||||||||||||||||||||||||
| 1749 | */ | - | ||||||||||||||||||||||||
| 1750 | void QFileSystemModelPrivate::removeVisibleFile(QFileSystemNode *parentNode, int vLocation) | - | ||||||||||||||||||||||||
| 1751 | { | - | ||||||||||||||||||||||||
| 1752 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1753 |     if (vLocation == -1)
  | 0 | ||||||||||||||||||||||||
| 1754 |         return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 1755 | QModelIndex parent = index(parentNode); | - | ||||||||||||||||||||||||
| 1756 | bool indexHidden = isHiddenByFilter(parentNode, parent); | - | ||||||||||||||||||||||||
| 1757 |     if (!indexHidden)
  | 0 | ||||||||||||||||||||||||
| 1758 |         q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), never executed:  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation)); | 0 | ||||||||||||||||||||||||
| 1759 |                                        translateVisibleLocation(parentNode, vLocation)); never executed:  q->beginRemoveRows(parent, translateVisibleLocation(parentNode, vLocation), translateVisibleLocation(parentNode, vLocation)); | 0 | ||||||||||||||||||||||||
| 1760 | parentNode->children.value(parentNode->visibleChildren.at(vLocation))->isVisible = false; | - | ||||||||||||||||||||||||
| 1761 | parentNode->visibleChildren.removeAt(vLocation); | - | ||||||||||||||||||||||||
| 1762 |     if (!indexHidden)
  | 0 | ||||||||||||||||||||||||
| 1763 |         q->endRemoveRows(); never executed:  q->endRemoveRows(); | 0 | ||||||||||||||||||||||||
| 1764 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1765 | - | |||||||||||||||||||||||||
| 1766 | /*! | - | ||||||||||||||||||||||||
| 1767 | \internal | - | ||||||||||||||||||||||||
| 1768 | - | |||||||||||||||||||||||||
| 1769 | The thread has received new information about files, | - | ||||||||||||||||||||||||
| 1770 | update and emit dataChanged if it has actually changed. | - | ||||||||||||||||||||||||
| 1771 | */ | - | ||||||||||||||||||||||||
| 1772 | void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QVector<QPair<QString, QFileInfo> > &updates) | - | ||||||||||||||||||||||||
| 1773 | { | - | ||||||||||||||||||||||||
| 1774 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1775 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1776 | QVector<QString> rowsToUpdate; | - | ||||||||||||||||||||||||
| 1777 | QStringList newFiles; | - | ||||||||||||||||||||||||
| 1778 | QFileSystemModelPrivate::QFileSystemNode *parentNode = node(path, false); | - | ||||||||||||||||||||||||
| 1779 | QModelIndex parentIndex = index(parentNode); | - | ||||||||||||||||||||||||
| 1780 |     for (int i = 0; i < updates.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1781 | QString fileName = updates.at(i).first; | - | ||||||||||||||||||||||||
| 1782 | Q_ASSERT(!fileName.isEmpty()); | - | ||||||||||||||||||||||||
| 1783 | QExtendedInformation info = fileInfoGatherer.getInfo(updates.at(i).second); | - | ||||||||||||||||||||||||
| 1784 | bool previouslyHere = parentNode->children.contains(fileName); | - | ||||||||||||||||||||||||
| 1785 |         if (!previouslyHere) {
  | 0 | ||||||||||||||||||||||||
| 1786 | addNode(parentNode, fileName, info.fileInfo()); | - | ||||||||||||||||||||||||
| 1787 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1788 | QFileSystemModelPrivate::QFileSystemNode * node = parentNode->children.value(fileName); | - | ||||||||||||||||||||||||
| 1789 | bool isCaseSensitive = parentNode->caseSensitive(); | - | ||||||||||||||||||||||||
| 1790 |         if (isCaseSensitive) {
  | 0 | ||||||||||||||||||||||||
| 1791 |             if (node->fileName != fileName)
  | 0 | ||||||||||||||||||||||||
| 1792 |                 continue; never executed:  continue; | 0 | ||||||||||||||||||||||||
| 1793 |         } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1794 |             if (QString::compare(node->fileName,fileName,Qt::CaseInsensitive) != 0)
  | 0 | ||||||||||||||||||||||||
| 1795 |                 continue; never executed:  continue; | 0 | ||||||||||||||||||||||||
| 1796 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1797 |         if (isCaseSensitive) {
  | 0 | ||||||||||||||||||||||||
| 1798 | Q_ASSERT(node->fileName == fileName); | - | ||||||||||||||||||||||||
| 1799 |         } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1800 | node->fileName = fileName; | - | ||||||||||||||||||||||||
| 1801 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1802 | - | |||||||||||||||||||||||||
| 1803 |         if (*node != info ) {
  | 0 | ||||||||||||||||||||||||
| 1804 | node->populate(info); | - | ||||||||||||||||||||||||
| 1805 | bypassFilters.remove(node); | - | ||||||||||||||||||||||||
| 1806 | // brand new information. | - | ||||||||||||||||||||||||
| 1807 |             if (filtersAcceptsNode(node)) {
  | 0 | ||||||||||||||||||||||||
| 1808 |                 if (!node->isVisible) {
  | 0 | ||||||||||||||||||||||||
| 1809 | newFiles.append(fileName); | - | ||||||||||||||||||||||||
| 1810 |                 } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1811 | rowsToUpdate.append(fileName); | - | ||||||||||||||||||||||||
| 1812 |                 } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1813 | } else { | - | ||||||||||||||||||||||||
| 1814 |                 if (node->isVisible) {
  | 0 | ||||||||||||||||||||||||
| 1815 | int visibleLocation = parentNode->visibleLocation(fileName); | - | ||||||||||||||||||||||||
| 1816 | removeVisibleFile(parentNode, visibleLocation); | - | ||||||||||||||||||||||||
| 1817 |                 } else { never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1818 | // The file is not visible, don't do anything | - | ||||||||||||||||||||||||
| 1819 |                 } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1820 | } | - | ||||||||||||||||||||||||
| 1821 | } | - | ||||||||||||||||||||||||
| 1822 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1823 | - | |||||||||||||||||||||||||
| 1824 | // bundle up all of the changed signals into as few as possible. | - | ||||||||||||||||||||||||
| 1825 | std::sort(rowsToUpdate.begin(), rowsToUpdate.end()); | - | ||||||||||||||||||||||||
| 1826 | QString min; | - | ||||||||||||||||||||||||
| 1827 | QString max; | - | ||||||||||||||||||||||||
| 1828 |     for (int i = 0; i < rowsToUpdate.count(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1829 | QString value = rowsToUpdate.at(i); | - | ||||||||||||||||||||||||
| 1830 | //##TODO is there a way to bundle signals with QString as the content of the list? | - | ||||||||||||||||||||||||
| 1831 | /*if (min.isEmpty()) { | - | ||||||||||||||||||||||||
| 1832 | min = value; | - | ||||||||||||||||||||||||
| 1833 | if (i != rowsToUpdate.count() - 1) | - | ||||||||||||||||||||||||
| 1834 | continue; | - | ||||||||||||||||||||||||
| 1835 | } | - | ||||||||||||||||||||||||
| 1836 | if (i != rowsToUpdate.count() - 1) { | - | ||||||||||||||||||||||||
| 1837 | if ((value == min + 1 && max.isEmpty()) || value == max + 1) { | - | ||||||||||||||||||||||||
| 1838 | max = value; | - | ||||||||||||||||||||||||
| 1839 | continue; | - | ||||||||||||||||||||||||
| 1840 | } | - | ||||||||||||||||||||||||
| 1841 | }*/ | - | ||||||||||||||||||||||||
| 1842 | max = value; | - | ||||||||||||||||||||||||
| 1843 | min = value; | - | ||||||||||||||||||||||||
| 1844 | int visibleMin = parentNode->visibleLocation(min); | - | ||||||||||||||||||||||||
| 1845 | int visibleMax = parentNode->visibleLocation(max); | - | ||||||||||||||||||||||||
| 1846 |         if (visibleMin >= 0
  | 0 | ||||||||||||||||||||||||
| 1847 |             && visibleMin < parentNode->visibleChildren.count()
  | 0 | ||||||||||||||||||||||||
| 1848 |             && parentNode->visibleChildren.at(visibleMin) == min
  | 0 | ||||||||||||||||||||||||
| 1849 |             && visibleMax >= 0) {
  | 0 | ||||||||||||||||||||||||
| 1850 | QModelIndex bottom = q->index(translateVisibleLocation(parentNode, visibleMin), 0, parentIndex); | - | ||||||||||||||||||||||||
| 1851 | QModelIndex top = q->index(translateVisibleLocation(parentNode, visibleMax), 3, parentIndex); | - | ||||||||||||||||||||||||
| 1852 | emit q->dataChanged(bottom, top); | - | ||||||||||||||||||||||||
| 1853 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1854 | - | |||||||||||||||||||||||||
| 1855 | /*min = QString(); | - | ||||||||||||||||||||||||
| 1856 | max = QString();*/ | - | ||||||||||||||||||||||||
| 1857 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1858 | - | |||||||||||||||||||||||||
| 1859 |     if (newFiles.count() > 0) {
  | 0 | ||||||||||||||||||||||||
| 1860 | addVisibleFiles(parentNode, newFiles); | - | ||||||||||||||||||||||||
| 1861 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1862 | - | |||||||||||||||||||||||||
| 1863 |     if (newFiles.count() > 0 || (sortColumn != 0 && rowsToUpdate.count() > 0)) {
 
 
  | 0 | ||||||||||||||||||||||||
| 1864 | forceSort = true; | - | ||||||||||||||||||||||||
| 1865 | delayedSort(); | - | ||||||||||||||||||||||||
| 1866 |     } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1867 | #else | - | ||||||||||||||||||||||||
| 1868 | Q_UNUSED(path) | - | ||||||||||||||||||||||||
| 1869 | Q_UNUSED(updates) | - | ||||||||||||||||||||||||
| 1870 | #endif // !QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1871 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1872 | - | |||||||||||||||||||||||||
| 1873 | /*! | - | ||||||||||||||||||||||||
| 1874 | \internal | - | ||||||||||||||||||||||||
| 1875 | */ | - | ||||||||||||||||||||||||
| 1876 | void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QString &resolvedName) | - | ||||||||||||||||||||||||
| 1877 | { | - | ||||||||||||||||||||||||
| 1878 | resolvedSymLinks[fileName] = resolvedName; | - | ||||||||||||||||||||||||
| 1879 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | /*! | - | ||||||||||||||||||||||||
| 1882 | \internal | - | ||||||||||||||||||||||||
| 1883 | */ | - | ||||||||||||||||||||||||
| 1884 | void QFileSystemModelPrivate::init() | - | ||||||||||||||||||||||||
| 1885 | { | - | ||||||||||||||||||||||||
| 1886 | Q_Q(QFileSystemModel); | - | ||||||||||||||||||||||||
| 1887 | qRegisterMetaType<QVector<QPair<QString,QFileInfo> > >(); | - | ||||||||||||||||||||||||
| 1888 | #ifndef QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1889 | q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)), | - | ||||||||||||||||||||||||
| 1890 | q, SLOT(_q_directoryChanged(QString,QStringList))); | - | ||||||||||||||||||||||||
| 1891 | q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QVector<QPair<QString,QFileInfo> >)), | - | ||||||||||||||||||||||||
| 1892 | q, SLOT(_q_fileSystemChanged(QString,QVector<QPair<QString,QFileInfo> >))); | - | ||||||||||||||||||||||||
| 1893 | q->connect(&fileInfoGatherer, SIGNAL(nameResolved(QString,QString)), | - | ||||||||||||||||||||||||
| 1894 | q, SLOT(_q_resolvedName(QString,QString))); | - | ||||||||||||||||||||||||
| 1895 | q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)), | - | ||||||||||||||||||||||||
| 1896 | q, SIGNAL(directoryLoaded(QString))); | - | ||||||||||||||||||||||||
| 1897 | #endif // !QT_NO_FILESYSTEMWATCHER | - | ||||||||||||||||||||||||
| 1898 | q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||
| 1900 |     roleNames.insertMulti(QFileSystemModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration never executed:  return ba; | 0 | ||||||||||||||||||||||||
| 1901 |     roleNames.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath")); never executed:  return ba; | 0 | ||||||||||||||||||||||||
| 1902 |     roleNames.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName")); never executed:  return ba; | 0 | ||||||||||||||||||||||||
| 1903 |     roleNames.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions")); never executed:  return ba; | 0 | ||||||||||||||||||||||||
| 1904 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1905 | - | |||||||||||||||||||||||||
| 1906 | /*! | - | ||||||||||||||||||||||||
| 1907 | \internal | - | ||||||||||||||||||||||||
| 1908 | - | |||||||||||||||||||||||||
| 1909 | Returns \c false if node doesn't pass the filters otherwise true | - | ||||||||||||||||||||||||
| 1910 | - | |||||||||||||||||||||||||
| 1911 | QDir::Modified is not supported | - | ||||||||||||||||||||||||
| 1912 | QDir::Drives is not supported | - | ||||||||||||||||||||||||
| 1913 | */ | - | ||||||||||||||||||||||||
| 1914 | bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) const | - | ||||||||||||||||||||||||
| 1915 | { | - | ||||||||||||||||||||||||
| 1916 | // always accept drives | - | ||||||||||||||||||||||||
| 1917 |     if (node->parent == &root || bypassFilters.contains(node))
 
  | 0 | ||||||||||||||||||||||||
| 1918 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||
| 1920 | // If we don't know anything yet don't accept it | - | ||||||||||||||||||||||||
| 1921 |     if (!node->hasInformation())
  | 0 | ||||||||||||||||||||||||
| 1922 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1923 | - | |||||||||||||||||||||||||
| 1924 |     const bool filterPermissions = ((filters & QDir::PermissionMask)
  | 0 | ||||||||||||||||||||||||
| 1925 |                                    && (filters & QDir::PermissionMask) != QDir::PermissionMask);
  | 0 | ||||||||||||||||||||||||
| 1926 | const bool hideDirs = !(filters & (QDir::Dirs | QDir::AllDirs)); | - | ||||||||||||||||||||||||
| 1927 | const bool hideFiles = !(filters & QDir::Files); | - | ||||||||||||||||||||||||
| 1928 |     const bool hideReadable      = !(!filterPermissions || (filters & QDir::Readable));
 
  | 0 | ||||||||||||||||||||||||
| 1929 |     const bool hideWritable      = !(!filterPermissions || (filters & QDir::Writable));
 
  | 0 | ||||||||||||||||||||||||
| 1930 |     const bool hideExecutable    = !(!filterPermissions || (filters & QDir::Executable));
 
  | 0 | ||||||||||||||||||||||||
| 1931 | const bool hideHidden = !(filters & QDir::Hidden); | - | ||||||||||||||||||||||||
| 1932 | const bool hideSystem = !(filters & QDir::System); | - | ||||||||||||||||||||||||
| 1933 | const bool hideSymlinks = (filters & QDir::NoSymLinks); | - | ||||||||||||||||||||||||
| 1934 | const bool hideDot = (filters & QDir::NoDot); | - | ||||||||||||||||||||||||
| 1935 | const bool hideDotDot = (filters & QDir::NoDotDot); | - | ||||||||||||||||||||||||
| 1936 | - | |||||||||||||||||||||||||
| 1937 | // Note that we match the behavior of entryList and not QFileInfo on this. | - | ||||||||||||||||||||||||
| 1938 | bool isDot = (node->fileName == QLatin1String(".")); | - | ||||||||||||||||||||||||
| 1939 | bool isDotDot = (node->fileName == QLatin1String("..")); | - | ||||||||||||||||||||||||
| 1940 |     if (   (hideHidden && !(isDot || isDotDot) && node->isHidden())
 
 
 
  | 0 | ||||||||||||||||||||||||
| 1941 |         || (hideSystem && node->isSystem())
 
  | 0 | ||||||||||||||||||||||||
| 1942 |         || (hideDirs && node->isDir())
 
  | 0 | ||||||||||||||||||||||||
| 1943 |         || (hideFiles && node->isFile())
 
  | 0 | ||||||||||||||||||||||||
| 1944 |         || (hideSymlinks && node->isSymLink())
 
  | 0 | ||||||||||||||||||||||||
| 1945 |         || (hideReadable && node->isReadable())
 
  | 0 | ||||||||||||||||||||||||
| 1946 |         || (hideWritable && node->isWritable())
 
  | 0 | ||||||||||||||||||||||||
| 1947 |         || (hideExecutable && node->isExecutable())
 
  | 0 | ||||||||||||||||||||||||
| 1948 |         || (hideDot && isDot)
 
  | 0 | ||||||||||||||||||||||||
| 1949 |         || (hideDotDot && isDotDot))
 
  | 0 | ||||||||||||||||||||||||
| 1950 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1951 | - | |||||||||||||||||||||||||
| 1952 |     return nameFilterDisables || passNameFilters(node); never executed:  return nameFilterDisables || passNameFilters(node);
 
  | 0 | ||||||||||||||||||||||||
| 1953 | } | - | ||||||||||||||||||||||||
| 1954 | - | |||||||||||||||||||||||||
| 1955 | /* | - | ||||||||||||||||||||||||
| 1956 | \internal | - | ||||||||||||||||||||||||
| 1957 | - | |||||||||||||||||||||||||
| 1958 | Returns \c true if node passes the name filters and should be visible. | - | ||||||||||||||||||||||||
| 1959 | */ | - | ||||||||||||||||||||||||
| 1960 | bool QFileSystemModelPrivate::passNameFilters(const QFileSystemNode *node) const | - | ||||||||||||||||||||||||
| 1961 | { | - | ||||||||||||||||||||||||
| 1962 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||||||||
| 1963 |     if (nameFilters.isEmpty())
  | 0 | ||||||||||||||||||||||||
| 1964 |         return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||
| 1966 | // Check the name regularexpression filters | - | ||||||||||||||||||||||||
| 1967 |     if (!(node->isDir() && (filters & QDir::AllDirs))) {
 
  | 0 | ||||||||||||||||||||||||
| 1968 |         for (int i = 0; i < nameFilters.size(); ++i) {
  | 0 | ||||||||||||||||||||||||
| 1969 | QRegExp copy = nameFilters.at(i); | - | ||||||||||||||||||||||||
| 1970 |             if (copy.exactMatch(node->fileName))
  | 0 | ||||||||||||||||||||||||
| 1971 |                 return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 1972 |         } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 1973 |         return false; never executed:  return false; | 0 | ||||||||||||||||||||||||
| 1974 | } | - | ||||||||||||||||||||||||
| 1975 | #endif | - | ||||||||||||||||||||||||
| 1976 |     return true; never executed:  return true; | 0 | ||||||||||||||||||||||||
| 1977 | } | - | ||||||||||||||||||||||||
| 1978 | - | |||||||||||||||||||||||||
| 1979 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1980 | - | |||||||||||||||||||||||||
| 1981 | #include "moc_qfilesystemmodel.cpp" | - | ||||||||||||||||||||||||
| 1982 | - | |||||||||||||||||||||||||
| 1983 | #endif // QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |