3 public class AppSettings : Object
6 // what are we going to have as settings?
7 public string roo_html_dir { get; set; }
11 this.notify.connect(() => {
16 public static AppSettings factory()
19 var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
21 if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
22 return new AppSettings();
25 FileUtils.get_contents(setting_file, out data);
26 return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
30 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
31 var setting_file = dirname + "/builder.settings";
32 string data = Json.gobject_to_data (this, null);
33 print("saving application settings\n");
34 FileUtils.set_contents(setting_file, data);
41 public static BuilderApplication application = null;
43 public class BuilderApplication : Gtk.Application
52 public const Gtk.TargetEntry[] targetList = {
53 { "INTEGER", 0, Target.INT32 },
54 { "STRING", 0, Target.STRING },
55 { "application/json", 0, Target.STRING },
56 { "text/plain", 0, Target.STRING },
57 { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
59 public AppSettings settings = null;
62 public BuilderApplication ()
65 application_id: "org.roojs.app-builder",
66 flags: ApplicationFlags.FLAGS_NONE
70 this.settings = AppSettings.factory();
72 this.initResources(true);
79 public static BuilderApplication singleton()
81 if (application==null) {
82 application = new BuilderApplication();
90 public static string configDirectory()
92 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
94 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
95 var dir = File.new_for_path(dirname);
98 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
99 var dir = File.new_for_path(dirname + "/resources");
100 dir.make_directory();
107 public void initResources(bool force = false)
109 // files to fetch from resources.
111 "bootstrap.builder.html",
118 for (var i = 0; i < res.length; i++ ) {
119 this.fetchResource(res[i], force);
122 this.fetchResourceFrom (
123 "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json",
130 public void fetchResource(string res, bool force) {
131 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
134 this.fetchResourceFrom(
135 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + res,
143 public void fetchResourceFrom(string src, string res, bool force) {
144 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
148 print("downloading %s \nto : %s\n", src,res);
149 var session = new Soup.Session ();
150 session.user_agent = "App Builder ";
151 var message = new Soup.Message ("GET",
155 // send the HTTP request and wait for response
156 session.send_message (message);
158 // output the XML result to stdout
159 FileUtils.set_contents(
160 configDirectory() + "/resources/" + res,
161 (string) message.response_body.data