source: libi4uc/i4ucproject.vala @ e20be4a7bb7f7ce258435a7e11766c564c2abbc0

Revision e20be4a7bb7f7ce258435a7e11766c564c2abbc0, 3.1 KB checked in by Matias De la Puente <mfpuente.ar@…>, 3 years ago (diff)

Fix several vala warnings

  • Property mode set to 100644
Line 
1/* i4ucproject.vala
2 *
3 * Copyright (C) 2009-2010  Matias De la Puente
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 *      Matias De la Puente <mfpuente.ar@gmail.com>
20 */
21using Gee;
22
23public class I4uc.Project : GLib.Object
24{
25        private const string _I4UC_PROJECT = "i4uc project";
26       
27        private Document _project_file = new Document ();
28        private ArrayList<string> _authors = new ArrayList<string> ();
29        private ArrayList<string> _files = new ArrayList<string> ();
30        private HashMap<string, ProjectProfile> _profiles = new HashMap<string, ProjectProfile> ();
31       
32        public string name { set; get; }
33        public string uri { owned get { return _project_file.uri; } }
34        public string folder_uri { owned get { return _project_file.folder; } }
35        public Gee.List<string> authors { get { return _authors; } }
36        public Gee.List<string> files { get { return _files; } }
37        public Gee.Map<string, ProjectProfile> profiles { get { return _profiles; } }
38       
39        public bool open (string uri) throws GLib.Error, GLib.KeyFileError
40        {
41                var project_content = _project_file.load_contents (uri);
42                var key_file = new KeyFile ();
43                if (!key_file.load_from_data (project_content, project_content.length, KeyFileFlags.NONE) ||
44                    key_file.get_start_group () != _I4UC_PROJECT)
45                        return false;
46               
47                this.name = key_file.get_string (_I4UC_PROJECT, "name");
48               
49                var authors = key_file.get_string_list (_I4UC_PROJECT, "authors");
50                _authors.clear ();
51                foreach (var author in authors)
52                        _authors.add (author);
53               
54                var files = key_file.get_string_list (_I4UC_PROJECT, "files");
55                _files.clear ();
56                foreach (var file in files)
57                        _files.add (file);
58               
59                var profiles = key_file.get_string_list (_I4UC_PROJECT, "profiles");
60                _profiles.clear ();
61                foreach (var profile in profiles)
62                        if (key_file.has_group (@"$profile profile"))
63                                _profiles[profile] = new ProjectProfile.from_key_file (key_file, @"$profile profile");
64               
65                return true;
66        }
67       
68        public void save (string? uri = null)
69        {
70                var key_file = new KeyFile ();
71               
72                key_file.set_string (_I4UC_PROJECT, "name", _name);
73                key_file.set_string_list (_I4UC_PROJECT, "authors", _authors.to_array ());
74                key_file.set_string_list (_I4UC_PROJECT, "files", _files.to_array ());
75                key_file.set_string_list (_I4UC_PROJECT, "profiles", _profiles.keys.to_array ());
76               
77                foreach (var profile in _profiles.values)
78                        profile.to_key_file (key_file, @"$(profile.name) profile");
79               
80                _project_file.save_contents (key_file.to_data (null), uri);
81        }
82       
83        public string? get_file_uri (string file)
84        {
85                return File.new_for_uri (this.folder_uri).get_child_for_display_name (file).get_uri ();
86        }
87}
Note: See TracBrowser for help on using the repository browser.