#include <wx/fswatcher.h>
The wxFileSystemWatcher class allows to receive notifications of file system changes.
For the full list of change types that are reported see wxFSWFlags.
There are three different ways to use this class:
EVT_FSWATCHER
macro or wxEvtHandler::Connect to redirect events to an event handler defined in the derived class. If the default constructor is used, the file system watcher object will be its own owner object, since it is derived from wxEvtHandler.EVT_FSWATCHER
macro or wxEvtHandler::Connect to send the events to the event handler which will receive wxFileSystemWatcherEvent.For example:
class MyWatcher : public wxFileSystemWatcher { protected: void OnChange(int changeType, const wxFileName& path, const wxFileName& newPath) { // do whatever you like with the event } }; class MyApp : public wxApp { public: ... void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop)) { // you have to construct the watcher here, because it needs an active loop m_watcher = new MyWatcher(); // please notify me when a new log file is created m_watcher->Add(wxFileName::DirName("/var/log", wxFSW_EVENT_CREATE); } private: MyWatcher* m_watcher; };
Public Member Functions | |
wxFileSystemWatcher () | |
Default constructor. | |
virtual | ~wxFileSystemWatcher () |
Destructor. | |
virtual bool | Add (const wxFileName &path, int events=wxFSW_EVENT_ALL) |
Adds path to currently watched files. | |
virtual bool | AddTree (const wxFileName &path, int events=wxFSW_EVENT_ALL, const wxString &filter=wxEmptyString)=0 |
This is the same as Add(), but recursively adds every file/directory in the tree rooted at path. | |
virtual bool | Remove (const wxFileName &path) |
Removes path from the list of watched paths. | |
virtual bool | RemoveTree (const wxFileName &path) |
Same as Remove(), but also removes every file/directory belonging to the tree rooted at path. | |
virtual bool | RemoveAll () |
Clears the list of currently watched paths. | |
int | GetWatchedPathCount () const |
Returns the number of watched paths. | |
int | GetWatchedPaths (wxArrayString *paths) const |
Retrieves all watched paths and places them in paths. | |
void | SetOwner (wxEvtHandler *handler) |
Associates the file system watcher with the given handler object. | |
Protected Member Functions | |
virtual void | OnChange (int changeType, const wxFileName &path, const wxFileName &newPath) |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here. | |
virtual void | OnWarning (const wxString &errorMessage) |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here. | |
virtual void | OnError (const wxString &errorMessage) |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here. |
wxFileSystemWatcher::wxFileSystemWatcher | ( | ) |
Default constructor.
If you create file system watcher using it you have to either call SetOwner() and connect an event handler or override OnChange(), OnWarning() and OnError().
virtual wxFileSystemWatcher::~wxFileSystemWatcher | ( | ) | [virtual] |
Destructor.
Stops all paths from being watched and frees any system resources used by this file system watcher object.
virtual bool wxFileSystemWatcher::Add | ( | const wxFileName & | path, | |
int | events = wxFSW_EVENT_ALL | |||
) | [virtual] |
Adds path to currently watched files.
Optionally a filter can be specified to receive only events of particular type.
Any events concerning this particular path will be sent either to connected handler or passed to OnChange(), OnWarning() or OnError().
virtual bool wxFileSystemWatcher::AddTree | ( | const wxFileName & | path, | |
int | events = wxFSW_EVENT_ALL , |
|||
const wxString & | filter = wxEmptyString | |||
) | [pure virtual] |
This is the same as Add(), but recursively adds every file/directory in the tree rooted at path.
Additionally a file mask can be specified to include only files matching that particular mask.
int wxFileSystemWatcher::GetWatchedPathCount | ( | ) | const |
Returns the number of watched paths.
int wxFileSystemWatcher::GetWatchedPaths | ( | wxArrayString * | paths | ) | const |
Retrieves all watched paths and places them in paths.
Returns the number of watched paths, which is also the number of entries added to paths.
virtual void wxFileSystemWatcher::OnChange | ( | int | changeType, | |
const wxFileName & | path, | |||
const wxFileName & | newPath | |||
) | [protected, virtual] |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here.
Perform whatever action which is to be taken on file system change.
virtual void wxFileSystemWatcher::OnError | ( | const wxString & | errorMessage | ) | [protected, virtual] |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here.
Perform whatever action which is to be taken when an error condition arises.
virtual void wxFileSystemWatcher::OnWarning | ( | const wxString & | errorMessage | ) | [protected, virtual] |
You may either connect your event handler to intercept file system watcher events or override this member and handle them here.
Perform whatever action which is to be taken when a warning condition arises.
virtual bool wxFileSystemWatcher::Remove | ( | const wxFileName & | path | ) | [virtual] |
Removes path from the list of watched paths.
virtual bool wxFileSystemWatcher::RemoveAll | ( | ) | [virtual] |
Clears the list of currently watched paths.
virtual bool wxFileSystemWatcher::RemoveTree | ( | const wxFileName & | path | ) | [virtual] |
Same as Remove(), but also removes every file/directory belonging to the tree rooted at path.
void wxFileSystemWatcher::SetOwner | ( | wxEvtHandler * | handler | ) |
Associates the file system watcher with the given handler object.
Basically this means that all events will be passed to this handler object unless you have change the default behaviour by overriding OnChange(), OnWarning() or OnError().
![]() |
[ top ] |