2022-10-18 18:47:41 +00:00
|
|
|
#include "directorieswatcher.h"
|
|
|
|
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QDirIterator>
|
|
|
|
|
|
|
|
DirectoriesWatcher::DirectoriesWatcher(QObject *parent)
|
|
|
|
: QObject{parent}, fsWatcher(new QFileSystemWatcher(this))
|
|
|
|
{
|
|
|
|
connect(fsWatcher, &QFileSystemWatcher::directoryChanged,
|
|
|
|
this, &DirectoriesWatcher::changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirectoriesWatcher::addPaths(const QStringList &paths)
|
|
|
|
{
|
|
|
|
for (auto& path : paths) {
|
2022-10-25 08:24:47 +00:00
|
|
|
QDirIterator it(path, QDir::AllDirs | QDir::NoDotAndDotDot,
|
|
|
|
QDirIterator::Subdirectories);
|
2022-10-18 18:47:41 +00:00
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
const auto& subpath = it.filePath();
|
|
|
|
|
|
|
|
if (!subpath.isEmpty())
|
|
|
|
fsWatcher->addPath(subpath);
|
|
|
|
|
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
fsWatcher->addPath(path);
|
|
|
|
}
|
|
|
|
}
|