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 Resources : Object
20 public signal void updateProgress(uint cur_pos);
22 static Resources singleton_val;
25 Gee.ArrayList<string> fetch_files;
27 public static Resources singleton()
29 if (singleton_val == null) {
30 singleton_val = new Resources();
41 "bootstrap.builder.html",
47 "resources/Editors/*.js"
48 "Editors/Editor.Roo.grid.GridPanel.js"
50 this.fetch_files = new Gee.ArrayList<string>();
51 for (var i=0;i < avail_files.length; i++) {
52 this.fetch_files.add(avail_files[i]);
62 public void fetchStart()
64 if (this.fetch_pos > 0) { // only fetch one at a time...
71 public void fetchNext()
73 var cur = this.fetch_pos;
75 this.updateProgress(this.fetch_pos); // min=0;
78 if (this.fetch_pos > this.avail_files.length) {
79 this.updateProgress(0);
84 var target = this.avail_files[cur];
86 var src = "https://raw.githubusercontent.com/roojs/app.Builder.js/master/resources/" + target;
87 //var src = "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + target;
88 if (target == "roodata.json") {
89 src = "https://raw.githubusercontent.com/roojs/roojs1/master/docs/json/roodata.json";
90 //src = "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json";
93 if (target.contains('*')) {
94 var split = target.split('*');
95 src = "https://api.github.com/repos/roojs/app.Builder.js/contents/resources/Editors
98 this.fetchResourceFrom ( src, target );
102 public void checkResources()
104 bool needsload = false;
105 string[] res = this.avail_files;
107 for (var i = 0; i < res.length; i++ ) {
110 BuilderApplication.configDirectory() + "/resources/" + res[i],
126 public void fetchResourceFrom(string src, string target)
130 print("downloading %s \nto : %s\n", src,target);
131 var session = new Soup.Session ();
132 session.user_agent = "App Builder ";
133 var message = new Soup.Message ("GET", src );
134 session.queue_message (message, (sess, mess) => {
137 var tfn = BuilderApplication.configDirectory() + "/resources/" + target;
138 // create parent directory if needed
139 if (!GLib.FileUtils.test (GLib.Path.get_dirname(tfn), FileTest.IS_DIR)) {
140 var f = GLib.File.new_for_path(GLib.Path.get_dirname(tfn));
141 f.make_directory_with_parents ();
145 // set data??? - if it's binary?
146 FileUtils.set_contents( tfn, (string) message.response_body.data );
150 Palete.Gir.factory("Gtk").loadOverrides(true);
154 Palete.factory("Gtk").load();
158 Palete.factory("Roo").classes = null;
159 Palete.factory("Roo").load();