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