1 //<Script type="text/javascript">
3 * Monitor class - handles monitor managment for a large tree...
12 * x.stop() // stops all scanning.
13 * x.play(); // starts the scanning
21 Monitor = function(cfg){
35 monitors : false, // Array of GioFileMonitors
36 top : false, // list of top level directories..
38 * add a directory or file to monitor
49 this.top.forEach(this.monitor, this);
52 * stop / pause monitoring
57 this.monitors.foreach(function(m) {
63 * monitor a file or directory (privatish)
67 function monitor(path, fn)
70 fn = fn || function (fm, f, of, event_type, uh) {
71 _this.onEvent(fm, f, of, event_type, uh);
74 var f = Gio.file_new_for_path(path);
75 //var cancel = new Gio.Cancellable ();
76 var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
77 fm.signal.changed.connect(fn);
78 this.monitors.push(fm);
81 var file_enum = f.enumerate_children(
82 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+
83 Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
84 Gio.FileQueryInfoFlags.NONE,
87 while ((next_file = file_enum.next_file(null)) != null) {
89 if (next_file.get_file_type() != Gio.FileType.DIRECTORY) {
92 if (next_file.get_display_name()[0] == '.') {
95 this.monitor(path+'/'+next_file.get_display_name(), fn)
98 file_enum.close(null);
101 function onEvent(fm, f, of, event_type, uh)
104 name : f.get_basename(),
108 name : of.get_basename(),
109 path : of.get_path(),
113 case Gio.FileMonitorEvent.CHANGED:
115 return; // ingore thise?? -wait for changes_done_htin?
117 case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
118 this.onChangesDoneHint(src);
121 case Gio.FileMonitorEvent.DELETED:
125 case Gio.FileMonitorEvent.CREATED:
129 case Gio.FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
130 this.onAttributeCreated(src);
133 case Gio.FileMonitorEvent.MOVED: // eg. chmod/chatt
134 this.onMoved(src,dest);
137 // rest are mount related - not really relivant.. maybe add later..
141 /** override these to do stuff.. */
143 function onChanged(src) { },
144 function onChangesDoneHint(src) { },
145 function onDeleted(src) { },
146 function onCreated(src) { },
147 function onMoved(src) { },