Added support for saving/loading 'animate' option.
[drlaunch] / src / apps.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
27 from gettext import translation
28 #import locale
29
30 #from xdg.IconTheme import getIconPath
31
32 appdir="/usr/share/applications/hildon"
33
34 def readOneFn(fn):
35     global appdir
36
37     ret={
38         'id':       fn[:-8],
39         'name':     None,
40         'exec':     None,
41         'icon':     None,
42         'iconpath': None,
43         'domain':   None,
44         'type':     None,
45         }
46
47     fn2=appdir + '/' + fn
48
49     try:
50         f=open(fn2, 'rt')
51     except:
52         return(None)
53
54     inde=False
55     for line in f:
56         line=line.strip()
57         if line=='[Desktop Entry]':
58             inde=True
59             continue
60
61         if inde==False:
62             continue
63
64         # Reached another block
65         if line.startswith('[') and inde:
66             break
67
68         elif line.startswith('Name='):
69             l=line[5:]
70             ret['name']=l
71         elif line.startswith('Exec='):
72             l=line[5:]
73             ret['exec']=l
74         elif line.startswith('Icon='):
75             l=line[5:]
76             ret['icon']=l
77             # ret['iconpath']=getIconPath(l)
78         elif line.startswith('X-Text-Domain='):
79             l=line[14:]
80             ret['domain']=l
81         elif line.startswith('Type='):
82             l=line[5:]
83             ret['type']=l
84
85     if ret['domain']!=None:
86         try:
87             c=translation(ret['domain'])
88         except IOError, e:
89             c=None
90
91         if c!=None:
92             ret['name0']=ret['name']
93             ret['name']=c.gettext(ret['name0'])
94
95     if ret['name']==None:
96         ret['name']=ret['id']
97
98     return(ret)
99
100 def readOne(name):
101     fn=name + ".desktop"
102
103     ret=readOneFn(fn)
104
105     return(ret)
106
107 def scan():
108     global appdir
109
110     files=os.listdir(appdir)
111
112     ret={}
113
114     for f in files:
115         if not f.endswith('.desktop'):
116             continue
117         if f.startswith('catorise-'):
118             continue
119
120         dt=readOneFn(f)
121
122         if dt==None:
123             continue
124         if dt['type']=='Daemon' or dt['type']=='daemon':
125             continue
126
127         t=f[:-8]
128         ret[t]=dt
129
130     return(ret)
131
132 if __name__=="__main__":
133     #locale.setlocale(locale.LC_ALL, '')
134     print scan()
135
136 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
137