blob: da229ca695f70139181739d06448084109551cd4 [file] [log] [blame] [view]
Jared Lindblomd5ba95f2013-01-12 22:50:09 -08001Overview:
2
3FileSystemWatcher reports changes that are made to a monitored directory by signaling a registered callback function and passing that function a list of changes that have occurred. Each element of the list represents a file and the action that was performed on that file.
4
5Example:
6
7 ADDED: /Users/jared/Desktop/test.txt
8
9The list is held in a vector of type sEventInfo, where sEventInfo is a struct defined as follows:
10
11 enum eEvent {
12 ADDED = 0,
13 MODIFIED,
14 DELETED
15 };
16
17 struct sEventInfo {
18 eEvent event;
19 std::string absFilePath;
20 };
21
22The eEvent enumerator specifies the action taken on the file and the string absFilePath is the absolute file path of the file.
23
24Usage:
25
26SimpleEventCatcher is a dummy class that serves as an example of how to register for signals from FileSystemWatcher. These are the basic steps:
27
28 // invoke file system watcher on specified path
29 FileSystemWatcher watcher("/Users/jared/Desktop");
30
31 // pass the instance of FileSystemWatcher to the class
32 // that will register for event notifications
33 SimpleEventCatcher dirEventCatcher(&watcher);
34
35 // register for directory event signal (callback function)
36 QObject::connect(watcher, SIGNAL(dirEventSignal(std::vector<sEventInfo>)), this,
37 SLOT(handleDirEvent(std::vector<sEventInfo>)));
38
39 // implement handleDirEvent
40 void SimpleEventCatcher::handleDirEvent(std::vector<sEventInfo>)
41 {
42 /* implementation here */
43 }
44
45Debug:
46
47The debug flag can be set in filesystemwatcher.h. It is set to 1 by default and outputs the following information to the console:
48
49[BOOTSTRAP]
50
51[TIMER] Triggered Path: "/Users/jared/Desktop"
52 "ADDED: /Users/jared/Desktop/test2.txt"
53 "ADDED: /Users/jared/Desktop/test.txt"
54
55[SIGNAL] From SimpleEventCatcher Slot:
56 "ADDED: /Users/jared/Desktop/test2.txt"
57 "ADDED: /Users/jared/Desktop/test.txt"
58
59[\BOOTSTRAP]
60
61[WATCHER] Triggered Path: "/Users/jared/Desktop"
62 "DELETED: /Users/jared/Desktop/test2.txt"
63
64[SIGNAL] From SimpleEventCatcher Slot:
65 "DELETED: /Users/jared/Desktop/test2.txt"