WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
Zbl::ZFileSystemWatcher Class Reference

This class wraps QFileSystemWatcher and adds path reference counting. More...

#include <ZFileSystemWatcher.h>

Inheritance diagram for Zbl::ZFileSystemWatcher:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZFileSystemWatcher:
Collaboration graph
[legend]

Public Types

typedef QMap< QString, int > zFileWatcherMap
 

Signals

void fileChanged (const QString &path)
 
void directoryChanged (const QString &path)
 

Public Member Functions

 ZFileSystemWatcher (QObject *parent=nullptr)
 
Q_INVOKABLE bool addPath (const QString &file)
 
Q_INVOKABLE QStringList addPaths (const QStringList &files)
 
Q_INVOKABLE bool removePath (const QString &file)
 
Q_INVOKABLE QStringList removePaths (const QStringList &files)
 
Q_INVOKABLE QStringList files () const
 
Q_INVOKABLE QStringList directories () const
 
bool getRestoreDeletedFiles ()
 
void setRestoreDeletedFiles (bool restoreFiles)
 

Static Public Member Functions

static void registerType ()
 Registers ZFileSystemWatcher as a QML type. More...
 

Protected Member Functions

void onFileChanged (const QString &path)
 
bool waitForFileCreation (const QString &path)
 

Protected Attributes

QFileSystemWatcher m_watcher
 
zFileWatcherMap m_paths
 
QMutex m_lock
 
bool m_restoreDeletedFiles
 

Properties

bool restoreDeletedFiles
 When true ZFileSystemWatcher will wait for deleted files to be restored. More...
 

Detailed Description

This class wraps QFileSystemWatcher and adds path reference counting.

Each time a path is added to ZFileSystemWatcher the path's reference count is incremented and each time a path is removed it's reference count is decremented. As long as the path's reference count is greater than zero ZFileSystemWatcher will continue to watch the path. When the path's reference count reaches zero that path is removed from the watch list and the path will no longer be watched.

Definition at line 50 of file ZFileSystemWatcher.h.

Member Typedef Documentation

◆ zFileWatcherMap

typedef QMap<QString, int> Zbl::ZFileSystemWatcher::zFileWatcherMap

Definition at line 55 of file ZFileSystemWatcher.h.

Constructor & Destructor Documentation

◆ ZFileSystemWatcher()

Zbl::ZFileSystemWatcher::ZFileSystemWatcher ( QObject *  parent = nullptr)
explicit

Definition at line 33 of file ZFileSystemWatcher.cpp.

Member Function Documentation

◆ addPath()

bool Zbl::ZFileSystemWatcher::addPath ( const QString &  file)

Definition at line 50 of file ZFileSystemWatcher.cpp.

Referenced by addPaths(), and Zbl::ZSettings::setFileWatcher().

◆ addPaths()

QStringList Zbl::ZFileSystemWatcher::addPaths ( const QStringList &  files)

Definition at line 81 of file ZFileSystemWatcher.cpp.

◆ directories()

QStringList Zbl::ZFileSystemWatcher::directories ( ) const

Definition at line 156 of file ZFileSystemWatcher.cpp.

◆ directoryChanged

void Zbl::ZFileSystemWatcher::directoryChanged ( const QString &  path)
signal

Referenced by ZFileSystemWatcher().

◆ fileChanged

void Zbl::ZFileSystemWatcher::fileChanged ( const QString &  path)
signal

◆ files()

QStringList Zbl::ZFileSystemWatcher::files ( ) const

Definition at line 148 of file ZFileSystemWatcher.cpp.

Referenced by Zbl::ZSettings::onFileChanged().

◆ getRestoreDeletedFiles()

bool Zbl::ZFileSystemWatcher::getRestoreDeletedFiles ( )

Definition at line 164 of file ZFileSystemWatcher.cpp.

◆ onFileChanged()

void Zbl::ZFileSystemWatcher::onFileChanged ( const QString &  path)
protected

Definition at line 202 of file ZFileSystemWatcher.cpp.

Referenced by ZFileSystemWatcher().

◆ registerType()

void Zbl::ZFileSystemWatcher::registerType ( )
static

Registers ZFileSystemWatcher as a QML type.

Definition at line 42 of file ZFileSystemWatcher.cpp.

Referenced by Zbl::Zblcore::registerTypes().

◆ removePath()

bool Zbl::ZFileSystemWatcher::removePath ( const QString &  file)

Definition at line 100 of file ZFileSystemWatcher.cpp.

Referenced by removePaths(), and Zbl::ZSettings::setFileWatcher().

◆ removePaths()

QStringList Zbl::ZFileSystemWatcher::removePaths ( const QStringList &  files)

Definition at line 129 of file ZFileSystemWatcher.cpp.

◆ setRestoreDeletedFiles()

void Zbl::ZFileSystemWatcher::setRestoreDeletedFiles ( bool  restoreFiles)

Definition at line 171 of file ZFileSystemWatcher.cpp.

Referenced by Zbl::ZSettings::ZSettings().

◆ waitForFileCreation()

bool Zbl::ZFileSystemWatcher::waitForFileCreation ( const QString &  path)
protected

Definition at line 178 of file ZFileSystemWatcher.cpp.

Referenced by onFileChanged().

Member Data Documentation

◆ m_lock

QMutex Zbl::ZFileSystemWatcher::m_lock
protected

◆ m_paths

zFileWatcherMap Zbl::ZFileSystemWatcher::m_paths
protected

Definition at line 111 of file ZFileSystemWatcher.h.

Referenced by addPath(), removePath(), and waitForFileCreation().

◆ m_restoreDeletedFiles

bool Zbl::ZFileSystemWatcher::m_restoreDeletedFiles
protected

◆ m_watcher

QFileSystemWatcher Zbl::ZFileSystemWatcher::m_watcher
protected

Definition at line 109 of file ZFileSystemWatcher.h.

Referenced by addPath(), directories(), files(), onFileChanged(), and removePath().

Property Documentation

◆ restoreDeletedFiles

bool Zbl::ZFileSystemWatcher::restoreDeletedFiles
readwrite

When true ZFileSystemWatcher will wait for deleted files to be restored.

Some programs modify files by deleting and re-creating them. The file deletion causes QFileSystemWatcher to stop watching the deleted path. When restoreDeletedFiles is true ZFileSystemWatcher will wait for deleted files to be re-created by the modifying process before emitting the fileChanged signal and adding the deleted path back to QFileSystemWatcher's path list.

WARNING: When this property is set file deletions NOT immediately re-created by the modifying process will cause ZFileSystemWatcher to time out and generate an error message.

Definition at line 81 of file ZFileSystemWatcher.h.


The documentation for this class was generated from the following files: