ability to add timers directly from the eventview screen
[enigma2.git] / lib / python / Screens / EventView.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Label import Label
4 from Components.ScrollLabel import ScrollLabel
5 from enigma import eServiceEventPtr
6 from ServiceReference import ServiceReference
7 from RecordTimer import RecordTimerEntry
8 from TimerEntry import TimerEntry
9
10 class EventView(Screen):
11         def __init__(self, session, Event, Ref, callback=None):
12                 Screen.__init__(self, session)
13                 self.cbFunc = callback
14                 self.currentService=None
15                 self["epg_description"] = ScrollLabel()
16                 self["datetime"] = Label()
17                 self["channel"] = Label()
18                 self["duration"] = Label()
19                 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
20                         {
21                                 "cancel": self.close,
22                                 "ok": self.close,
23                                 "pageUp": self.pageUp,
24                                 "pageDown": self.pageDown,
25                                 "prevEvent": self.prevEvent,
26                                 "nextEvent": self.nextEvent,
27                                 "timerAdd": self.timerAdd
28                         })
29                 self.setEvent(Event)
30                 self.setService(Ref)
31
32         def prevEvent(self):
33                 if self.cbFunc is not None:
34                         self.cbFunc(self.setEvent, -1)
35
36         def nextEvent(self):
37                 if self.cbFunc is not None:
38                         self.cbFunc(self.setEvent, +1)
39                         
40         def timerAdd(self):
41                 epg = self.event
42                 
43                 if (epg == None):
44                         description = "unknown event"
45                 else:
46                         description = epg.getEventName()
47                         # FIXME we need a timestamp here:
48                         begin = epg.getBeginTime()
49                         
50                         print begin
51                         print epg.getDuration()
52                         end = begin + epg.getDuration()
53
54
55                 # FIXME only works if already playing a service
56                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
57                 
58                 newEntry = RecordTimerEntry(begin, end, serviceref, epg, description)
59                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
60
61         def timerEditFinished(self, answer):
62                 if (answer[0]):
63                         self.session.nav.RecordTimer.record(answer[1])
64                 else:
65                         print "Timeredit aborted"       
66
67         def setService(self, service):
68                 self.currentService=service
69                 name = self.currentService.getServiceName()
70                 if name is not None:
71                         self["channel"].setText(name)
72                 else:
73                         self["channel"].setText(_("unknown service"))
74
75         def setEvent(self, event):
76                 self.event = event
77                 text = event.getEventName()
78                 short = event.getShortDescription()
79                 ext = event.getExtendedDescription()
80                 if len(short) > 0 and short != text:
81                         text = text + '\n\n' + short
82                 if len(ext) > 0:
83                         if len(text) > 0:
84                                 text = text + '\n\n'
85                         text = text + ext
86                 self.session.currentDialog.instance.setTitle(event.getEventName())
87                 self["epg_description"].setText(text)
88                 self["datetime"].setText(event.getBeginTimeString())
89                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
90
91         def pageUp(self):
92                 self["epg_description"].pageUp()
93         
94         def pageDown(self):
95                 self["epg_description"].pageDown()