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)
69 * initially called with ~/gitlive null 0 (effectvely)
73 monitor : function(path, fn, depth)
78 depth = typeof(depth) == 'number' ? depth *1 : 0;
81 fn = fn || function (fm, f, of, event_type, uh) {
82 _this.onEvent(fm, f, of, event_type, uh);
85 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
86 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
93 var f = Gio.file_new_for_path(path);
94 //var cancel = new Gio.Cancellable ();
96 var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
97 fm.signal.changed.connect(fn);
98 this.monitors.push(fm);
99 // print("ADD path " + depth + ' ' + path);
103 if (GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR) && this.initRepo) {
109 var file_enum = f.enumerate_children(
110 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+
111 Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
112 Gio.FileQueryInfoFlags.NONE,
117 while ((next_file = file_enum.next_file(null)) != null) {
119 if (next_file.get_file_type() != Gio.FileType.DIRECTORY) {
122 if (next_file.get_display_name()[0] == '.') {
125 var sp = path+'/'+next_file.get_display_name();
129 this.monitor(sp, fn, depth + 1)
132 file_enum.close(null);
136 onEvent : function(fm, f, of, event_type, uh)
139 name : f.get_basename(),
141 dir : GLib.path_get_dirname(f.get_path())
144 name : of.get_basename(),
145 path : of.get_path(),
146 dir : GLib.path_get_dirname(of.get_path())
150 for(var i in Gio.FileMonitorEvent) {
151 if (Gio.FileMonitorEvent[i] == event_type) {
155 //print ("got event: " +event_name);
156 //print ("got src: " + src.toString());
157 //print ("got event: " + src.toString());
161 case Gio.FileMonitorEvent.CHANGED:
163 return; // ingore thise?? -wait for changes_done_htin?
165 case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
166 this.onChangesDoneHint(src);
169 case Gio.FileMonitorEvent.DELETED:
173 case Gio.FileMonitorEvent.CREATED:
177 case Gio.FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
178 this.onAttributeChanged(src);
181 case Gio.FileMonitorEvent.MOVED: // eg. chmod/chatt
182 this.onMoved(src,dest);
185 // rest are mount related - not really relivant.. maybe add later..
193 /** override these to do stuff.. */
194 initRepo : function(src) { }, // called on startup at the top level repo dir.
195 onChanged : function(src) { },
196 onChangesDoneHint : function(src) { },
197 onDeleted : function(src) { },
198 onCreated : function(src) { },
199 onAttributeChanged : function(src) { },
200 onMoved : function(src) { }