2 * config - zavai configuration
4 * Copyright (C) 2009--2010 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 string _sim_pin;
128 public string sim_pin
130 get { return _sim_pin; }
131 set { _sim_pin = set_string("sim_pin", value); }
134 private int _power_button_keycode;
135 public int power_button_keycode
137 get { return _power_button_keycode; }
138 set { _power_button_keycode = set_int("power_button_keycode", value); }
141 private int _aux_button_keycode;
142 public int aux_button_keycode
144 get { return _aux_button_keycode; }
145 set { _aux_button_keycode = set_int("aux_button_keycode", value); }
148 private string _ringtone_alarm;
149 public string ringtone_alarm
151 get { return _ringtone_alarm; }
152 set { _ringtone_alarm = set_string("ringtone_alarm", value); }
155 private string _ringtone_call;
156 public string ringtone_call
158 get { return _ringtone_call; }
159 set { _ringtone_call = set_string("ringtone_call", value); }
162 private string _ringtone_sms;
163 public string ringtone_sms
165 get { return _ringtone_sms; }
166 set { _ringtone_sms = set_string("ringtone_sms", value); }
169 public int backlight_max
175 private string _argv0;
176 public string argv0 {
177 get { return _argv0; }
179 if (value.chr(-1, '/') != null)
181 if (Path.is_absolute(value))
185 _argv0 = Path.build_filename(Environment.get_current_dir(), value, null);
188 _argv0 = Environment.find_program_in_path(value);
190 zavai.log.debug("ARGV0: " + _argv0);
194 /// Reread config values from the Lua VM, to be run after running Lua code
195 protected void refresh_from_lua()
197 _version = get_string("version");
198 _profile = get_string("profile");
199 _homedir = get_string("homedir");
200 _icondir = get_string("icondir");
201 _min_button_height = get_int("min_button_height");
202 _gpsd_host = get_string("gpsd_host");
203 _gpsd_port = get_string("gpsd_port");
204 _gprs_apn = get_string("gprs_apn");
205 _gprs_user = get_string("gprs_user");
206 _gprs_pass = get_string("gprs_pass");
207 _sim_pin = get_string("sim_pin");
208 _power_button_keycode = get_int("power_button_keycode");
209 _aux_button_keycode = get_int("aux_button_keycode");
210 _ringtone_alarm = get_string("ringtone_alarm");
211 _ringtone_call = get_string("ringtone_call");
212 _ringtone_sms = get_string("ringtone_sms");
217 lua = new Lua.LuaVM();
223 homedir = GLib.Environment.get_home_dir() + "/.zavai";
224 icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
226 icondir = "/usr/share/zavai/icons";
227 min_button_height = 80;
228 gpsd_host = "localhost";
230 gprs_apn = "general.t-mobile.uk";
235 power_button_keycode = 124;
236 aux_button_keycode = 177;
237 ringtone_alarm = "file:///usr/share/sounds/yue-fso/lec1.ogg";
238 ringtone_call = "file:///usr/share/sounds/yue-fso/jmf1.ogg";
239 ringtone_sms = "file:///usr/share/sounds/yue-fso/nothing4.ogg";
242 if (lua.do_file(homedir + "/config"))
244 zavai.log.error("Failed to parse " + homedir + "/config: " + lua.to_string(-1));
250 * Find a zavai script.
252 * ~/.zavai/NAME is searched first, then /usr/share/zavai/hooks/
254 * If the script is not found, NULL is returned
256 public string? find_script(string name)
258 string candidate = homedir + "/" + name;
259 if (FileUtils.test(candidate, FileTest.EXISTS))
261 candidate = "/usr/share/zavai/hooks/" + name;
262 if (FileUtils.test(candidate, FileTest.EXISTS))
267 public void find_and_run_script(string script, string args) throws SpawnError
269 string cmd = find_script(script);
271 throw new SpawnError.NOENT("hook '" + cmd + "' not found");
272 run_script(cmd + " " + args);
275 public void run_script(string command) throws SpawnError
277 zavai.log.info("Run program: " + command);
278 string[] args = command.split(" ");
281 Environment.get_home_dir(),
284 SpawnFlags.SEARCH_PATH,
289 public int run_script_sync(string command, out string std_out, out string std_err) throws SpawnError
292 zavai.log.info("Run program: " + command);
293 string[] args = command.split(" ");
294 bool res = Process.spawn_sync(Environment.get_home_dir(), args, null, SpawnFlags.SEARCH_PATH, null, out std_out, out std_err, out status);
299 public Config config = null;