diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/src/Caelestia/filesystemmodel.cpp | 19 | ||||
| -rw-r--r-- | plugin/src/Caelestia/filesystemmodel.hpp | 7 |
2 files changed, 24 insertions, 2 deletions
diff --git a/plugin/src/Caelestia/filesystemmodel.cpp b/plugin/src/Caelestia/filesystemmodel.cpp index 40b322b..3ba95d8 100644 --- a/plugin/src/Caelestia/filesystemmodel.cpp +++ b/plugin/src/Caelestia/filesystemmodel.cpp @@ -59,6 +59,21 @@ void FileSystemModel::setRecursive(bool recursive) { update(); } +bool FileSystemModel::watchChanges() const { + return m_watchChanges; +} + +void FileSystemModel::setWatchChanges(bool watchChanges) { + if (m_watchChanges == watchChanges) { + return; + } + + m_watchChanges = watchChanges; + emit watchChangesChanged(); + + update(); +} + FileSystemModel::Filter FileSystemModel::filter() const { return m_filter; } @@ -79,7 +94,7 @@ QList<FileSystemEntry*> FileSystemModel::entries() const { } void FileSystemModel::watchDirIfRecursive(const QString& path) { - if (m_recursive) { + if (m_recursive && m_watchChanges) { const auto currentDir = m_dir; const auto future = QtConcurrent::run([path]() { QDirIterator iter(path, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); @@ -112,7 +127,7 @@ void FileSystemModel::updateWatcher() { m_watcher.removePaths(m_watcher.directories()); } - if (m_path.isEmpty()) { + if (!m_watchChanges || m_path.isEmpty()) { return; } diff --git a/plugin/src/Caelestia/filesystemmodel.hpp b/plugin/src/Caelestia/filesystemmodel.hpp index 978497e..ab226a3 100644 --- a/plugin/src/Caelestia/filesystemmodel.hpp +++ b/plugin/src/Caelestia/filesystemmodel.hpp @@ -62,6 +62,7 @@ class FileSystemModel : public QAbstractListModel { Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) + Q_PROPERTY(bool watchChanges READ watchChanges WRITE setWatchChanges NOTIFY watchChangesChanged) Q_PROPERTY(Filter filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged) @@ -77,6 +78,7 @@ public: explicit FileSystemModel(QObject* parent = nullptr) : QAbstractListModel(parent) , m_recursive(true) + , m_watchChanges(true) , m_filter(NoFilter) { connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::watchDirIfRecursive); connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntriesForDir); @@ -92,6 +94,9 @@ public: bool recursive() const; void setRecursive(bool recursive); + bool watchChanges() const; + void setWatchChanges(bool watchChanges); + Filter filter() const; void setFilter(Filter filter); @@ -100,6 +105,7 @@ public: signals: void pathChanged(); void recursiveChanged(); + void watchChangesChanged(); void filterChanged(); void entriesChanged(); @@ -114,6 +120,7 @@ private: QString m_path; bool m_recursive; + bool m_watchChanges; Filter m_filter; void watchDirIfRecursive(const QString& path); |