1 #ifndef WXFILESYSTEMMONITOR_H
2 #define WXFILESYSTEMMONITOR_H
3 
4 
5 
6 #include <wx/wx.h>
7 
8 #define MONITOR_TERMINATE 0x010000
9 #define MONITOR_TOO_MANY_CHANGES 0x020000
10 #define MONITOR_ERROR 0x040000
11 #define MONITOR_FILE_CHANGED 0x001
12 #define MONITOR_FILE_DELETED 0x002
13 #define MONITOR_FILE_CREATED 0x004
14 //TODO: Decide if it is worth having these
15 #define MONITOR_FILE_ATTRIBUTES 0x080
16 #define MONITOR_FILE_STARTEXEC 0x010
17 #define MONITOR_FILE_STOPEXEC 0x020
18 
19 #define DEFAULT_MONITOR_FILTER MONITOR_FILE_CHANGED|MONITOR_FILE_DELETED|MONITOR_FILE_CREATED|MONITOR_FILE_ATTRIBUTES
20 
21 class DirMonitorThread;
22 
23 class wxDirectoryMonitor;
24 
25 ///////////////////////////////////////
26 // EVENT CODE /////////////////////////
27 ///////////////////////////////////////
28 
29 /*
30 Defines a wxDirectoryMonitorEvent with public member naming the path
31 monitored, the file or directory creating the event and the code for
32 the event. Also used to send Termination events (on win32)
33 
34 Also defines event table macro EVT_MONITOR_NOTIFY to notify the
35 caller of change events
36 */
37 
38 BEGIN_DECLARE_EVENT_TYPES()
39 DECLARE_LOCAL_EVENT_TYPE(wxEVT_MONITOR_NOTIFY, -1)
40 DECLARE_LOCAL_EVENT_TYPE(wxEVT_MONITOR_NOTIFY2, -1)
END_DECLARE_EVENT_TYPES()41 END_DECLARE_EVENT_TYPES()
42 
43 class wxDirectoryMonitorEvent: public wxNotifyEvent
44 {
45 public:
46     wxDirectoryMonitorEvent(const wxString &mon_dir, int event_type, const wxString &uri);
47     wxDirectoryMonitorEvent(const wxDirectoryMonitorEvent& c);
48     wxEvent *Clone() const { return new wxDirectoryMonitorEvent(*this); }
49     ~wxDirectoryMonitorEvent() {}
50     wxString m_mon_dir;
51     int m_event_type;
52     wxString m_info_uri;
53 };
54 
55 typedef void (wxEvtHandler::*wxDirectoryMonitorEventFunction)(wxDirectoryMonitorEvent&);
56 
57 #define EVT_MONITOR_NOTIFY(id, fn) \
58     DECLARE_EVENT_TABLE_ENTRY( wxEVT_MONITOR_NOTIFY, id, -1, \
59     (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) \
60     wxStaticCastEvent( wxDirectoryMonitorEventFunction, & fn ), (wxObject *) NULL ),
61 
62 ///////////////////////////////////////
63 // DIRECTORY MONITOR CLASS ////////////
64 ///////////////////////////////////////
65 
66 class wxDirectoryMonitor: public wxEvtHandler
67 {
68 public:
69     wxDirectoryMonitor(wxEvtHandler *parent, const wxArrayString &uri, int eventfilter=DEFAULT_MONITOR_FILTER);
70     virtual ~wxDirectoryMonitor();
71     bool Start();
72     void ChangePaths(const wxArrayString &uri);
73     void OnMonitorEvent(wxDirectoryMonitorEvent &e);
74     void OnMonitorEvent2(wxCommandEvent &e);
75 private:
76     wxArrayString m_uri;
77     wxEvtHandler *m_parent;
78     int m_eventfilter;
79     DirMonitorThread *m_monitorthread;
80     DECLARE_EVENT_TABLE()
81 };
82 
83 #endif // WXFILESYSTEMMONITOR_H
84