store a .eit file for each recoring this holds raw eit event informations
[enigma2.git] / lib / python / Screens / EventView.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Button import Button
4 from Components.Label import Label
5 from Components.ScrollLabel import ScrollLabel
6 from enigma import eServiceEventPtr
7 from ServiceReference import ServiceReference
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from TimerEntry import TimerEntry
10
11 class EventViewBase:
12         def __init__(self, Event, Ref, callback=None):
13                 self.cbFunc = callback
14                 self.currentService=Ref
15                 self.isRecording = len(Ref.ref.getPath())
16                 self.event = Event
17                 self["epg_description"] = ScrollLabel()
18                 self["datetime"] = Label()
19                 self["channel"] = Label()
20                 self["duration"] = Label()
21                 self["key_red"] = Button("")
22                 if self.isRecording:
23                         self["key_green"] = Button("")
24                 else:
25                         self["key_green"] = Button(_("Add timer"))
26                 self["key_yellow"] = Button("")
27                 self["key_blue"] = Button("")
28                 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
29                         {
30                                 "cancel": self.close,
31                                 "ok": self.close,
32                                 "pageUp": self.pageUp,
33                                 "pageDown": self.pageDown,
34                                 "prevEvent": self.prevEvent,
35                                 "nextEvent": self.nextEvent,
36                                 "timerAdd": self.timerAdd
37                         })
38                 self.onShown.append(self.onCreate)
39
40         def onCreate(self):
41                 self.setEvent(self.event)
42                 self.setService(self.currentService)
43
44         def prevEvent(self):
45                 if self.cbFunc is not None:
46                         self.cbFunc(self.setEvent, self.setService, -1)
47
48         def nextEvent(self):
49                 if self.cbFunc is not None:
50                         self.cbFunc(self.setEvent, self.setService, +1)
51
52         def timerAdd(self):
53                 if not self.isRecording:
54                         newEntry = RecordTimerEntry(self.currentService, *parseEvent(self.event))
55                         self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
56
57         def timerEditFinished(self, answer):
58                 if (answer[0]):
59                         self.session.nav.RecordTimer.record(answer[1])
60                 else:
61                         print "Timeredit aborted"
62
63         def setService(self, service):
64                 self.currentService=service
65                 if self.isRecording:
66                         self["channel"].setText(_("Recording"))
67                 else:
68                         name = self.currentService.getServiceName()
69                         if name is not None:
70                                 self["channel"].setText(name)
71                         else:
72                                 self["channel"].setText(_("unknown service"))
73
74         def setEvent(self, event):
75                 self.event = event
76                 text = event.getEventName()
77                 short = event.getShortDescription()
78                 ext = event.getExtendedDescription()
79                 if len(short) > 0 and short != text:
80                         text = text + '\n\n' + short
81                 if len(ext) > 0:
82                         if len(text) > 0:
83                                 text = text + '\n\n'
84                         text = text + ext
85                 self.session.currentDialog.instance.setTitle(event.getEventName())
86                 self["epg_description"].setText(text)
87                 self["datetime"].setText(event.getBeginTimeString())
88                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
89
90         def pageUp(self):
91                 self["epg_description"].pageUp()
92
93         def pageDown(self):
94                 self["epg_description"].pageDown()
95
96 class EventViewSimple(Screen, EventViewBase):
97         def __init__(self, session, Event, Ref, callback=None):
98                 Screen.__init__(self, session)
99                 self.skinName = "EventView"
100                 EventViewBase.__init__(self, Event, Ref, callback)
101
102 class EventViewEPGSelect(Screen, EventViewBase):
103         def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None):
104                 Screen.__init__(self, session)
105                 self.skinName = "EventView"
106                 EventViewBase.__init__(self, Event, Ref, callback)
107                 self["key_yellow"].setText(_("Single EPG"))
108                 self["key_blue"].setText(_("Multi EPG"))
109                 self["epgactions"] = ActionMap(["EventViewEPGActions"],
110                         {
111                                 "openSingleServiceEPG": singleEPGCB,
112                                 "openMultiServiceEPG": multiEPGCB
113                         })