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 _gprs_apn;
93 public string gprs_apn
95 get { return _gprs_apn; }
96 set { _gprs_apn = set_string("gprs_apn", value); }
99 private string _gprs_user;
100 public string gprs_user
102 get { return _gprs_user; }
103 set { _gprs_user = set_string("gprs_user", value); }
106 private string _gprs_pass;
107 public string gprs_pass
109 get { return _gprs_pass; }
110 set { _gprs_pass = set_string("gprs_pass", value); }
113 private int _power_button_keycode;
114 public int power_button_keycode
116 get { return _power_button_keycode; }
117 set { _power_button_keycode = set_int("power_button_keycode", value); }
120 private int _aux_button_keycode;
121 public int aux_button_keycode
123 get { return _aux_button_keycode; }
124 set { _aux_button_keycode = set_int("aux_button_keycode", value); }
127 public int backlight_max
133 private string _argv0;
134 public string argv0 {
135 get { return _argv0; }
137 if (value.chr(-1, '/') != null)
139 if (Path.is_absolute(value))
143 _argv0 = Path.build_filename(Environment.get_current_dir(), value, null);
146 _argv0 = Environment.find_program_in_path(value);
148 zavai.log.debug("ARGV0: " + _argv0);
152 /// Reread config values from the Lua VM, to be run after running Lua code
153 protected void refresh_from_lua()
155 _version = get_string("version");
156 _profile = get_string("profile");
157 _homedir = get_string("homedir");
158 _icondir = get_string("icondir");
159 _min_button_height = get_int("min_button_height");
160 _gprs_apn = get_string("gprs_apn");
161 _gprs_user = get_string("gprs_user");
162 _gprs_pass = get_string("gprs_pass");
163 _power_button_keycode = get_int("power_button_keycode");
164 _aux_button_keycode = get_int("aux_button_keycode");
169 lua = new Lua.LuaVM();
175 homedir = GLib.Environment.get_home_dir() + "/.zavai";
176 icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
178 icondir = "/usr/share/zavai/icons";
179 min_button_height = 80;
180 gprs_apn = "general.t-mobile.uk";
184 power_button_keycode = 124;
185 aux_button_keycode = 177;
188 if (lua.do_file(homedir + "/config"))
190 zavai.log.error("Failed to parse " + homedir + "/config: " + lua.to_string(-1));
196 public Config config = null;