6 public class AppSettings : Object
9 // what are we going to have as settings?
10 public string roo_html_dir { get; set; }
14 this.notify.connect(() => {
19 public static AppSettings factory()
22 var setting_file = Application.configDirectory() + "/builder.settings";
24 if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
25 return new AppSettings();
28 FileUtils.get_contents(setting_file, out data);
29 return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
33 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
34 var setting_file = dirname + "/builder.settings";
35 string data = Json.gobject_to_data (this, null);
36 print("saving application settings\n");
37 FileUtils.set_contents(setting_file, data);
44 public static Application application = null;
46 public class Application : Gtk.Application
55 public const Gtk.TargetEntry[] targetList = {
56 { "INTEGER", 0, Target.INT32 },
57 { "STRING", 0, Target.STRING },
58 { "application/json", 0, Target.STRING },
59 { "text/plain", 0, Target.STRING },
60 { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
62 public AppSettings settings = null;
68 application_id: "org.roojs.app-builder",
69 flags: ApplicationFlags.FLAGS_NONE
73 this.settings = AppSettings.factory();
75 this.initResources(true);
82 public static Application singleton()
84 if (application==null) {
85 application = new Application();
93 public static string configDirectory()
95 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
97 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
98 var dir = File.new_for_path(dirname);
101 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
102 var dir = File.new_for_path(dirname + "/resources");
103 dir.make_directory();
110 public void initResources(bool force = false)
112 // files to fetch from resources.
114 "bootstrap.builder.html",
121 for (var i = 0; i < res.length; i++ ) {
122 this.fetchResource(res[i], force);
125 this.fetchResourceFrom (
126 "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json",
133 public void fetchResource(string res, bool force) {
134 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
137 this.fetchResourceFrom(
138 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + res,
146 public void fetchResourceFrom(string src, string res, bool force) {
147 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
151 print("downloading %s \nto : %s\n", src,res);
152 var session = new Soup.Session ();
153 session.user_agent = "App Builder ";
154 var message = new Soup.Message ("GET",
158 // send the HTTP request and wait for response
159 session.send_message (message);
161 // output the XML result to stdout
162 FileUtils.set_contents(
163 configDirectory() + "/resources/" + res,
164 (string) message.response_body.data