tests/JsCoreExecTest.vala.c
[app.Builder.js] / src / Application.vala
1
2  
3         public class AppSettings : Object
4         {
5
6                 // what are we going to have as settings?
7                 public string roo_html_dir { get; set; }
8
9                 public AppSettings()
10                 {
11                         this.notify.connect(() => {
12                                 this.save();
13                         });
14                 }
15
16                 public static AppSettings factory()
17                 {
18                          
19                         var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
20                         
21                         if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
22                                  return new AppSettings();
23                         }
24                         string data; 
25                         FileUtils.get_contents(setting_file, out data);
26                         return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
27                 }
28                 public void save()
29                 {
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);
35                 }
36
37                 
38         }
39         
40         
41         public static BuilderApplication application = null;
42         
43         public class BuilderApplication : Gtk.Application
44         {
45                 enum Target {
46                     INT32,
47                     STRING,
48                     ROOTWIN
49                 }
50
51
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 }
58                 };
59                 public AppSettings settings = null;
60
61         
62                 public BuilderApplication ()
63                 {
64                         Object(
65                                application_id: "org.roojs.app-builder",
66                                 flags: ApplicationFlags.FLAGS_NONE
67                         );
68                                          
69                         configDirectory();
70                         this.settings = AppSettings.factory();  
71  
72
73                 }
74
75
76                 
77                 public static BuilderApplication  singleton()
78                 {
79                         if (application==null) {
80                                 application = new BuilderApplication();
81  
82                         
83                         }
84                         return application;
85                 }
86
87                 
88                 public static string configDirectory()
89                 {
90                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
91                 
92                         if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
93                                 var dir = File.new_for_path(dirname);
94                                 dir.make_directory();    
95                         }
96                         if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
97                                 var dir = File.new_for_path(dirname + "/resources");
98                                 dir.make_directory();    
99                         }
100
101                 
102                         return dirname;
103                 }
104           
105         } 
106
107
108         
109         
110
111