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) }
28 public class Resources : Object
31 public signal void updateProgress(uint cur_pos);
33 static Resources singleton_val;
36 Gee.ArrayList<ResourcesItem> fetch_files;
38 public static Resources singleton()
40 if (singleton_val == null) {
41 singleton_val = new Resources();
52 "bootstrap.builder.html",
59 //"Editors/Editor.Roo.grid.GridPanel.js"
61 this.fetch_files = new Gee.ArrayList<string>();
62 for (var i=0;i < avail_files.length; i++) {
63 var target = avail_files[i];
64 var src = "https://raw.githubusercontent.com/roojs/app.Builder.js/master/resources/" + target;
66 if (target == "roodata.json") {
67 src = "https://raw.githubusercontent.com/roojs/roojs1/master/docs/json/roodata.json";
68 //src = "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json";
70 if (target.contains('*')) {
71 var split = target.split('*');
72 src = "https://api.github.com/repos/roojs/app.Builder.js/contents/resources/" + split[0];
75 this.fetch_files.add(new ResourcesItem(src,target));
85 public void fetchStart()
87 if (this.fetch_pos > 0) { // only fetch one at a time...
94 public void fetchNext()
96 var cur = this.fetch_pos;
98 this.updateProgress(this.fetch_pos); // min=0;
101 if (this.fetch_pos > this.fetch_files.size) {
102 this.updateProgress(0);
108 this.fetchResourceFrom ( src, target );
112 public void checkResources()
114 bool needsload = false;
115 string[] res = this.fetch_files;
117 for (var i = 0; i < this.fetch_files.length; i++ ) {
120 BuilderApplication.configDirectory() + "/resources/" + this.fetch_files.get(i).target
136 public void fetchResourceFrom(ResourcesItem item)
140 print("downloading %s \nto : %s\n", item.src,item.target);
141 var session = new Soup.Session ();
142 session.user_agent = "App Builder ";
143 var message = new Soup.Message ("GET", item.src );
144 session.queue_message (message, (sess, mess) => {
147 var tfn = BuilderApplication.configDirectory() + "/resources/" + target;
148 // create parent directory if needed
149 if (!GLib.FileUtils.test (GLib.Path.get_dirname(tfn), FileTest.IS_DIR)) {
150 var f = GLib.File.new_for_path(GLib.Path.get_dirname(tfn));
151 f.make_directory_with_parents ();
155 // set data??? - if it's binary?
156 FileUtils.set_contents( tfn, (string) message.response_body.data );
158 switch (item.target) {
160 Palete.Gir.factory("Gtk").loadOverrides(true);
164 Palete.factory("Gtk").load();
168 Palete.factory("Roo").classes = null;
169 Palete.factory("Roo").load();