meson.build.o7QLX02
[roobuilder] / src / Project / GtkValaSettings.vala
1 namespace Project 
2 {
3 // an object describing a build config (or generic ...)
4         public class GtkValaSettings : Object {
5                 public string name { get; set; }
6  
7                 
8                 Gtk project;
9
10                 public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
11  
12
13                 public string execute_args;
14                 
15                 public bool loading_ui = true;
16                 
17                 public GtkValaSettings(Gtk project, string name) 
18                 {
19                         this.name = name;
20                         this.project = project;
21  
22                  
23                         this.sources = new Gee.ArrayList<string>();
24                         this.execute_args = "";
25                                 
26                 }
27                  
28                 public GtkValaSettings.from_json(Gtk project, Json.Object el) {
29
30                         this.project = project;
31                         this.name = el.get_string_member("name");
32  
33                         if ( el.has_member("execute_args")) {
34                                 this.execute_args = el.get_string_member("execute_args");
35                         } else {
36                                 this.execute_args = "";
37                    }
38                         // sources and packages.
39                         this.sources = this.filterFiles(this.project.readArray(el.get_array_member("sources")));
40                         
41
42                 }
43                 
44                 // why not array of strings?
45                 
46                 
47                 
48                 public Json.Object toJson()
49                 {
50                         var ret = new Json.Object();
51                         ret.set_string_member("name", this.name);
52                         ret.set_string_member("execute_args", this.execute_args);
53  
54                         ret.set_array_member("sources", this.writeArray( this.filterFiles(this.sources)));
55  
56
57                         return ret;
58                 }
59                 public Json.Array writeArray(Gee.ArrayList<string> ar) {
60                         var ret = new Json.Array();
61                         for(var i =0; i< ar.size; i++) {
62                                 ret.add_string_element(ar.get(i));
63                         }
64                         return ret;
65                 }
66                 public bool has_file(JsRender.JsRender file)
67                 {
68                         
69                         GLib.debug("Checking %s has file %s", this.name, file.path);
70                         var pr = (Gtk) file.project;
71                         for(var i = 0; i < this.sources.size;i++) {
72                                 var path = pr.path + "/" +  this.sources.get(i);
73                                 GLib.debug("check %s", path);
74                                 
75                                 if (path == file.path) {
76                                         GLib.debug("GOT IT");
77                                         return true;
78                                 }
79                         }
80                         GLib.debug("CANT FIND IT");
81                         return false;
82                 
83                 }
84                 
85                 public Gee.ArrayList<string> filterFiles( Gee.ArrayList<string> ar)
86                 {
87                         var ret = new Gee.ArrayList<string>();
88                         foreach(var f in ar) {
89                                 if (null == this.project.getByRelPath(f)) {
90                                         continue;
91                                 }
92                                 ret.add(f);
93                         }
94                         return ret;
95                 }
96                 
97         }
98  }