1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
6 File = imports.File.File;
8 XObject = imports.XObject.XObject;
10 console = imports.console.console;
14 GI.Repository = GI.IRepository;
15 GI.FunctionInfoFlags = GI.IFunctionInfoFlags ;
16 GI.InfoType = GI.IInfoType;
17 GI.TypeTag= GI.ITypeTag;
19 GI.IBaseInfo.prototype.get_name = function(n) {
20 return GI.base_info_get_name(this, n);
22 GI.IBaseInfo.prototype.get_namespace = function(n) {
23 return GI.base_info_get_namespace(this, n);
25 GI.IBaseInfo.prototype.get_attribute = function( n) {
26 return GI.base_info_get_attribute(this, n);
36 namespaces : function(ns)
38 // this should be a class of it's own...
39 this.references[ns] = []; // technically not needed - but fills in files..
40 // get this from GI... (it's the path..)
45 if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) {
48 File.list(dir).forEach(function(fn)
50 if (!fn.match(/\.typelib$/)) {
53 var par = fn.split('-').shift();
54 //console.log('trying ' + par);
55 if (ret.indexOf(par) > -1) {
62 var gi = GI.Repository.get_default();
63 var pth = GI.Repository.get_search_path();
74 var gi = GI.Repository.get_default();
76 titleType: 'Namespace',
87 // so ns looks like class..
89 extendsClasses : [], // what it extends...
90 childClasses : [], // what uses it..
94 values : [], /// really constants.
99 for (var i=0; i < gi.get_n_infos (ns); i++ ) {
100 var info = gi.get_info (ns, i);
101 // print("NAME: " + info.get_name());
103 var info_type = GI.base_info_get_type ? GI.base_info_get_type(info) : info.get_type();
104 // print("Type: " + info_type);
106 case GI.InfoType.OBJECT:
107 ret.objects.push(info.get_name());
108 this.clsGatherInterfaces(ns , info.get_name());
110 case GI.InfoType.INTERFACE:
111 ret.interfaces.push(info.get_name());
113 case GI.InfoType.FUNCTION:
114 new imports.Method.Method(info, ret, 'functions', []);
117 case GI.InfoType.CALLBACK:
118 // new Introspect.Callback(info, ret, 'callbacks', []);
121 case GI.InfoType.ENUM:
122 case GI.InfoType.FLAGS:
123 ret.enums.push(info.get_name());
125 case GI.InfoType.STRUCT:
126 if (GI.struct_info_is_gtype_struct (info)) {
130 ret.structs.push(info.get_name());
132 case GI.InfoType.UNION:
133 ret.unions.push(info.get_name());
135 case GI.InfoType.CONSTANT:
136 new imports.Constant.Constant(info, ret, 'values', []);
145 //print ("SCAN NAMESPACES ALL DONE");
147 var gi = GI.Repository.get_default();
148 var ver = gi.get_version(ns);
149 var pth = GI.Repository.get_search_path ();
150 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
152 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
153 ret.gir_filename = ns + '-' + ver + '.gir';
155 //console.dump(this.ifaceList);
162 // store all the interfaces, so we can show a list of them later...
163 // called when you list the namespace
164 clsGatherInterfaces : function(ns, cls)
166 // print("clsGatherInterfaces: " + ns + ", " + cls);
167 var gi = GI.Repository.get_default();
168 var bb = gi.find_by_name(ns, cls);
169 var fullname = ns+'.'+cls;
170 this.ifaceList = this.ifaceList || { };
173 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
175 var prop = GI.object_info_get_interface(bb,i);
177 var add = prop.get_namespace() +'.' + prop.get_name();
178 this.ifaceList[add] = this.ifaceList[add] || [];
179 if (this.ifaceList[add].indexOf(fullname) < 0) {
180 this.ifaceList[add].push(fullname);
192 doc : function(what) {
193 //print ("DOC: + " +what);
194 var ns = what.split('.').shift();
196 this.commentLoad(ns);
197 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
205 commentLoad : function(ns)
208 if (typeof(this.comments[ns]) != 'undefined') {
212 console.log("LOAD DOCS: " + ns);
213 var gi = GI.Repository.get_default();
214 var ver = gi.get_version(ns);
216 this.comments[ns] = {};
221 // no idea why this is broken on my build system.
222 var getAttribute = function(n, name){
223 var properties = n.properties;
225 if (properties.name == name)
226 return properties.children.content;
227 properties = properties.next
233 function walk (element, path) {
240 var n = getAttribute(element, 'name') ;
241 //console.log("WALK" + n);
242 if (element.name == 'signal') {
247 path += path.length ? '.' : '';
250 if (element.name == 'return-value') {
251 path += '.return-value';
254 var d = getAttribute(element,'doc');
256 // Seed.print(path + ':' + d);
260 var child = element.children;
263 //console.log(child.tag);
264 if (child.type == "element"){
271 var pth = GI.Repository.get_search_path ();
274 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
278 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
281 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
282 console.log('missing docc file ' + fn);
283 this.comments[ns] = {};
287 var doc = xml.parseFile(fn);
288 //console.log("xmldoc?" + doc);
291 this.comments[ns] = ret;
295 factory : function(type, ns, name) {
296 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
297 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
298 this.registry[ns +'.' + name].load();
301 return this.registry[ns +'.' + name];