timer: add name/description, factor out "parse from epg event", fix some cases where...
[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, parseEvent
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                 newEntry = RecordTimerEntry(self.currentService, *parseEvent(self.event))
42                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
43
44         def timerEditFinished(self, answer):
45                 if (answer[0]):
46                         self.session.nav.RecordTimer.record(answer[1])
47                 else:
48                         print "Timeredit aborted"       
49
50         def setService(self, service):
51                 self.currentService=service
52                 name = self.currentService.getServiceName()
53                 if name is not None:
54                         self["channel"].setText(name)
55                 else:
56                         self["channel"].setText(_("unknown service"))
57
58         def setEvent(self, event):
59                 self.event = event
60                 text = event.getEventName()
61                 short = event.getShortDescription()
62                 ext = event.getExtendedDescription()
63                 if len(short) > 0 and short != text:
64                         text = text + '\n\n' + short
65                 if len(ext) > 0:
66                         if len(text) > 0:
67                                 text = text + '\n\n'
68                         text = text + ext
69                 self.session.currentDialog.instance.setTitle(event.getEventName())
70                 self["epg_description"].setText(text)
71                 self["datetime"].setText(event.getBeginTimeString())
72                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
73
74         def pageUp(self):
75                 self["epg_description"].pageUp()
76         
77         def pageDown(self):
78                 self["epg_description"].pageDown()