2 * config - zavai configuration
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 protected Lua.LuaVM lua;
26 protected weak string get_string(string name)
29 weak string res = lua.to_string(-1);
33 protected string set_string(string name, string? val)
42 protected weak int get_int(string name)
45 int res = lua.to_integer(-1);
49 protected int set_int(string name, int val)
51 lua.push_integer(val);
56 private string _version;
59 get { return _version; }
60 set { _version = set_string("version", value); }
63 // "phone" or "laptop"
64 private string _profile;
67 get { return _profile; }
68 set { _profile = set_string("profile", value); }
71 private string _homedir;
74 get { return _homedir; }
75 set { _homedir = set_string("homedir", value); }
78 private string _icondir;
81 get { return _icondir; }
82 set { _icondir = set_string("icondir", value); }
85 private int _min_button_height;
86 public int min_button_height
88 get { return _min_button_height; }
89 set { _min_button_height = set_int("min_button_height", value); }
92 private string _gpsd_host;
93 public string gpsd_host
95 get { return _gpsd_host; }
96 set { _gpsd_host = set_string("gpsd_host", value); }
99 private string _gpsd_port;
100 public string gpsd_port
102 get { return _gpsd_port; }
103 set { _gpsd_port = set_string("gpsd_port", value); }
106 private string _gprs_apn;
107 public string gprs_apn
109 get { return _gprs_apn; }
110 set { _gprs_apn = set_string("gprs_apn", value); }
113 private string _gprs_user;
114 public string gprs_user
116 get { return _gprs_user; }
117 set { _gprs_user = set_string("gprs_user", value); }
120 private string _gprs_pass;
121 public string gprs_pass
123 get { return _gprs_pass; }
124 set { _gprs_pass = set_string("gprs_pass", value); }
127 private int _power_button_keycode;
128 public int power_button_keycode
130 get { return _power_button_keycode; }
131 set { _power_button_keycode = set_int("power_button_keycode", value); }
134 private int _aux_button_keycode;
135 public int aux_button_keycode
137 get { return _aux_button_keycode; }
138 set { _aux_button_keycode = set_int("aux_button_keycode", value); }
141 public int backlight_max
147 private string _argv0;
148 public string argv0 {
149 get { return _argv0; }
151 if (value.chr(-1, '/') != null)
153 if (Path.is_absolute(value))
157 _argv0 = Path.build_filename(Environment.get_current_dir(), value, null);
160 _argv0 = Environment.find_program_in_path(value);
162 zavai.log.debug("ARGV0: " + _argv0);
166 /// Reread config values from the Lua VM, to be run after running Lua code
167 protected void refresh_from_lua()
169 _version = get_string("version");
170 _profile = get_string("profile");
171 _homedir = get_string("homedir");
172 _icondir = get_string("icondir");
173 _min_button_height = get_int("min_button_height");
174 _gpsd_host = get_string("gpsd_host");
175 _gpsd_port = get_string("gpsd_port");
176 _gprs_apn = get_string("gprs_apn");
177 _gprs_user = get_string("gprs_user");
178 _gprs_pass = get_string("gprs_pass");
179 _power_button_keycode = get_int("power_button_keycode");
180 _aux_button_keycode = get_int("aux_button_keycode");
185 lua = new Lua.LuaVM();
191 homedir = GLib.Environment.get_home_dir() + "/.zavai";
192 icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
194 icondir = "/usr/share/zavai/icons";
195 min_button_height = 80;
196 gpsd_host = "localhost";
198 gprs_apn = "general.t-mobile.uk";
202 power_button_keycode = 124;
203 aux_button_keycode = 177;
206 if (lua.do_file(homedir + "/config"))
208 zavai.log.error("Failed to parse " + homedir + "/config: " + lua.to_string(-1));
214 public Config config = null;