Monitor.vala
[gitlive] / Monitor.vala
index 77b753f..5819e98 100644 (file)
@@ -5,7 +5,7 @@
 //var XObject = imports.XObject.XObject;
 //var File    = imports.File.File;
 
-
+/// # valac --pkg gee-0.8 --pkg gio-2.0  --pkg posix Monitor.val
 
  
 using Gee; // for array list?
@@ -18,7 +18,7 @@ static int main (string[] args) {
 }
 
 
-class  MonitorNamePathDir {
+public class  MonitorNamePathDir {
     
     public string name;
     public string path;
@@ -68,7 +68,7 @@ public class Monitor : Object
         this.paused = false;
     }
      
-    public ArrayList<FileMonitor> monitors;// Array of GioFileMonitors
+    public ArrayList<FileMonitor> monitors;// Array of MonitorNamePathDirileMonitors
     public ArrayList<string> top; // list of top level directories..
     public bool paused;
     /**
@@ -83,7 +83,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 +94,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?
@@ -139,7 +139,9 @@ public class Monitor : Object
         if (depth > 0) {     
             var fm = f.monitor(FileMonitorFlags.SEND_MOVED,null); //Gio.FileMonitorFlags.SEND_MOVED
             
-            fm.changed.connect(onEvent);
+            fm.changed.connect( ( fm,  f_orig,  of_orig,  event_type) => {
+                    this.onEvent (fm,  f_orig,  of_orig,  event_type ) ;
+            });
             this.monitors.add(fm);
             // print("ADD path " + depth + ' ' + path);
         }
@@ -150,11 +152,9 @@ public class Monitor : Object
         //    this.initRepo(path);
         //}
         
-        var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
-
+       
          var file_enum = f.enumerate_children(
-            FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+    FILE_ATTRIBUTE_STANDARD_TYPE,
+            FileAttribute.STANDARD_DISPLAY_NAME + "," +   FileAttribute.STANDARD_TYPE,
             0, // FileQueryInfoFlags.NONE,
             null);
         
@@ -164,12 +164,12 @@ public class Monitor : Object
          
             //print("got a file " + next_file.sudo () + '?=' + Gio.FileType.DIRECTORY);
             
-            if (next_file.get_file_type() != FILETYPE_DIRECTORY) {
+            if (next_file.get_file_type() != FileType.DIRECTORY) {
                 next_file = null;
                 continue;
             }
             
-            if (next_file.get_file_type() == FILETYPE_SYMBOLIC_LINK) {
+            if (next_file.get_file_type() ==FileType.SYMBOLIC_LINK) {
                 next_file = null;
                 continue;
             }
@@ -178,7 +178,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);
          
@@ -211,11 +211,11 @@ public class Monitor : Object
         
 // FIX ME - string split?/? 
         var bn = file.get_basename();
-        var ar =  file.get_path().to_string().split('/');
-        ar.pop();
-        var dirname = ar.join('/');
+        var ar =  file.get_path().split("/");
+        ar.resize(ar.length-1);
+        var dirname = string.joinv("/",ar );
         var rp = Posix.realpath(dirname);
-        return File.new_for_path(rp + '/' + bn);
+        return File.new_for_path(rp + "/" + bn);
         
     }
    
@@ -234,11 +234,11 @@ public class Monitor : Object
  
         
  
-        MonitorNamePathDir src = new MonitorNamePathDir( f.get_basename(), f.get_path() , GLib.path_get_dirname(f.get_path()));
+        MonitorNamePathDir src = new MonitorNamePathDir( f.get_basename(), f.get_path() , Path.get_dirname(f.get_path()));
         MonitorNamePathDir dest = null;
         
-        if (of) {
-            dest = new MonitorNamePathDir( of.get_basename(), of.get_path(),  GLib.path_get_dirname(of.get_path()));
+        if (of != null) {
+            dest = new MonitorNamePathDir( of.get_basename(), of.get_path(),  Path.get_dirname(of.get_path()));
             
         }
         string event_name = "UKNOWN";
@@ -257,27 +257,27 @@ public class Monitor : Object
         try {
                 
             switch(event_type) {
-                case Gio.FileMonitorEvent.CHANGED:
+                case FileMonitorEvent.CHANGED:
                     this.onChanged(src);
                     return; // ingore thise?? -wait for changes_done_htin?
                     
-                case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
+                case FileMonitorEvent.CHANGES_DONE_HINT:
                     this.onChangesDoneHint(src);
                     return;
                     
-                case Gio.FileMonitorEvent.DELETED:
+                case FileMonitorEvent.DELETED:
                     this.onDeleted(src);
                     return;
                     
-                case Gio.FileMonitorEvent.CREATED:
+                case FileMonitorEvent.CREATED:
                     this.onCreated(src);
                     return;
                 
-                case Gio.FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
+                case FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
                     this.onAttributeChanged(src);
                     return;
                 
-                case Gio.FileMonitorEvent.MOVED: // eg. chmod/chatt
+                case FileMonitorEvent.MOVED: // eg. chmod/chatt
                     this.onMoved(src,dest);
                     return; 
                 
@@ -296,7 +296,7 @@ public class Monitor : Object
     public void onDeleted(MonitorNamePathDir src) { }
     public void onCreated(MonitorNamePathDir src) { }
     public void onAttributeChanged(MonitorNamePathDir src) { }
-    public void onMoved(MonitorNamePathDir src) { }
+    public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
           
     
 }