clean-ups
[drlaunch] / src / config.py
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 # Copyright (C) 2010 Stefanos Harhalakis
5 #
6 # This file is part of wifieye.
7 #
8 # wifieye is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # wifieye is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
22
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
24
25 import os
26 import pickle
27
28 version = "0.1"
29
30 try:
31     from glib import get_user_config_dir
32 except:
33     def get_user_config_dir():
34         home=os.environ['HOME']
35         if home=='':
36             home="/home/user"
37         cfg="%s/.config" % (home)
38
39         return(cfg)
40
41 size = 2
42 iconsize = 64
43 iconspace = 42
44 apps=None
45
46 def setSize(sz):
47     global size
48
49     size=sz
50
51 def getSize():
52     global size
53
54     return(size)
55
56 def setApps(aps):
57     """ apps is a dictionary of (x,y)=>appname """
58     global apps
59
60     apps=aps
61
62 def getApps():
63     global apps
64
65     if apps==None:
66         tmp={
67             (0,0):  'rtcom-call-ui',
68             (0,1):  'rtcom-messaging-ui',
69             (1,0):  'browser',
70             (1,1):  'osso-addressbook',
71             }
72         setApps(tmp)
73
74     return(apps)
75
76 def ensure_dir():
77     dir0=get_user_config_dir()
78     dir=dir0+'/drlaunch'
79     if not os.path.exists(dir):
80         os.mkdir(dir)
81     if not os.path.isdir(dir):
82         raise Exception('Failed to ensure directory' + dir)
83
84     return(dir)
85
86 def get_config_fn():
87     dir=ensure_dir()
88     ret=dir + '/config'
89
90     return(ret)
91
92 def save():
93     fn=get_config_fn()
94
95     dt={
96         'version':  1,
97         'size':     getSize(),
98         'apps':     getApps()
99         }
100
101     st=pickle.dumps(dt)
102     f=file(fn, 'w')
103     f.write(st)
104     f.close()
105
106 def load():
107     fn=get_config_fn()
108
109     try:
110         f=file(fn, 'r')
111         st=f.read()
112         f.close()
113         dt=pickle.loads(st)
114     except:
115         return
116
117     setSize(dt['size'])
118     setApps(dt['apps'])
119
120 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
121