Monitor.vala
[gitlive] / Monitor.vala
index 8931342..1932ab0 100644 (file)
@@ -13,7 +13,7 @@ using Gee; // for array list?
 static int main (string[] args) {
     // A reference to our file
     var file = File.new_for_path ("data.txt");
-
+    return 0;
 
 }
 
@@ -33,6 +33,9 @@ public class  MonitorNamePathDir {
     }
 }
 
+static void onEventHander (FileMonitor fm, File f_orig, File of_orig, FileMonitorEvent event_type);
+
+
 /**
  * Monitor class - handles monitor managment for a large tree...
  *
@@ -83,7 +86,7 @@ public class Monitor : Object
      */
     public void start()
     {
-        foreach(var in in this.top) {
+        for(int i = 0; i < this.monitors.size ; i++) {
             this.monitor(this.top[i]);
         }
     }
@@ -94,7 +97,7 @@ public class Monitor : Object
     public void stop()
     {
         
-        foreach(var i in  this.monitors) {
+        for(int i = 0; i < this.monitors.size ; i++) {
             this.monitors[i].cancel();
         } 
         this.monitors = new ArrayList<FileMonitor>(); // clean /destroy/ kill old?
@@ -120,7 +123,7 @@ public class Monitor : Object
      * 
      * 
      */
-    public void monitor(string path, string fn, int depth)
+    public void monitor(string path, onEventHander fn = null, int depth = 0)
     {
          
        // print("ADD: " + path)
@@ -140,6 +143,10 @@ public class Monitor : Object
             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);
@@ -178,7 +185,7 @@ public class Monitor : Object
                 next_file = null;
                 continue;
             }
-            var sp = path+'/'+next_file.get_display_name();
+            var sp = path+"/"+next_file.get_display_name();
             // skip modules.
             //print("got a file : " + sp);
          
@@ -241,7 +248,7 @@ public class Monitor : Object
             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..