1 //<Script type="text/javascript">
3 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 Monitor = function(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)
74 fn = fn || function (fm, f, of, event_type, uh) {
75 _this.onEvent(fm, f, of, event_type, uh);
78 var f = Gio.file_new_for_path(path);
79 //var cancel = new Gio.Cancellable ();
80 var fm = f.monitor(2,null); //Gio.FileMonitorFlags.SEND_MOVED
81 fm.signal.changed.connect(fn);
82 this.monitors.push(fm);
85 var file_enum = f.enumerate_children(
86 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ','+
87 Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
88 Gio.FileQueryInfoFlags.NONE,
91 while ((next_file = file_enum.next_file(null)) != null) {
93 if (next_file.get_file_type() != Gio.FileType.DIRECTORY) {
96 if (next_file.get_display_name()[0] == '.') {
99 this.monitor(path+'/'+next_file.get_display_name(), fn)
102 file_enum.close(null);
105 onEvent : function(fm, f, of, event_type, uh)
108 name : f.get_basename(),
110 dir : GLib.path_get_dirname(of.get_path())
113 name : of.get_basename(),
114 path : of.get_path(),
115 dir : GLib.path_get_dirname(of.get_path())
119 case Gio.FileMonitorEvent.CHANGED:
121 return; // ingore thise?? -wait for changes_done_htin?
123 case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
124 this.onChangesDoneHint(src);
127 case Gio.FileMonitorEvent.DELETED:
131 case Gio.FileMonitorEvent.CREATED:
135 case Gio.FileMonitorEvent.ATTRIBUTE_CHANGED: // eg. chmod/chatt
136 this.onAttributeCreated(src);
139 case Gio.FileMonitorEvent.MOVED: // eg. chmod/chatt
140 this.onMoved(src,dest);
143 // rest are mount related - not really relivant.. maybe add later..
147 /** override these to do stuff.. */
149 onChanged : function(src) { },
150 onChangesDoneHint : function(src) { },
151 onDeleted : function(src) { },
152 onCreated : function(src) { },
153 onAttributeChanged : function(src) { },
154 onMoved : function(src) { }