4 * Idea is to manage resourse used by the app.
6 * The original code downloaded all the resources before it renders the main window
8 * This is a bit annoying as although they do change quite a bit, it's not on every app start
10 * So the Resource fetching behaviour should be a button on the File view page
11 * That starts the refresh of the resources.
13 * I'm not quite sure how we should flow this - if we do them all at once.. might be a bit of a server
14 * overload... so sequentially may be best...
17 public class ResourcesItem : Object {
20 public ResourcesItem(string src, string target)
24 print("New ResourcesItem %s => %s\n", target ,src);
30 public class Resources : Object
33 public signal void updateProgress(uint cur_pos);
35 static Resources singleton_val;
38 Gee.ArrayList<ResourcesItem> fetch_files;
40 public static Resources singleton()
42 if (singleton_val == null) {
43 singleton_val = new Resources();
54 "bootstrap.builder.html",
61 //"Editors/Editor.Roo.grid.GridPanel.js"
63 this.fetch_files = new Gee.ArrayList<string>();
64 for (var i=0;i < avail_files.length; i++) {
65 var target = avail_files[i];
66 var src = "https://raw.githubusercontent.com/roojs/app.Builder.js/master/resources/" + target;
68 if (target == "roodata.json") {
69 src = "https://raw.githubusercontent.com/roojs/roojs1/master/docs/json/roodata.json";
70 //src = "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json";
72 if (target.contains('*')) {
73 var split = target.split('*');
74 src = "https://api.github.com/repos/roojs/app.Builder.js/contents/resources/" + split[0];
77 this.fetch_files.add(new ResourcesItem(src,target));
87 public void fetchStart()
89 if (this.fetch_pos > 0) { // only fetch one at a time...
96 public void fetchNext()
98 var cur = this.fetch_pos;
100 this.updateProgress(this.fetch_pos); // min=0;
103 if (this.fetch_pos > this.fetch_files.size) {
104 this.updateProgress(0);
110 this.fetchResourceFrom ( src, target );
114 public void checkResources()
116 bool needsload = false;
117 string[] res = this.fetch_files;
119 for (var i = 0; i < this.fetch_files.length; i++ ) {
122 BuilderApplication.configDirectory() + "/resources/" + this.fetch_files.get(i).target
134 public void parseDirectory(string json, string target)
136 var pa = new Json.Parser();
137 pa.load_from_file(json);
138 var node = pa.get_root();
139 if (node.get_node_type () != Json.NodeType.ARRAY) {
141 //throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
144 var split = target.split('*');
145 var obj = node.get_array ();
146 for(var i = 0; i < node.get_length(); i++) {
147 var ob = node.get_object_element(i);
148 var n = ob.get_string_member("name");
150 if (split.length > 1 && !name.has_suffix(split[1])) {
154 if (this.files_has_target(split[0] + n)) {
157 var src = "https://raw.githubusercontent.com/roojs/app.Builder.js/master/resources/" + split[0] + n;
158 this.fetch_files.add(new ResourcesItem(src, split[0] + n);
162 public bool files_has_target(string target)
164 for (var i = 0; i < this.fetch_files.length; i++ ) {
165 if (this.fetch_files.get(i).target == target) {
176 public void fetchResourceFrom(ResourcesItem item)
180 print("downloading %s \nto : %s\n", item.src,item.target);
181 var session = new Soup.Session ();
182 session.user_agent = "App Builder ";
183 var message = new Soup.Message ("GET", item.src );
184 session.queue_message (message, (sess, mess) => {
186 if (item.target.contains('*')) {
187 // then it's a directory listing in JSON, and we need to add any new items to our list..
188 // it's used to fetch Editors (and maybe other stuff..)
189 this.parseDirectory((string) message.response_body.data,item.target );
195 var tfn = BuilderApplication.configDirectory() + "/resources/" + target;
198 // create parent directory if needed
199 if (!GLib.FileUtils.test (GLib.Path.get_dirname(tfn), FileTest.IS_DIR)) {
200 var f = GLib.File.new_for_path(GLib.Path.get_dirname(tfn));
201 f.make_directory_with_parents ();
207 // set data??? - if it's binary?
208 FileUtils.set_contents( tfn, (string) message.response_body.data );
210 switch (item.target) {
212 Palete.Gir.factory("Gtk").loadOverrides(true);
216 Palete.factory("Gtk").load();
220 Palete.factory("Roo").classes = null;
221 Palete.factory("Roo").load();