static int main (string[] args) {
// A reference to our file
var file = File.new_for_path ("data.txt");
-
+ var m = new Monitor();
+ return 0;
}
}
}
+public delegate void onEventHander (FileMonitor fm, File f_orig, File of_orig, FileMonitorEvent event_type);
+
+
/**
* Monitor class - handles monitor managment for a large tree...
*
public void start()
{
for(int i = 0; i < this.monitors.size ; i++) {
- this.monitor(this.top[i]);
+ this.monitor(this.top[i], ( fm, f_orig, of_orig, event_type) => {
+ this.onEvent (fm, f_orig, of_orig, event_type ) ;
+ } );
}
}
/**
*
*
*/
- public void monitor(string path, string fn, int depth)
+ public void monitor(string path, onEventHander fn , int depth = 0)
{
// print("ADD: " + path)
var f = File.new_for_path(path);
//var cancel = new Gio.Cancellable ();
- if (depth > 0) {
- var fm = f.monitor(FileMonitorFlags.SEND_MOVED,null); //Gio.FileMonitorFlags.SEND_MOVED
-
- fm.changed.connect( ( fm, f_orig, of_orig, event_type) => {
- this.onEvent (fm, f_orig, of_orig, event_type ) ;
- });
- this.monitors.add(fm, '', 0);
+ if (depth > 0) {
+ try {
+
+ var fm = f.monitor(FileMonitorFlags.SEND_MOVED,null); //Gio.FileMonitorFlags.SEND_MOVED
+
+ fm.changed.connect( ( fm, f_orig, of_orig, event_type) => {
+ //if (fn) {
+ fn (fm, f_orig, of_orig, event_type ) ;
+ // return;
+ //}
+ //this.onEvent (fm, f_orig, of_orig, event_type ) ;
+ });
+ this.monitors.add(fm);
+
+ } catch (Error e) {
+ // FIXME -- show error? do nothing..
+ }
// print("ADD path " + depth + ' ' + path);
}
// iterate children?
dest = new MonitorNamePathDir( of.get_basename(), of.get_path(), Path.get_dirname(of.get_path()));
}
- string event_name = "UKNOWN";
+ //string event_name = "UKNOWN";
// extract the event names ... - not sure if introspection is feasible in vala..