fix default for single parameter in About, when parameter does not exist in skin
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / About.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Sources.StaticText import StaticText
4 from Components.Harddisk import harddiskmanager
5 from Components.NimManager import nimmanager
6 from Components.About import about
7 from Components.ScrollLabel import ScrollLabel
8 from Components.Button import Button
9
10 from Components.Label import Label
11 from Components.ProgressBar import ProgressBar
12
13 from Tools.StbHardware import getFPVersion
14 from enigma import eTimer, eLabel
15
16 from Components.HTMLComponent import HTMLComponent
17 from Components.GUIComponent import GUIComponent
18 import skin
19
20 class About(Screen):
21         def __init__(self, session):
22                 Screen.__init__(self, session)
23                 hddsplit, = skin.parameters.get("AboutHddSplit", (0,))
24
25                 AboutText = _("Hardware: ") + about.getHardwareTypeString() + "\n"
26                 AboutText += _("CPU: ") + about.getCPUInfoString() + "\n"
27                 AboutText += _("Image: ") + about.getImageTypeString() + "\n"
28                 AboutText += _("Installed: ") + about.getFlashDateString() + "\n"
29                 AboutText += _("Kernel version: ") + about.getKernelVersionString() + "\n"
30
31                 EnigmaVersion = "Enigma: " + about.getEnigmaVersionString()
32                 self["EnigmaVersion"] = StaticText(EnigmaVersion)
33                 AboutText += EnigmaVersion + "\n"
34
35                 GStreamerVersion = "GStreamer: " + about.getGStreamerVersionString()
36                 self["GStreamerVersion"] = StaticText(GStreamerVersion)
37                 AboutText += GStreamerVersion + "\n"
38
39                 ImageVersion = _("Last upgrade: ") + about.getImageVersionString()
40                 self["ImageVersion"] = StaticText(ImageVersion)
41                 AboutText += ImageVersion + "\n"
42
43                 AboutText += _("DVB drivers: ") + about.getDriverInstalledDate() + "\n"
44
45                 AboutText += _("Python version: ") + about.getPythonVersionString() + "\n"
46
47                 fp_version = getFPVersion()
48                 if fp_version is None:
49                         fp_version = ""
50                 else:
51                         fp_version = _("Frontprocessor version: %d") % fp_version
52                         AboutText += fp_version + "\n"
53
54                 self["FPVersion"] = StaticText(fp_version)
55
56                 self["TunerHeader"] = StaticText(_("Detected NIMs:"))
57                 AboutText += "\n" + _("Detected NIMs:") + "\n"
58
59                 nims = nimmanager.nimList()
60                 for count in range(len(nims)):
61                         if count < 4:
62                                 self["Tuner" + str(count)] = StaticText(nims[count])
63                         else:
64                                 self["Tuner" + str(count)] = StaticText("")
65                         AboutText += nims[count] + "\n"
66
67                 self["HDDHeader"] = StaticText(_("Detected HDD:"))
68                 AboutText += "\n" + _("Detected HDD:") + "\n"
69
70                 hddlist = harddiskmanager.HDDList()
71                 hddinfo = ""
72                 if hddlist:
73                         formatstring = hddsplit and "%s:%s, %.1f %sB %s" or "%s\n(%s, %.1f %sB %s)"
74                         for count in range(len(hddlist)):
75                                 if hddinfo:
76                                         hddinfo += "\n"
77                                 hdd = hddlist[count][1]
78                                 if int(hdd.free()) > 1024:
79                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free()/1024, "G", _("free"))
80                                 else:
81                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free()/1024, "M", _("free"))
82                 else:
83                         hddinfo = _("none")
84                 self["hddA"] = StaticText(hddinfo)
85                 AboutText += hddinfo
86                 self["AboutScrollLabel"] = ScrollLabel(AboutText)
87                 self["key_green"] = Button(_("Translations"))
88                 self["key_red"] = Button(_("Latest Commits"))
89                 self["key_blue"] = Button(_("Memory Info"))
90
91                 self["actions"] = ActionMap(["ColorActions", "SetupActions", "DirectionActions"],
92                         {
93                                 "cancel": self.close,
94                                 "ok": self.close,
95                                 "red": self.showCommits,
96                                 "green": self.showTranslationInfo,
97                                 "blue": self.showMemoryInfo,
98                                 "up": self["AboutScrollLabel"].pageUp,
99                                 "down": self["AboutScrollLabel"].pageDown
100                         })
101
102         def showTranslationInfo(self):
103                 self.session.open(TranslationInfo)
104
105         def showCommits(self):
106                 self.session.open(CommitInfo)
107
108         def showMemoryInfo(self):
109                 self.session.open(MemoryInfo)
110
111 class TranslationInfo(Screen):
112         def __init__(self, session):
113                 Screen.__init__(self, session)
114                 # don't remove the string out of the _(), or it can't be "translated" anymore.
115
116                 # TRANSLATORS: Add here whatever should be shown in the "translator" about screen, up to 6 lines (use \n for newline)
117                 info = _("TRANSLATOR_INFO")
118
119                 if info == "TRANSLATOR_INFO":
120                         info = "(N/A)"
121
122                 infolines = _("").split("\n")
123                 infomap = {}
124                 for x in infolines:
125                         l = x.split(': ')
126                         if len(l) != 2:
127                                 continue
128                         (type, value) = l
129                         infomap[type] = value
130                 print infomap
131
132                 self["key_red"] = Button(_("Cancel"))
133                 self["TranslationInfo"] = StaticText(info)
134
135                 translator_name = infomap.get("Language-Team", "none")
136                 if translator_name == "none":
137                         translator_name = infomap.get("Last-Translator", "")
138
139                 self["TranslatorName"] = StaticText(translator_name)
140
141                 self["actions"] = ActionMap(["SetupActions"],
142                         {
143                                 "cancel": self.close,
144                                 "ok": self.close,
145                         })
146
147 class CommitInfo(Screen):
148         def __init__(self, session):
149                 Screen.__init__(self, session)
150                 self.skinName = ["CommitInfo", "About"]
151                 self["AboutScrollLabel"] = ScrollLabel(_("Please wait"))
152
153                 self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
154                         {
155                                 "cancel": self.close,
156                                 "ok": self.close,
157                                 "up": self["AboutScrollLabel"].pageUp,
158                                 "down": self["AboutScrollLabel"].pageDown,
159                                 "left": self.left,
160                                 "right": self.right
161                         })
162
163                 self["key_red"] = Button(_("Cancel"))
164
165                 self.project = 0
166                 self.projects = [
167                         ("enigma2", "Enigma2"),
168                         ("openpli-oe-core", "Openpli Oe Core"),
169                         ("enigma2-plugins", "Enigma2 Plugins"),
170                         ("aio-grab", "Aio Grab"),
171                         ("gst-plugin-dvbmediasink", "Gst Plugin Dvbmediasink"),
172                         ("openembedded", "Openembedded"),
173                         ("plugin-xmltvimport", "Plugin Xmltvimport"),
174                         ("plugins-enigma2", "Plugins Enigma2"),
175                         ("skin-magic", "Skin Magic"),
176                         ("tuxtxt", "Tuxtxt")
177                 ]
178                 self.cachedProjects = {}
179                 self.Timer = eTimer()
180                 self.Timer.callback.append(self.readCommitLogs)
181                 self.Timer.start(50, True)
182
183         def readCommitLogs(self):
184                 url = 'http://sourceforge.net/p/openpli/%s/feed' % self.projects[self.project][0]
185                 commitlog = ""
186                 from urllib2 import urlopen
187                 try:
188                         commitlog += 80 * '-' + '\n'
189                         commitlog += url.split('/')[-2] + '\n'
190                         commitlog += 80 * '-' + '\n'
191                         for x in  urlopen(url, timeout=5).read().split('<title>')[2:]:
192                                 for y in x.split("><"):
193                                         if '</title' in y:
194                                                 title = y[:-7]
195                                         if '</dc:creator' in y:
196                                                 creator = y.split('>')[1].split('<')[0]
197                                         if '</pubDate' in y:
198                                                 date = y.split('>')[1].split('<')[0][:-6]
199                                 commitlog += date + ' ' + creator + '\n' + title + 2 * '\n'
200                         self.cachedProjects[self.projects[self.project][1]] = commitlog
201                 except:
202                         commitlog = _("Currently the commit log cannot be retrieved - please try later again")
203                 self["AboutScrollLabel"].setText(commitlog)
204
205         def updateCommitLogs(self):
206                 if self.cachedProjects.has_key(self.projects[self.project][1]):
207                         self["AboutScrollLabel"].setText(self.cachedProjects[self.projects[self.project][1]])
208                 else:
209                         self["AboutScrollLabel"].setText(_("Please wait"))
210                         self.Timer.start(50, True)
211
212         def left(self):
213                 self.project = self.project == 0 and len(self.projects) - 1 or self.project - 1
214                 self.updateCommitLogs()
215
216         def right(self):
217                 self.project = self.project != len(self.projects) - 1 and self.project + 1 or 0
218                 self.updateCommitLogs()
219
220 class MemoryInfo(Screen):
221         def __init__(self, session):
222                 Screen.__init__(self, session)
223
224                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
225                         {
226                                 "cancel": self.close,
227                                 "ok": self.getMemoryInfo,
228                                 "green": self.getMemoryInfo,
229                                 "blue": self.clearMemory,
230                         })
231
232                 self["key_red"] = Label(_("Cancel"))
233                 self["key_green"] = Label(_("Refresh"))
234                 self["key_blue"] = Label(_("Clear"))
235
236                 self['lmemtext'] = Label()
237                 self['lmemvalue'] = Label()
238                 self['rmemtext'] = Label()
239                 self['rmemvalue'] = Label()
240
241                 self['pfree'] = Label()
242                 self['pused'] = Label()
243                 self["slide"] = ProgressBar()
244                 self["slide"].setValue(100)
245
246                 self["params"] = MemoryInfoSkinParams()
247
248                 self['info'] = Label(_("This info is for developers only.\nFor a normal users it is not important.\nDon't panic, please, when here will be displayed any suspicious informations!"))
249
250                 self.setTitle(_("Memory Info"))
251                 self.onLayoutFinish.append(self.getMemoryInfo)
252
253         def getMemoryInfo(self):
254                 try:
255                         ltext = rtext = ""
256                         lvalue = rvalue = ""
257                         mem = 1
258                         free = 0
259                         i = 0
260                         for line in open('/proc/meminfo','r'):
261                                 ( name, size, units ) = line.strip().split()
262                                 if "MemTotal" in name:
263                                         mem = int(size)
264                                 if "MemFree" in name:
265                                         free = int(size)
266                                 if i < self["params"].rows_in_column:
267                                         ltext += "".join((name,"\n"))
268                                         lvalue += "".join((size," ",units,"\n"))
269                                 else:
270                                         rtext += "".join((name,"\n"))
271                                         rvalue += "".join((size," ",units,"\n"))
272                                 i += 1
273                         self['lmemtext'].setText(ltext)
274                         self['lmemvalue'].setText(lvalue)
275                         self['rmemtext'].setText(rtext)
276                         self['rmemvalue'].setText(rvalue)
277
278                         self["slide"].setValue(int(100.0*(mem-free)/mem+0.25))
279                         self['pfree'].setText("%.1f %s" % (100.*free/mem,'%'))
280                         self['pused'].setText("%.1f %s" % (100.*(mem-free)/mem,'%'))
281
282                 except Exception, e:
283                         print "[About] getMemoryInfo FAIL:", e
284
285         def clearMemory(self):
286                 from os import system
287                 system("sync")
288                 system("echo 3 > /proc/sys/vm/drop_caches")
289                 self.getMemoryInfo()
290
291 class MemoryInfoSkinParams(HTMLComponent, GUIComponent):
292         def __init__(self):
293                 GUIComponent.__init__(self)
294                 self.rows_in_column = 25
295
296         def applySkin(self, desktop, screen):
297                 if self.skinAttributes is not None:
298                         attribs = [ ]
299                         for (attrib, value) in self.skinAttributes:
300                                 if attrib == "rowsincolumn":
301                                         self.rows_in_column = int(value)
302                         self.skinAttributes = attribs
303                 return GUIComponent.applySkin(self, desktop, screen)
304
305         GUI_WIDGET = eLabel