34 QObject(parent), m_lock(QMutex::Recursive), m_restoreDeletedFiles(false)
36 connect(&m_watcher, &QFileSystemWatcher::fileChanged,
38 connect(&m_watcher, &QFileSystemWatcher::directoryChanged,
46 qmlRegisterType<ZFileSystemWatcher>(
"org.zuble.qml", 1, 0,
"ZFileSystemWatcher");
53 QMutexLocker lock(&
m_lock);
55 zFileWatcherMap::iterator it =
m_paths.find(file);
57 int fileReferenceCount = -1;
62 fileReferenceCount = 1;
65 m_paths.insert(file, fileReferenceCount);
67 zCritical() <<
"Zuble can't watch file path: " << file;
71 fileReferenceCount = it.value();
73 m_paths.insert(file, fileReferenceCount);
83 QStringList failedPaths;
86 QMutexLocker lock(&
m_lock);
88 const int fileCount = files.count();
90 for(
int i=0; i<fileCount; i++)
93 failedPaths.append(files.at(i));
103 QMutexLocker lock(&
m_lock);
105 zFileWatcherMap::iterator it =
m_paths.find(file);
107 int fileReferenceCount = -1;
112 fileReferenceCount = it.value();
114 if(fileReferenceCount == 1)
120 fileReferenceCount--;
121 m_paths.insert(file, fileReferenceCount);
131 QStringList failedPaths;
134 QMutexLocker lock(&
m_lock);
136 const int fileCount = files.count();
138 for(
int i=0; i<fileCount; i++)
141 failedPaths.append(files.at(i));
151 QMutexLocker lock(const_cast<QMutex*>(&
m_lock));
159 QMutexLocker lock(const_cast<QMutex*>(&
m_lock));
166 QMutexLocker lock(const_cast<QMutex*>(&
m_lock));
173 QMutexLocker lock(const_cast<QMutex*>(&
m_lock));
180 zFileWatcherMap::const_iterator i =
m_paths.find(path);
185 static const int max_iterations = 300;
187 for(
int iterations = 0; !QFile::exists(path); iterations++)
189 if(iterations > max_iterations)
191 zCritical() <<
"ERROR: ZFileSystemWatcher timed out waiting for creation of file: " 205 QMutexLocker lock(const_cast<QMutex*>(&
m_lock));
bool waitForFileCreation(const QString &path)
This class wraps QFileSystemWatcher and adds path reference counting.
bool m_restoreDeletedFiles
Q_INVOKABLE QStringList removePaths(const QStringList &files)
Q_INVOKABLE QStringList directories() const
void onFileChanged(const QString &path)
#define ZBL_REGISTER_LOGGED_OBJECT
Q_INVOKABLE bool removePath(const QString &file)
Q_INVOKABLE bool addPath(const QString &file)
void setRestoreDeletedFiles(bool restoreFiles)
Q_INVOKABLE QStringList addPaths(const QStringList &files)
#define ZBL_SLOT_BEGIN_TRY
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
static void registerType()
Registers ZFileSystemWatcher as a QML type.
Q_INVOKABLE QStringList files() const
bool getRestoreDeletedFiles()
QFileSystemWatcher m_watcher
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
void fileChanged(const QString &path)
void directoryChanged(const QString &path)