1 from Screen import Screen
2 from Screens.TimerEdit import TimerSanityConflict
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import ActionMap
5 from Components.Button import Button
6 from Components.Label import Label
7 from Components.ScrollLabel import ScrollLabel
8 from Components.TimerList import TimerList
9 from Components.UsageConfig import preferredTimerPath
10 from enigma import eEPGCache, eTimer, eServiceReference
11 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
12 from TimerEntry import TimerEntry
13 from time import localtime
14 from Components.config import config
20 def __init__(self, Event, Ref, callback=None, similarEPGCB=None):
21 self.similarEPGCB = similarEPGCB
22 self.cbFunc = callback
23 self.currentService=Ref
24 self.isRecording = (not Ref.ref.flags & eServiceReference.isGroup) and Ref.ref.getPath()
26 self["epg_description"] = ScrollLabel()
27 self["datetime"] = Label()
28 self["channel"] = Label()
29 self["duration"] = Label()
30 self["key_red"] = Button("")
31 if similarEPGCB is not None:
32 self.SimilarBroadcastTimer = eTimer()
33 self.SimilarBroadcastTimer.callback.append(self.getSimilarEvents)
35 self.SimilarBroadcastTimer = None
36 self.key_green_choice = self.ADD_TIMER
38 self["key_green"] = Button("")
40 self["key_green"] = Button(_("Add timer"))
41 self["key_yellow"] = Button("")
42 self["key_blue"] = Button("")
43 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
47 "pageUp": self.pageUp,
48 "pageDown": self.pageDown,
49 "prevEvent": self.prevEvent,
50 "nextEvent": self.nextEvent,
51 "timerAdd": self.timerAdd,
52 "openSimilarList": self.openSimilarList
54 self.onShown.append(self.onCreate)
57 self.setService(self.currentService)
58 self.setEvent(self.event)
61 if self.cbFunc is not None:
62 self.cbFunc(self.setEvent, self.setService, -1)
65 if self.cbFunc is not None:
66 self.cbFunc(self.setEvent, self.setService, +1)
68 def removeTimer(self, timer):
69 timer.afterEvent = AFTEREVENT.NONE
70 self.session.nav.RecordTimer.removeEntry(timer)
71 self["key_green"].setText(_("Add timer"))
72 self.key_green_choice = self.ADD_TIMER
78 serviceref = self.currentService
81 eventid = event.getEventId()
82 refstr = serviceref.ref.toString()
83 for timer in self.session.nav.RecordTimer.timer_list:
84 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
85 cb_func = lambda ret : not ret or self.removeTimer(timer)
86 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
89 newEntry = RecordTimerEntry(self.currentService, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(self.event))
90 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
92 def finishedAdd(self, answer):
96 simulTimerList = self.session.nav.RecordTimer.record(entry)
97 if simulTimerList is not None:
98 for x in simulTimerList:
99 if x.setAutoincreaseEnd(entry):
100 self.session.nav.RecordTimer.timeChanged(x)
101 simulTimerList = self.session.nav.RecordTimer.record(entry)
102 if simulTimerList is not None:
103 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
104 self["key_green"].setText(_("Remove timer"))
105 self.key_green_choice = self.REMOVE_TIMER
107 self["key_green"].setText(_("Add timer"))
108 self.key_green_choice = self.ADD_TIMER
109 print "Timeredit aborted"
111 def finishSanityCorrection(self, answer):
112 self.finishedAdd(answer)
114 def setService(self, service):
115 self.currentService=service
117 self["channel"].setText(_("Recording"))
119 name = self.currentService.getServiceName()
121 self["channel"].setText(name)
123 self["channel"].setText(_("unknown service"))
125 def sort_func(self,x,y):
133 def setEvent(self, event):
137 text = event.getEventName()
138 short = event.getShortDescription()
139 ext = event.getExtendedDescription()
140 if short and short != text:
141 text += '\n\n' + short
147 self.setTitle(event.getEventName())
148 self["epg_description"].setText(text)
149 self["datetime"].setText(event.getBeginTimeString())
150 self["duration"].setText(_("%d min")%(event.getDuration()/60))
151 self["key_red"].setText("")
152 if self.SimilarBroadcastTimer is not None:
153 self.SimilarBroadcastTimer.start(400,True)
155 serviceref = self.currentService
156 eventid = self.event.getEventId()
157 refstr = serviceref.ref.toString()
158 isRecordEvent = False
159 for timer in self.session.nav.RecordTimer.timer_list:
160 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
163 if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
164 self["key_green"].setText(_("Remove timer"))
165 self.key_green_choice = self.REMOVE_TIMER
166 elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
167 self["key_green"].setText(_("Add timer"))
168 self.key_green_choice = self.ADD_TIMER
172 self["epg_description"].pageUp()
175 self["epg_description"].pageDown()
177 def getSimilarEvents(self):
178 # search similar broadcastings
179 refstr = str(self.currentService)
180 id = self.event.getEventId()
181 epgcache = eEPGCache.getInstance()
182 ret = epgcache.search(('NB', 100, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, id))
184 descr = self["epg_description"]
185 text = descr.getText()
186 text += '\n\n' + _('Similar broadcasts:')
187 ret.sort(self.sort_func)
190 text += '\n%d.%d.%d, %02d:%02d - %s'%(t[2], t[1], t[0], t[3], t[4], x[0])
192 self["key_red"].setText(_("Similar"))
194 def openSimilarList(self):
195 if self.similarEPGCB is not None and self["key_red"].getText():
196 id = self.event and self.event.getEventId()
197 refstr = str(self.currentService)
199 self.similarEPGCB(id, refstr)
201 class EventViewSimple(Screen, EventViewBase):
202 def __init__(self, session, Event, Ref, callback=None, similarEPGCB=None):
203 Screen.__init__(self, session)
204 self.skinName = "EventView"
205 EventViewBase.__init__(self, Event, Ref, callback, similarEPGCB)
207 class EventViewEPGSelect(Screen, EventViewBase):
208 def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None, similarEPGCB=None):
209 Screen.__init__(self, session)
210 self.skinName = "EventView"
211 EventViewBase.__init__(self, Event, Ref, callback, similarEPGCB)
212 self["key_yellow"].setText(_("Single EPG"))
213 self["key_blue"].setText(_("Multi EPG"))
214 self["epgactions"] = ActionMap(["EventViewEPGActions"],
216 "openSingleServiceEPG": singleEPGCB,
217 "openMultiServiceEPG": multiEPGCB,