Attribute changed old-javascript
[app.Builder.js] / old-javascript / Builder4 / Application.vala
1
2
3 namespace Builder4
4 {
5
6         public class AppSettings : Object
7         {
8
9                 // what are we going to have as settings?
10                 public string roo_html_dir { get; set; }
11
12                 public AppSettings()
13                 {
14                         this.notify.connect(() => {
15                                 this.save();
16                         });
17                 }
18
19                 public static AppSettings factory()
20                 {
21                          
22                         var setting_file = Application.configDirectory() + "/builder.settings";
23                         
24                         if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
25                                  return new AppSettings();
26                         }
27                         string data; 
28                         FileUtils.get_contents(setting_file, out data);
29                         return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
30                 }
31                 public void save()
32                 {
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);
38                 }
39
40                 
41         }
42         
43         
44         public static Application application = null;
45         
46         public class Application : Gtk.Application
47         {
48                 enum Target {
49                     INT32,
50                     STRING,
51                     ROOTWIN
52                 }
53
54
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 }
61                 };
62                 public AppSettings settings = null;
63
64         
65                 public Application ()
66                 {
67                         Object(
68                                application_id: "org.roojs.app-builder",
69                                 flags: ApplicationFlags.FLAGS_NONE
70                         );
71                                          
72                         configDirectory();
73                         this.settings = AppSettings.factory();  
74
75                         this.initResources(true); 
76                 
77
78                 }
79
80
81                 
82                 public static Application  singleton()
83                 {
84                         if (application==null) {
85                                 application = new Application();
86  
87                         
88                         }
89                         return application;
90                 }
91
92                 
93                 public static string configDirectory()
94                 {
95                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
96                 
97                         if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
98                                 var dir = File.new_for_path(dirname);
99                                 dir.make_directory();    
100                         }
101                         if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
102                                 var dir = File.new_for_path(dirname + "/resources");
103                                 dir.make_directory();    
104                         }
105
106                 
107                         return dirname;
108                 }
109         
110
111                 public void initResources(bool force = false)
112                 {
113                         // files to fetch from resources.
114                         string[] res = { 
115                                 "bootstrap.builder.html",
116                                 "roo.builder.html",
117                                 "roo.builder.js",
118                                 "Gir.overides"
119                         };
120                         for (var i = 0; i < res.length; i++ ) { 
121                                 this.fetchResource(res[i], force);
122                         }
123                         this.fetchResourceFrom (
124                                 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=Palete/RooUsage.txt",
125                                 "RooUsage.txt",
126                                 force
127                         );
128                         this.fetchResourceFrom (
129                                 "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=Palete/GtkUsage.txt",
130                                 "GtkUsage.txt",
131                                 force
132                         );
133                         this.fetchResourceFrom (
134                                 "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json",
135                                 "roodata.json",
136                                 force
137                         );
138                         
139
140                 }
141                 public void fetchResource(string res, bool force) {
142                         if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
143                                 return;
144                         }
145                         this.fetchResourceFrom(
146                                "http://git.roojs.org/?p=app.Builder.js;a=blob_plain;f=resources/" + res,
147                                res,
148                                force
149                        );
150                         
151
152                 }
153
154                 public void fetchResourceFrom(string src, string res, bool force) {
155                         if (!force && FileUtils.test(configDirectory() + "/resources/" + res, FileTest.EXISTS)) {
156                                 return;
157                         }
158                         // fetch...
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", 
163                                 src
164                         );
165
166                             // send the HTTP request and wait for response
167                          session.send_message (message);
168
169                             // output the XML result to stdout
170                         FileUtils.set_contents(
171                                configDirectory() + "/resources/" + res,
172                               (string) message.response_body.data
173                         );
174
175
176                 }
177                 
178         } 
179
180
181         
182         
183
184
185                 
186         
187 }