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(JSON.stringify(info));
102 // print("NAME: " + info.get_name());
104 var info_type = info.get_type();
105 // print("Type: " + info_type);
107 case GI.InfoType.OBJECT:
108 ret.objects.push(info.get_name());
109 this.clsGatherInterfaces(ns , info.get_name());
111 case GI.InfoType.INTERFACE:
112 ret.interfaces.push(info.get_name());
114 case GI.InfoType.FUNCTION:
115 new imports.Method.Method(info, ret, 'functions', []);
118 case GI.InfoType.CALLBACK:
119 // new Introspect.Callback(info, ret, 'callbacks', []);
122 case GI.InfoType.ENUM:
123 case GI.InfoType.FLAGS:
124 ret.enums.push(info.get_name());
126 case GI.InfoType.STRUCT:
127 if (GI.struct_info_is_gtype_struct (info)) {
131 ret.structs.push(info.get_name());
133 case GI.InfoType.UNION:
134 ret.unions.push(info.get_name());
136 case GI.InfoType.CONSTANT:
137 new imports.Constant.Constant(info, ret, 'values', []);
146 //print ("SCAN NAMESPACES ALL DONE");
148 var gi = GI.Repository.get_default();
149 var ver = gi.get_version(ns);
150 var pth = GI.Repository.get_search_path ();
151 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
153 ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
154 ret.gir_filename = ns + '-' + ver + '.gir';
156 //console.dump(this.ifaceList);
163 // store all the interfaces, so we can show a list of them later...
164 // called when you list the namespace
165 clsGatherInterfaces : function(ns, cls)
167 // print("clsGatherInterfaces: " + ns + ", " + cls);
168 var gi = GI.Repository.get_default();
169 var bb = gi.find_by_name(ns, cls);
170 var fullname = ns+'.'+cls;
171 this.ifaceList = this.ifaceList || { };
174 for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
176 var prop = GI.object_info_get_interface(bb,i);
178 var add = prop.get_namespace() +'.' + prop.get_name();
179 this.ifaceList[add] = this.ifaceList[add] || [];
180 if (this.ifaceList[add].indexOf(fullname) < 0) {
181 this.ifaceList[add].push(fullname);
193 doc : function(what) {
194 //print ("DOC: + " +what);
195 var ns = what.split('.').shift();
197 this.commentLoad(ns);
198 return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
206 commentLoad : function(ns)
209 if (typeof(this.comments[ns]) != 'undefined') {
213 console.log("LOAD DOCS: " + ns);
214 var gi = GI.Repository.get_default();
215 var ver = gi.get_version(ns);
217 this.comments[ns] = {};
222 // no idea why this is broken on my build system.
223 var getAttribute = function(n, name){
224 var properties = n.properties;
226 if (properties.name == name)
227 return properties.children.content;
228 properties = properties.next
234 function walk (element, path) {
241 var n = getAttribute(element, 'name') ;
242 //console.log("WALK" + n);
243 if (element.name == 'signal') {
248 path += path.length ? '.' : '';
251 if (element.name == 'return-value') {
252 path += '.return-value';
255 var d = getAttribute(element,'doc');
257 // Seed.print(path + ':' + d);
261 var child = element.children;
264 //console.log(child.tag);
265 if (child.type == "element"){
272 var pth = GI.Repository.get_search_path ();
275 var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
279 var fn = gir_path + '/'+ ns + '-' + ver + '.gir';
282 if (!GLib.file_test(fn, GLib.FileTest.EXISTS)) {
283 console.log('missing docc file ' + fn);
284 this.comments[ns] = {};
288 var doc = xml.parseFile(fn);
289 //console.log("xmldoc?" + doc);
292 this.comments[ns] = ret;
296 factory : function(type, ns, name) {
297 if (typeof (this.registry[ns +'.' + name]) == 'undefined') {
298 this.registry[ns +'.' + name] = new imports[type][type](ns,name);
299 this.registry[ns +'.' + name].load();
302 return this.registry[ns +'.' + name];