CCIMXDesktop
 
Loading...
Searching...
No Matches
FileMonitor Class Reference

Monitors a specified directory for file additions or deletions at regular intervals. More...

#include <FileMonitor.h>

Inheritance diagram for FileMonitor:

Signals

void newFiles (const QStringList &files)
 Signal emitted when new files are detected in the monitored directory.
 
void deletedFiles (const QStringList &files)
 Signal emitted when files are detected as deleted from the monitored directory.
 
void monitoringChanged (const QString &path)
 Signal emitted when the monitored directory path changes.
 
void monitoringIntervalChanged (const int new_interval)
 Signal emitted when the monitoring scan interval changes.
 
void monitoringStateChanged (const bool new_state)
 Signal emitted when the monitoring state (active/inactive) changes.
 

Public Member Functions

 FileMonitor (const QString &path, QObject *parent=nullptr)
 Constructs a FileMonitor object.
 
void setMonitorDirent (const QString &newPath)
 Sets the directory path to be monitored.
 
QString monitorDirent () const
 Returns the current directory path being monitored.
 
void setMonitorScanInterval (const int interval)
 Sets the interval (in milliseconds) at which the directory will be scanned.
 
int monitorScanInterval () const
 Returns the current monitoring scan interval.
 
void setMonitoringState (bool st)
 Sets the monitoring state (active or inactive).
 
bool monitoringState () const
 Returns the current monitoring state.
 

Detailed Description

Monitors a specified directory for file additions or deletions at regular intervals.

The FileMonitor class provides a mechanism to observe a given directory and detect changes within it, specifically the creation of new files or the deletion of existing ones. It operates by periodically scanning the directory and comparing its current state with a previously recorded state. Signals are emitted upon detecting changes, or when its monitoring parameters (path, interval, state) change. Thread-safe access to internal state is ensured using a QMutex.

Constructor & Destructor Documentation

◆ FileMonitor()

FileMonitor::FileMonitor ( const QString &  path,
QObject *  parent = nullptr 
)
explicit

Constructs a FileMonitor object.

Parameters
pathThe initial directory path to monitor.
parentA pointer to the parent QObject, allowing for proper object hierarchy and memory management. Defaults to nullptr.

Member Function Documentation

◆ deletedFiles

void FileMonitor::deletedFiles ( const QStringList &  files)
signal

Signal emitted when files are detected as deleted from the monitored directory.

Parameters
filesA QStringList containing the absolute paths of the deleted files.

◆ monitorDirent()

QString FileMonitor::monitorDirent ( ) const

Returns the current directory path being monitored.

Returns
A QString containing the path of the monitored directory.

◆ monitoringChanged

void FileMonitor::monitoringChanged ( const QString &  path)
signal

Signal emitted when the monitored directory path changes.

Parameters
pathThe new path being monitored.

◆ monitoringIntervalChanged

void FileMonitor::monitoringIntervalChanged ( const int  new_interval)
signal

Signal emitted when the monitoring scan interval changes.

Parameters
new_intervalThe new scan interval in milliseconds.

◆ monitoringState()

bool FileMonitor::monitoringState ( ) const

Returns the current monitoring state.

Returns
True if monitoring is active, false otherwise.

◆ monitoringStateChanged

void FileMonitor::monitoringStateChanged ( const bool  new_state)
signal

Signal emitted when the monitoring state (active/inactive) changes.

Parameters
new_stateThe new monitoring state (true for active, false for inactive).

◆ monitorScanInterval()

int FileMonitor::monitorScanInterval ( ) const

Returns the current monitoring scan interval.

Returns
The scan interval in milliseconds.

◆ newFiles

void FileMonitor::newFiles ( const QStringList &  files)
signal

Signal emitted when new files are detected in the monitored directory.

Parameters
filesA QStringList containing the absolute paths of the newly detected files.

◆ setMonitorDirent()

void FileMonitor::setMonitorDirent ( const QString &  newPath)

Sets the directory path to be monitored.

  • If the new path is different from the current one, the monitor's state is reset, and a monitoringChanged signal is emitted.
    Parameters
    newPathThe new directory path to monitor.

◆ setMonitoringState()

void FileMonitor::setMonitoringState ( bool  st)

Sets the monitoring state (active or inactive).

  • When set to true, the monitor starts scanning. When set to false, it stops. A monitoringStateChanged signal is emitted upon state change.
    Parameters
    stTrue to start monitoring, false to stop.

◆ setMonitorScanInterval()

void FileMonitor::setMonitorScanInterval ( const int  interval)

Sets the interval (in milliseconds) at which the directory will be scanned.

  • If the new interval is different, the timer is updated, and a monitoringIntervalChanged signal is emitted.
    Parameters
    intervalThe new scan interval in milliseconds.

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