Moved into src.
[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 try:
29     from glib import get_user_config_dir
30 except:
31     def get_user_config_dir():
32         home=os.environ['HOME']
33         if home=='':
34             home="/home/user"
35         cfg="%s/.config" % (home)
36
37         return(cfg)
38
39 size = 2
40 iconsize = 64
41 iconspace = 42
42 apps=None
43
44 def setSize(sz):
45     global size
46
47     size=sz
48
49 def getSize():
50     global size
51
52     return(size)
53
54 def setApps(aps):
55     """ apps is a dictionary of (x,y)=>appname """
56     global apps
57
58     apps=aps
59
60 def getApps():
61     global apps
62
63     if apps==None:
64         tmp={
65             (0,0):  'rtcom-call-ui',
66             (0,1):  'rtcom-messaging-ui',
67             (1,0):  'browser',
68             (1,1):  'osso-addressbook',
69             }
70         setApps(tmp)
71
72     return(apps)
73
74 def ensure_dir():
75     dir0=get_user_config_dir()
76     dir=dir0+'/drlaunch'
77     if not os.path.exists(dir):
78         os.mkdir(dir)
79     if not os.path.isdir(dir):
80         raise Exception('Failed to ensure directory' + dir)
81
82     return(dir)
83
84 def get_config_fn():
85     dir=ensure_dir()
86     ret=dir + '/config'
87
88     return(ret)
89
90 def save():
91     fn=get_config_fn()
92     print "save", fn
93
94     dt={
95         'version':  1,
96         'size':     getSize(),
97         'apps':     getApps()
98         }
99
100     print "save:", dt
101
102     st=pickle.dumps(dt)
103     f=file(fn, 'w')
104     f.write(st)
105     f.close()
106
107 def load():
108     fn=get_config_fn()
109     print "load", fn
110
111     try:
112         f=file(fn, 'r')
113         st=f.read()
114         f.close()
115         dt=pickle.loads(st)
116     except:
117         return
118
119     print "load:", dt
120
121     setSize(dt['size'])
122     setApps(dt['apps'])
123
124 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
125