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