2014-07-12 16:58:23 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QDir>
|
2015-08-18 01:25:24 +01:00
|
|
|
#include "pathmatcher/IPathMatcher.h"
|
2014-07-12 16:58:23 +01:00
|
|
|
|
2015-09-05 17:46:57 +01:00
|
|
|
#include "multimc_logic_export.h"
|
|
|
|
|
|
|
|
class MULTIMC_LOGIC_EXPORT RecursiveFileSystemWatcher : public QObject
|
2014-07-12 16:58:23 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
RecursiveFileSystemWatcher(QObject *parent);
|
|
|
|
|
|
|
|
void setRootDir(const QDir &root);
|
2015-08-18 01:25:24 +01:00
|
|
|
QDir rootDir() const
|
|
|
|
{
|
|
|
|
return m_root;
|
|
|
|
}
|
2014-07-12 16:58:23 +01:00
|
|
|
|
|
|
|
// WARNING: setting this to true may be bad for performance
|
|
|
|
void setWatchFiles(const bool watchFiles);
|
2015-08-18 01:25:24 +01:00
|
|
|
bool watchFiles() const
|
|
|
|
{
|
|
|
|
return m_watchFiles;
|
|
|
|
}
|
2014-07-12 16:58:23 +01:00
|
|
|
|
2015-08-18 01:25:24 +01:00
|
|
|
void setMatcher(IPathMatcher::Ptr matcher)
|
|
|
|
{
|
|
|
|
m_matcher = matcher;
|
|
|
|
}
|
2014-07-12 16:58:23 +01:00
|
|
|
|
2015-08-18 01:25:24 +01:00
|
|
|
QStringList files() const
|
|
|
|
{
|
|
|
|
return m_files;
|
|
|
|
}
|
2014-07-12 16:58:23 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void filesChanged();
|
|
|
|
void fileChanged(const QString &path);
|
|
|
|
|
2014-07-12 22:02:52 +01:00
|
|
|
public slots:
|
2014-07-12 16:58:23 +01:00
|
|
|
void enable();
|
|
|
|
void disable();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QDir m_root;
|
|
|
|
bool m_watchFiles = false;
|
|
|
|
bool m_isEnabled = false;
|
2015-08-18 01:25:24 +01:00
|
|
|
IPathMatcher::Ptr m_matcher;
|
2014-07-12 16:58:23 +01:00
|
|
|
|
|
|
|
QFileSystemWatcher *m_watcher;
|
|
|
|
|
|
|
|
QStringList m_files;
|
2014-07-12 22:02:52 +01:00
|
|
|
void setFiles(const QStringList &files);
|
2014-07-12 16:58:23 +01:00
|
|
|
|
|
|
|
void addFilesToWatcherRecursive(const QDir &dir);
|
|
|
|
QStringList scanRecursive(const QDir &dir);
|
|
|
|
|
2014-07-12 22:02:52 +01:00
|
|
|
private slots:
|
2014-07-12 16:58:23 +01:00
|
|
|
void fileChange(const QString &path);
|
|
|
|
void directoryChange(const QString &path);
|
|
|
|
};
|