f3de7489114cbb05d43623aeccbaf73b67f2ade4
[gregoa/zavai.git] / src / config.vala
1 /*
2  * config - zavai configuration
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 namespace zavai {
22
23 public class Config
24 {
25     public string version { get; set; }
26     public string homedir { get; set; }
27     public string icondir { get; set; }
28     public int min_button_height { get; set; }
29     public string gprs_apn { get; set; }
30     public string gprs_user { get; set; }
31     public string gprs_pass { get; set; }
32     public int backlight_max { get; set; }
33     private string _argv0;
34     public string argv0 {
35             get { return _argv0; }
36             set { _argv0 = value; }
37     }
38
39     public Config()
40     {
41         // Set defaults
42         version = "0.1";
43         homedir = GLib.Environment.get_home_dir() + "/.zavai";
44         icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
45         if (icondir == null)
46                 icondir = "/usr/share/zavai/icons";
47         min_button_height = 80;
48         gprs_apn = "general.t-mobile.uk";
49         gprs_user = "x";
50         gprs_pass = "x";
51         backlight_max = 15;
52     }
53
54 /*
55     def _get_homedir(self):
56         res = self.get("global", "home")
57         if res is None:
58             res = os.path.expanduser("~/.zavai")
59         if not os.path.isdir(res):
60             zavai.info("Creating directory", res)
61             os.makedirs(res)
62         return res
63 */
64 }
65
66 /*
67 import os
68 import ConfigParser, StringIO
69
70 def read_config(rootDir = None, defaults = None, nick="octofuss"):
71     """
72     Read octofuss configuration, returning a ConfigParser object
73     """
74     if rootDir == None:
75         rootDir = os.environ.get(nick.upper() + "_CONFDIR", "/etc/" + nick)
76     files = []
77     def trytouse(path):
78         if os.path.exists(path):
79             files.append(path)
80
81     # Start with the main config file
82     trytouse(os.path.join(rootDir, nick + ".conf"))
83
84     # Add snippets found in rc.d style directory
85     subdir = os.path.join(rootDir, nick + ".conf.d")
86     if os.path.isdir(subdir):
87         for file in sorted(os.listdir(subdir)):
88             if file.startswith('#'): continue
89             if file.startswith('.'): continue
90             if file.endswith('~'): continue
91             if file.endswith('.bak'): continue
92             trytouse(os.path.join(subdir, file))
93
94     config = ConfigParser.ConfigParser()
95     if defaults != None:
96         infile = StringIO.StringIO(defaults)
97         config.readfp(infile, "defaults")
98     config.read(files)
99     return config
100 import os.path
101 import zavai
102
103 class Config:
104     def __init__(self):
105         self.conf = zavai.read_config(nick="zavai")
106
107     def get(self, section, name, default=None):
108         if self.conf.has_section(section):
109             if self.conf.has_option(section, name):
110                 return self.conf.get(section, name)
111         return None
112
113     homedir = property(_get_homedir)
114 */
115
116 public Config config = null;
117
118 }