Softwaremanager: * properly count processed packages.
[enigma2.git] / lib / python / Screens / Subtitles.py
1 from Screen import Screen
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from Components.ActionMap import ActionMap
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import config, getConfigListEntry, ConfigNothing
6 from enigma import iPlayableService
7
8 from Tools.ISO639 import LanguageCodes
9
10 class Subtitles(Screen, ConfigListScreen):
11         def __init__(self, session, infobar=None):
12                 Screen.__init__(self, session)
13         
14                 self["actions"] = ActionMap(["SetupActions"],
15                 {
16                         "ok": self.ok,
17                         "cancel": self.cancel,
18                 }, -2)
19
20                 self.list = []
21                 ConfigListScreen.__init__(self, self.list)
22                 self.infobar = infobar or self.session.infobar
23                 self.fillList()
24
25                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
26                         {
27                                 iPlayableService.evUpdatedInfo: self.__updatedInfo
28                         })
29                 self.cached_subtitle_checked = False
30                 self.__selected_subtitle = None
31
32         def fillList(self):
33                 list = self.list
34                 del list[:]
35                 print "self.list", list
36                 if self.subtitlesEnabled():
37                         list.append(getConfigListEntry(_("Disable Subtitles"), ConfigNothing(), None))
38                         sel = self.infobar.selected_subtitle
39                 else:
40                         sel = None
41                 for x in self.getSubtitleList():
42                         if sel and sel[:4] == x[:4]: #ignore Language code in compare
43                                 text = _("Running")
44                         else:
45                                 text = _("Enable")
46                         if x[0] == 0:
47                                 if LanguageCodes.has_key(x[4]):
48                                         list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
49                                 else:
50                                         list.append(getConfigListEntry(text+" DVB "+x[4], ConfigNothing(), x))
51                         elif x[0] == 1:
52                                 if x[4] == 'und': #undefined
53                                         list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2]), ConfigNothing(), x))
54                                 else:
55                                         if LanguageCodes.has_key(x[4]):
56                                                 list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+LanguageCodes[x[4]][0], ConfigNothing(), x))
57                                         else:
58                                                 list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+x[4], ConfigNothing(), x))
59                         elif x[0] == 2:
60                                 types = (" UTF-8 text "," SSA / AAS "," .SRT file ")
61                                 if x[4] == 'und': #undefined
62                                         list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d" % x[1], ConfigNothing(), x))
63                                 else:
64                                         if LanguageCodes.has_key(x[4]):
65                                                 list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles") + ' ' + LanguageCodes[x[4]][0], ConfigNothing(), x))
66                                         else:
67                                                 list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d " % x[1] +x[4], ConfigNothing(), x))
68 #               return _("Disable subtitles")
69                 self["config"].list = list
70                 self["config"].l.setList(list)
71
72         def __updatedInfo(self):
73                 self.fillList()
74
75         def getSubtitleList(self):
76                 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
77                 l = s and s.getSubtitleList() or [ ]
78                 return l
79
80         def subtitlesEnabled(self):
81                 return self.infobar.subtitles_enabled
82
83         def enableSubtitle(self, subtitles):
84                 if self.infobar.selected_subtitle != subtitles:
85                         self.infobar.subtitles_enabled = False
86                         self.infobar.selected_subtitle = subtitles
87                         if subtitles:
88                                 self.infobar.subtitles_enabled = True
89
90         def keyLeft(self):
91                 ConfigListScreen.keyLeft(self)
92
93         def keyRight(self):
94                 ConfigListScreen.keyRight(self)
95
96         def ok(self):
97                 if self.list:
98                         cur = self["config"].getCurrent()
99                         self.enableSubtitle(cur[2])
100                 self.close(1)
101
102         def cancel(self):
103                 self.close()