diff options
author | kakadu <kakadu.hafanana@gmail.com> | 2013-10-24 14:24:45 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 23:04:18 +0100 |
commit | 3d96c688a919c3ebc0ea3822e59bbc728c68eb95 (patch) | |
tree | 8dd1747350b89a7de4a4c5a29f8c3af2bf15932e /src/imports | |
parent | ba6fc15d729304c136447242de2410fbf4f020cd (diff) |
Add support of hidden files to folder list model.
Property 'ShowHidden' has been added to see hidden files.
Task-number: QTBUG-34247.
Change-Id: I7016b04b9d29731139c32bc0b30b93762e03e02e
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/folderlistmodel/fileinfothread.cpp | 12 | ||||
-rw-r--r-- | src/imports/folderlistmodel/fileinfothread_p.h | 2 | ||||
-rw-r--r-- | src/imports/folderlistmodel/plugins.qmltypes | 1 | ||||
-rw-r--r-- | src/imports/folderlistmodel/qquickfolderlistmodel.cpp | 33 | ||||
-rw-r--r-- | src/imports/folderlistmodel/qquickfolderlistmodel.h | 3 |
5 files changed, 48 insertions, 3 deletions
diff --git a/src/imports/folderlistmodel/fileinfothread.cpp b/src/imports/folderlistmodel/fileinfothread.cpp index 4aa43b2d3f..f7587c25f5 100644 --- a/src/imports/folderlistmodel/fileinfothread.cpp +++ b/src/imports/folderlistmodel/fileinfothread.cpp @@ -59,6 +59,7 @@ FileInfoThread::FileInfoThread(QObject *parent) showDirs(true), showDirsFirst(false), showDotAndDotDot(false), + showHidden(false), showOnlyReadable(false) { #ifndef QT_NO_FILESYSTEMWATCHER @@ -176,6 +177,15 @@ void FileInfoThread::setShowDotAndDotDot(bool on) condition.wakeAll(); } +void FileInfoThread::setShowHidden(bool on) +{ + QMutexLocker locker(&mutex); + showHidden = on; + folderUpdate = true; + needUpdate = true; + condition.wakeAll(); +} + void FileInfoThread::setShowOnlyReadable(bool on) { QMutexLocker locker(&mutex); @@ -231,6 +241,8 @@ void FileInfoThread::getFileInfos(const QString &path) filter = filter | QDir::NoDot | QDir::NoDotDot; else if (path == rootPath) filter = filter | QDir::NoDotDot; + if (showHidden) + filter = filter | QDir::Hidden; if (showOnlyReadable) filter = filter | QDir::Readable; if (showDirsFirst) diff --git a/src/imports/folderlistmodel/fileinfothread_p.h b/src/imports/folderlistmodel/fileinfothread_p.h index d50361de3a..d54b2dfcae 100644 --- a/src/imports/folderlistmodel/fileinfothread_p.h +++ b/src/imports/folderlistmodel/fileinfothread_p.h @@ -74,6 +74,7 @@ public: void setShowDirs(bool showFolders); void setShowDirsFirst(bool show); void setShowDotAndDotDot(bool on); + void setShowHidden(bool on); void setShowOnlyReadable(bool on); public Q_SLOTS: @@ -107,6 +108,7 @@ private: bool showDirs; bool showDirsFirst; bool showDotAndDotDot; + bool showHidden; bool showOnlyReadable; }; diff --git a/src/imports/folderlistmodel/plugins.qmltypes b/src/imports/folderlistmodel/plugins.qmltypes index 20914f4108..1d451e9e24 100644 --- a/src/imports/folderlistmodel/plugins.qmltypes +++ b/src/imports/folderlistmodel/plugins.qmltypes @@ -33,6 +33,7 @@ Module { Property { name: "showDirs"; type: "bool" } Property { name: "showDirsFirst"; type: "bool" } Property { name: "showDotAndDotDot"; type: "bool" } + Property { name: "showHidden"; type: "bool" } Property { name: "showOnlyReadable"; type: "bool" } Property { name: "count"; type: "int"; isReadonly: true } Signal { name: "rowCountChanged" } diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index 7cab257d32..e02de1c208 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -56,7 +56,8 @@ public: QQuickFolderListModelPrivate(QQuickFolderListModel *q) : q_ptr(q), sortField(QQuickFolderListModel::Name), sortReversed(false), showFiles(true), - showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false) + showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false), + showHidden(false) { nameFilters << QLatin1String("*"); } @@ -76,6 +77,7 @@ public: bool showDirsFirst; bool showDotAndDotDot; bool showOnlyReadable; + bool showHidden; ~QQuickFolderListModelPrivate() {} void init(); @@ -271,9 +273,10 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path) that are applied to names of files and directories, causing only those that match the filters to be exposed. - Directories can be included or excluded using the \l showDirs property, and + Directories can be included or excluded using the \l showDirs property, navigation directories can also be excluded by setting the \l showDotAndDotDot - property to false. + property to false, hidden files can be included or excluded using the + \l showHidden property. It is sometimes useful to limit the files and directories exposed to those that the user can access. The \l showOnlyReadable property can be set to @@ -721,6 +724,30 @@ void QQuickFolderListModel::setShowDotAndDotDot(bool on) } } + +/*! + \qmlproperty bool FolderListModel::showHidden + + If true, hidden files and directories are included in the model; otherwise + they are excluded. + + By default, this property is false. +*/ +bool QQuickFolderListModel::showHidden() const +{ + Q_D(const QQuickFolderListModel); + return d->showHidden; +} + +void QQuickFolderListModel::setShowHidden(bool on) +{ + Q_D(QQuickFolderListModel); + + if (on != d->showHidden) { + d->fileInfoThread.setShowHidden(on); + } +} + /*! \qmlproperty bool FolderListModel::showOnlyReadable diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.h b/src/imports/folderlistmodel/qquickfolderlistmodel.h index 3bf9a21d49..cdf7e0601a 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.h +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h @@ -73,6 +73,7 @@ class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst) Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) + Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden) Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) Q_PROPERTY(int count READ count NOTIFY countChanged) //![class props] @@ -131,6 +132,8 @@ public: void setShowDirsFirst(bool showDirsFirst); bool showDotAndDotDot() const; void setShowDotAndDotDot(bool on); + bool showHidden() const; + void setShowHidden(bool on); bool showOnlyReadable() const; void setShowOnlyReadable(bool on); //![prop funcs] |