1 //<Script type="text/javascript">
2 var Gio = imports.gi.Gio;
3 var GLib = imports.gi.GLib;
7 * Monitor class - handles monitor managment for a large tree...
11 change : function () {
16 * x.stop() // stops all scanning.
17 * x.play(); // starts the scanning
25 function Monitor(cfg){
39 monitors : false, // Array of GioFileMonitors
40 top : false, // list of top level directories..
42 * add a directory or file to monitor
53 this.top.forEach(this.monitor, this);
56 * stop / pause monitoring
61 this.monitors.forEach(function(m) {
67 * monitor a file or directory (privatish)
71 monitor : function(path, fn, depth)
74 depth = depth ? depth *1 : 0;
75 fn = fn || function (fm, f, of, event_type, uh) {
76 _this.onEvent(fm, f, of, event_type, uh);
79 if (depth > 0 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
86 var f = Gio.file_new_for_path(path);
87 //var cancel = new Gio.Cancellable ();
88 var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
89 fm.signal.changed.connect(fn);
90 this.monitors.push(fm);
93 var file_enum = f.enumerate_children(
94 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+
95 Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
96 Gio.FileQueryInfoFlags.NONE,
99 //print("ADD path " + depth + ' ' + path);
101 while ((next_file = file_enum.next_file(null)) != null) {
103 if (next_file.get_file_type() != Gio.FileType.DIRECTORY) {
106 if (next_file.get_display_name()[0] == '.') {
109 var sp = path+'/'+next_file.get_display_name();
113 this.monitor(sp, fn, depth + 1)
116 file_enum.close(null);
120 onEvent : function(fm, f, of, event_type, uh)
123 name : f.get_basename(),
125 dir : GLib.path_get_dirname(f.get_path())
128 name : of.get_basename(),
129 path : of.get_path(),
130 dir : GLib.path_get_dirname(of.get_path())
134 for(var i in Gio.FileMonitorEvent) {
135 if (Gio.FileMonitorEvent[i] == event_type) {
139 //print ("got event: " +event_name);
140 //print ("got src: " + src.toString());
141 //print ("got event: " + src.toString());
145 case Gio.FileMonitorEvent.CHANGED:
147 return; // ingore thise?? -wait for changes_done_htin?
149 case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
150 this.onChangesDoneHint(src);
153 case Gio.FileMonitorEvent.DELETED:
157 case Gio.FileMonitorEvent.CREATED:
161 case Gio.FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
162 this.onAttributeChanged(src);
165 case Gio.FileMonitorEvent.MOVED: // eg. chmod/chatt
166 this.onMoved(src,dest);
169 // rest are mount related - not really relivant.. maybe add later..
177 /** override these to do stuff.. */
179 onChanged : function(src) { },
180 onChangesDoneHint : function(src) { },
181 onDeleted : function(src) { },
182 onCreated : function(src) { },
183 onAttributeChanged : function(src) { },
184 onMoved : function(src) { }