use green to add a timer directly from the epgSelection
[enigma2.git] / lib / python / Screens / EpgSelection.py
1 from Screen import Screen
2 from Components.Button import Button
3 from Components.EpgList import EPGList
4 from Components.ActionMap import ActionMap
5 from Screens.EventView import EventView
6 from enigma import eServiceReference, eServiceEventPtr
7 from Screens.FixedMenu import FixedMenu
8 from RecordTimer import RecordTimerEntry
9 from TimerEdit import TimerEditList
10 from TimerEntry import TimerEntry
11 from ServiceReference import ServiceReference
12
13 import xml.dom.minidom
14
15 class EPGSelection(Screen):
16         def __init__(self, session, root):
17                 Screen.__init__(self, session)
18
19                 self["list"] = EPGList()
20
21                 class ChannelActionMap(ActionMap):
22                         def action(self, contexts, action):
23                                         ActionMap.action(self, contexts, action)
24
25                 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"], 
26                         {
27                                 "cancel": self.close,
28                                 "ok": self.eventSelected,
29                                 "timerAdd": self.timerAdd
30                         })
31                 self["actions"].csel = self
32                 self.setRoot(root)
33
34         def eventViewCallback(self, setEvent, val):
35                 if val == -1:
36                         self.moveUp()
37                         setEvent(self["list"].getCurrent())
38                 elif val == +1:
39                         self.moveDown()
40                         setEvent(self["list"].getCurrent())
41
42         def eventSelected(self):
43                 event = self["list"].getCurrent()
44                 self.session.open(EventView, event, self.eventViewCallback)
45         
46         def timerAdd(self):
47                 epg = self["list"].getCurrent()
48                 
49                 if (epg == None):
50                         description = "unknown event"
51                 else:
52                         description = epg.getEventName()
53                         # FIXME we need a timestamp here:
54                         begin = epg.getBeginTime()
55                         
56                         print begin
57                         print epg.getDuration()
58                         end = begin + epg.getDuration()
59
60
61                 # FIXME only works if already playing a service
62                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
63                 
64                 newEntry = RecordTimerEntry(begin, end, serviceref, epg, description)
65                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
66         
67         def timerEditFinished(self, answer):
68                 if (answer[0]):
69                         self.session.nav.RecordTimer.record(answer[1])
70                 else:
71                         print "Timeredit aborted"       
72                         
73         def setRoot(self, root):
74                 self["list"].setRoot(root)
75
76         def moveUp(self):
77                 self["list"].moveUp()
78
79         def moveDown(self):
80                 self["list"].moveDown()