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