source: libi4uc/i4ucbuilder.vala @ e20be4a7bb7f7ce258435a7e11766c564c2abbc0

Revision e20be4a7bb7f7ce258435a7e11766c564c2abbc0, 2.2 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/* i4ucbuilder.vala
2 *
3 * Copyright (C) 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.Builder : GLib.Object
24{
25        private const string _I4UC_BUILDER = "i4uc builder";
26       
27        private Document _builder_file = new Document ();
28        private HashMap<string, BuilderDeviceType> _device_types = new HashMap<string, BuilderDeviceType> ();
29       
30        public string id { set; get; }
31        public Gee.Map<string, BuilderDeviceType> device_types { get { return _device_types; } }
32       
33        public bool open (string uri) throws GLib.Error, GLib.KeyFileError
34        {
35                var builder_content = _builder_file.load_contents (uri);
36                var key_file = new KeyFile ();
37                if (!key_file.load_from_data (builder_content, builder_content.length, KeyFileFlags.NONE) ||
38                    key_file.get_start_group () != _I4UC_BUILDER)
39                        return false;
40               
41                this.id = key_file.get_string (_I4UC_BUILDER, "id");
42               
43                foreach (var device_type in key_file.get_string_list (_I4UC_BUILDER, "device_types"))
44                        if (key_file.has_group (@"$device_type device type"))
45                                _device_types[device_type] = new BuilderDeviceType.from_key_file (key_file, @"$device_type device type");
46               
47                return true;
48        }
49       
50        public void save (string? uri = null) throws GLib.Error
51        {
52                var key_file = new KeyFile ();
53               
54                key_file.set_string (_I4UC_BUILDER, "id", _id);
55                key_file.set_string_list (_I4UC_BUILDER, "device_types", _device_types.keys.to_array ());
56               
57                foreach (var device_type in _device_types.values)
58                        device_type.to_key_file (key_file, @"$(device_type.device_type) device type");
59               
60                _builder_file.save_contents (key_file.to_data (null), uri);
61        }
62}
Note: See TracBrowser for help on using the repository browser.