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();
111 public void initResources(bool force = false)
113 // files to fetch from resources.
115 "bootstrap.builder.html",
120 for (var i = 0; i < res.length; i++ ) {
121 this.fetchResource(res[i], force);
123 this.fetchResourceFrom (
124 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=Palete/RooUsage.txt",
128 this.fetchResourceFrom (
129 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=Palete/GtkUsage.txt",
133 this.fetchResourceFrom (
134 "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json",
141 public void fetchResource(string res, bool force) {
142 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
145 this.fetchResourceFrom(
146 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + res,
154 public void fetchResourceFrom(string src, string res, bool force) {
155 if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
159 print("downloading %s \nto : %s\n", src,res);
160 var session = new Soup.Session ();
161 session.user_agent = "App Builder ";
162 var message = new Soup.Message ("GET",
166 // send the HTTP request and wait for response
167 session.send_message (message);
169 // output the XML result to stdout
170 FileUtils.set_contents(
171 configDirectory() + "/resources/" + res,
172 (string) message.response_body.data