fa4755c82eb78a58575b67b257025e1553a36f25
[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 Tools.StbHardware import getFPVersion
11 from enigma import eTimer
12
13 class About(Screen):
14         def __init__(self, session):
15                 Screen.__init__(self, session)
16
17
18                 AboutText = _("Hardware: ") + about.getHardwareTypeString() + "\n"
19                 AboutText += _("CPU: ") + about.getCPUInfoString() + "\n"
20                 AboutText += _("Image: ") + about.getImageTypeString() + "\n"
21                 AboutText += _("Kernel version: ") + about.getKernelVersionString() + "\n"
22
23                 EnigmaVersion = "Enigma: " + about.getEnigmaVersionString()
24                 self["EnigmaVersion"] = StaticText(EnigmaVersion)
25                 AboutText += EnigmaVersion + "\n"
26
27                 ImageVersion = _("Last upgrade: ") + about.getImageVersionString()
28                 self["ImageVersion"] = StaticText(ImageVersion)
29                 AboutText += ImageVersion + "\n"
30
31                 fp_version = getFPVersion()
32                 if fp_version is None:
33                         fp_version = ""
34                 else:
35                         fp_version = _("Frontprocessor version: %d") % fp_version
36                         AboutText += fp_version + "\n"
37
38                 self["FPVersion"] = StaticText(fp_version)
39
40                 self["TunerHeader"] = StaticText(_("Detected NIMs:"))
41                 AboutText += "\n" + _("Detected NIMs:") + "\n"
42
43                 nims = nimmanager.nimList()
44                 for count in range(len(nims)):
45                         if count < 4:
46                                 self["Tuner" + str(count)] = StaticText(nims[count])
47                         else:
48                                 self["Tuner" + str(count)] = StaticText("")
49                         AboutText += nims[count] + "\n"
50
51                 self["HDDHeader"] = StaticText(_("Detected HDD:"))
52                 AboutText += "\n" + _("Detected HDD:") + "\n"
53
54                 hddlist = harddiskmanager.HDDList()
55                 hddinfo = ""
56                 if hddlist:
57                         for count in range(len(hddlist)):
58                                 if hddinfo:
59                                         hddinfo += "\n"
60                                 hdd = hddlist[count][1]
61                                 if int(hdd.free()) > 1024:
62                                         hddinfo += "%s\n(%s, %d GB %s)" % (hdd.model(), hdd.capacity(), hdd.free()/1024, _("free"))
63                                 else:
64                                         hddinfo += "%s\n(%s, %d MB %s)" % (hdd.model(), hdd.capacity(), hdd.free(), _("free"))
65                 else:
66                         hddinfo = _("none")
67                 self["hddA"] = StaticText(hddinfo)
68                 AboutText += hddinfo
69                 self["AboutScrollLabel"] = ScrollLabel(AboutText)
70                 self["key_green"] = Button(_("Translations"))
71                 self["key_red"] = Button(_("Latest Commits"))
72
73                 self["actions"] = ActionMap(["ColorActions", "SetupActions", "DirectionActions"],
74                         {
75                                 "cancel": self.close,
76                                 "ok": self.close,
77                                 "red": self.showCommits,
78                                 "green": self.showTranslationInfo,
79                                 "up": self["AboutScrollLabel"].pageUp,
80                                 "down": self["AboutScrollLabel"].pageDown
81                         })
82
83         def showTranslationInfo(self):
84                 self.session.open(TranslationInfo)
85
86         def showCommits(self):
87                 self.session.open(CommitInfo)
88
89 class TranslationInfo(Screen):
90         def __init__(self, session):
91                 Screen.__init__(self, session)
92                 # don't remove the string out of the _(), or it can't be "translated" anymore.
93
94                 # TRANSLATORS: Add here whatever should be shown in the "translator" about screen, up to 6 lines (use \n for newline)
95                 info = _("TRANSLATOR_INFO")
96
97                 if info == "TRANSLATOR_INFO":
98                         info = "(N/A)"
99
100                 infolines = _("").split("\n")
101                 infomap = {}
102                 for x in infolines:
103                         l = x.split(': ')
104                         if len(l) != 2:
105                                 continue
106                         (type, value) = l
107                         infomap[type] = value
108                 print infomap
109
110                 self["TranslationInfo"] = StaticText(info)
111
112                 translator_name = infomap.get("Language-Team", "none")
113                 if translator_name == "none":
114                         translator_name = infomap.get("Last-Translator", "")
115
116                 self["TranslatorName"] = StaticText(translator_name)
117
118                 self["actions"] = ActionMap(["SetupActions"],
119                         {
120                                 "cancel": self.close,
121                                 "ok": self.close,
122                         })
123
124 class CommitInfo(Screen):
125         def __init__(self, session):
126                 Screen.__init__(self, session)
127                 self.skinName = ["CommitInfo", "About"]
128                 self["AboutScrollLabel"] = ScrollLabel(_("Please wait"))
129
130                 self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
131                         {
132                                 "cancel": self.close,
133                                 "ok": self.close,
134                                 "up": self["AboutScrollLabel"].pageUp,
135                                 "down": self["AboutScrollLabel"].pageDown,
136                                 "left": self.left,
137                                 "right": self.right
138                         })
139
140                 self.project = 0
141                 self.projects = [
142                         ("enigma2", "Enigma2"),
143                         ("openpli-oe-core", "Openpli Oe Core"),
144                         ("enigma2-plugins", "Enigma2 Plugins"),
145                         ("aio-grab", "Aio Grab"),
146                         ("gst-plugin-dvbmediasink", "Gst Plugin Dvbmediasink"),
147                         ("openembedded", "Openembedded"),
148                         ("plugin-xmltvimport", "Plugin Xmltvimport"),
149                         ("plugins-enigma2", "Plugins Enigma2"),
150                         ("skin-magic", "Skin Magic"),
151                         ("tuxtxt", "Tuxtxt")
152                 ]
153                 self.cachedProjects = {}
154                 self.Timer = eTimer()
155                 self.Timer.callback.append(self.readCommitLogs)
156                 self.Timer.start(50, True)
157
158         def readCommitLogs(self):
159                 url = 'http://sourceforge.net/p/openpli/%s/feed' % self.projects[self.project][0]
160                 commitlog = ""
161                 from urllib2 import urlopen
162                 try:
163                         commitlog += 80 * '-' + '\n'
164                         commitlog += url.split('/')[-2] + '\n'
165                         commitlog += 80 * '-' + '\n'
166                         for x in  urlopen(url, timeout=5).read().split('<title>')[2:]:
167                                 for y in x.split("><"):
168                                         if '</title' in y:
169                                                 title = y[:-7]
170                                         if '</dc:creator' in y:
171                                                 creator = y.split('>')[1].split('<')[0]
172                                         if '</pubDate' in y:
173                                                 date = y.split('>')[1].split('<')[0][:-6]
174                                 commitlog += date + ' ' + creator + '\n' + title + 2 * '\n'
175                         self.cachedProjects[self.projects[self.project][1]] = commitlog
176                 except:
177                         commitlog = _("Currently the commit log cannot be retrieved - please try later again")
178                 self["AboutScrollLabel"].setText(commitlog)
179
180         def updateCommitLogs(self):
181                 if self.cachedProjects.has_key(self.projects[self.project][1]):
182                         self["AboutScrollLabel"].setText(self.cachedProjects[self.projects[self.project][1]])
183                 else:
184                         self["AboutScrollLabel"].setText(_("Please wait"))
185                         self.Timer.start(50, True)
186
187         def left(self):
188                 self.project = self.project == 0 and len(self.projects) - 1 or self.project - 1
189                 self.updateCommitLogs()
190
191         def right(self):
192                 self.project = self.project != len(self.projects) - 1 and self.project + 1 or 0
193                 self.updateCommitLogs()