subservice quickzap fixes
[enigma2.git] / lib / python / Screens / SubservicesQuickzap.py
1 from Screens.Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.Label import Label
4
5 from Screens.ChoiceBox import ChoiceBox
6 from Screens.MessageBox import MessageBox
7 from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport
8
9 from enigma import eTimer
10
11 class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, Screen):
12         def __init__(self, session, subservices):
13                 Screen.__init__(self, session)
14                 for x in [InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarSubtitleSupport, InfoBarExtensions]:
15                         x.__init__(self)
16
17                 self.restoreService = self.session.nav.getCurrentlyPlayingServiceReference()
18                 
19                 self["CurrentSubserviceNumber"] = Label("")
20                 self.currentSubserviceNumberLabel = self["CurrentSubserviceNumber"]
21                 
22                 self.updateSubservices()
23                 self.currentlyPlayingSubservice = 0
24
25                 self.timer = eTimer()
26                 self.timer.timeout.get().append(self.playSubservice)
27                 self.onLayoutFinish.append(self.onLayoutFinished)
28
29                 self["actions"] = NumberActionMap( [ "InfobarSubserviceQuickzapActions", "NumberActions", "DirectionActions", "ColorActions" ], 
30                         {
31                                 "up": self.showSelection,
32                                 "down": self.showSelection,
33                                 "right": self.nextSubservice,
34                                 "left": self.previousSubservice,
35                                 "green": self.showSelection,
36                                 "exit": self.quitQuestion,
37                                 "1": self.keyNumberGlobal,
38                                 "2": self.keyNumberGlobal,
39                                 "3": self.keyNumberGlobal,
40                                 "4": self.keyNumberGlobal,
41                                 "5": self.keyNumberGlobal,
42                                 "6": self.keyNumberGlobal,
43                                 "7": self.keyNumberGlobal,
44                                 "8": self.keyNumberGlobal,
45                                 "9": self.keyNumberGlobal,
46                                 "0": self.keyNumberGlobal
47                         }, -1)
48
49         def onLayoutFinished(self):
50                 self.timer.start(0,True)
51
52         def updateSubservices(self):
53                 self.service = self.session.nav.getCurrentService()
54                 self.subservices = self.service and self.service.subServices()
55                 self.n = self.subservices and self.subservices.getNumberOfSubservices()
56         
57         def nextSubservice(self):
58                 self.updateSubservices()
59                 if self.n:
60                         if self.currentlyPlayingSubservice >= self.n - 1:
61                                 self.playSubservice(0)
62                         else:
63                                 self.playSubservice(self.currentlyPlayingSubservice + 1)
64         
65         def previousSubservice(self):
66                 self.updateSubservices()
67                 if self.n:
68                         if self.currentlyPlayingSubservice > self.n:
69                                 self.currentlyPlayingSubservice = self.n
70                         if self.currentlyPlayingSubservice == 0:
71                                 self.playSubservice(self.n - 1)
72                         else:
73                                 self.playSubservice(self.currentlyPlayingSubservice - 1)
74
75         def getSubserviceIndex(self, service):
76                 self.updateSubservices()
77                 for x in range(self.n):
78                         if service == self.subservices.getSubservice(x):
79                                 return self.n
80         
81         def keyNumberGlobal(self, number):
82                 print number, "pressed"
83                 self.updateSubservices()
84                 if number == 0:
85                         self.playSubservice(self.lastservice)
86                 elif number <= self.n - 1:
87                         self.playSubservice(number)
88         
89         def showSelection(self):
90                 self.updateSubservices()
91                 tlist = []
92                 for x in range(self.n):
93                         i = self.subservices.getSubservice(x)
94                         tlist.append((i.getName(), x))
95
96                 keys = [ "", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * self.n
97                 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice..."), list = tlist, selection = self.currentlyPlayingSubservice, keys = keys)
98         
99         def subserviceSelected(self, service):
100                 print "playing subservice number", service
101                 if service is not None:
102                         self.playSubservice(service[1])
103         
104         def keyOK(self):
105                 pass
106         
107         def quitQuestion(self):
108                 self.session.openWithCallback(self.quit, MessageBox, _("Really exit the subservices quickzap?"))
109         
110         def quit(self, answer):
111                 if answer:
112                         self.session.nav.playService(self.restoreService)
113                         self.close()
114                 
115         def playSubservice(self, number = 0):
116                 newservice = self.subservices.getSubservice(number)
117                 if newservice.valid():
118                         del self.subservices
119                         del self.service
120                         self.lastservice = self.currentlyPlayingSubservice
121                         self.session.nav.playService(newservice)
122                         self.currentlyPlayingSubservice = number
123                         self.currentSubserviceNumberLabel.setText(str(number))
124                         self.doShow()