diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2014-07-12 23:02:52 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-07-12 23:31:06 +0200 |
commit | 4c0dc51110603cbe0e98228c703e26402094a3cc (patch) | |
tree | b056d601ba2494e046752e5c94e3049182293515 /logic/RecursiveFileSystemWatcher.cpp | |
parent | 5c4384235989b16d6931cc0cfa26dd192af68b96 (diff) | |
download | MultiMC-4c0dc51110603cbe0e98228c703e26402094a3cc.tar MultiMC-4c0dc51110603cbe0e98228c703e26402094a3cc.tar.gz MultiMC-4c0dc51110603cbe0e98228c703e26402094a3cc.tar.lz MultiMC-4c0dc51110603cbe0e98228c703e26402094a3cc.tar.xz MultiMC-4c0dc51110603cbe0e98228c703e26402094a3cc.zip |
Finish of the OtherLogs page, and (re)format page related files
Diffstat (limited to 'logic/RecursiveFileSystemWatcher.cpp')
-rw-r--r-- | logic/RecursiveFileSystemWatcher.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/logic/RecursiveFileSystemWatcher.cpp b/logic/RecursiveFileSystemWatcher.cpp index 5cfa7e4e..39985699 100644 --- a/logic/RecursiveFileSystemWatcher.cpp +++ b/logic/RecursiveFileSystemWatcher.cpp @@ -1,13 +1,15 @@ #include "RecursiveFileSystemWatcher.h" #include <QRegularExpression> +#include <QDebug> RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject *parent) - : QObject(parent), - m_watcher(new QFileSystemWatcher(this)) + : QObject(parent), m_exp(".*"), m_watcher(new QFileSystemWatcher(this)) { - connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &RecursiveFileSystemWatcher::fileChange); - connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &RecursiveFileSystemWatcher::directoryChange); + connect(m_watcher, &QFileSystemWatcher::fileChanged, this, + &RecursiveFileSystemWatcher::fileChange); + connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, + &RecursiveFileSystemWatcher::directoryChange); } void RecursiveFileSystemWatcher::setRootDir(const QDir &root) @@ -34,12 +36,20 @@ void RecursiveFileSystemWatcher::setWatchFiles(const bool watchFiles) void RecursiveFileSystemWatcher::enable() { + if (m_isEnabled) + { + return; + } Q_ASSERT(m_root != QDir::root()); addFilesToWatcherRecursive(m_root); m_isEnabled = true; } void RecursiveFileSystemWatcher::disable() { + if (!m_isEnabled) + { + return; + } m_isEnabled = false; m_watcher->removePaths(m_watcher->files()); m_watcher->removePaths(m_watcher->directories()); @@ -57,9 +67,9 @@ void RecursiveFileSystemWatcher::setFiles(const QStringList &files) void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir) { m_watcher->addPath(dir.absolutePath()); - for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) + for (const QString &directory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { - addFilesToWatcherRecursive(info.absoluteDir()); + addFilesToWatcherRecursive(dir.absoluteFilePath(directory)); } if (m_watchFiles) { @@ -69,19 +79,19 @@ void RecursiveFileSystemWatcher::addFilesToWatcherRecursive(const QDir &dir) } } } -QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &dir) +QStringList RecursiveFileSystemWatcher::scanRecursive(const QDir &directory) { QStringList ret; QRegularExpression exp(m_exp); - for (const QFileInfo &info : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files)) + for (const QString &dir : directory.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { - if (info.isFile() && exp.match(info.absoluteFilePath()).hasMatch()) - { - ret.append(info.absoluteFilePath()); - } - else if (info.isDir()) + ret.append(scanRecursive(directory.absoluteFilePath(dir))); + } + for (const QString &file : directory.entryList(QDir::Files)) + { + if (exp.match(file).hasMatch()) { - ret.append(scanRecursive(info.absoluteDir())); + ret.append(m_root.relativeFilePath(directory.absoluteFilePath(file))); } } return ret; |