fix bluescreen
[enigma2.git] / lib / python / Screens / EventView.py
index 48d85bf733df6c9e51545e5f14965c94cab471e6..869474615851498b702dc035b9080162423bb43e 100644 (file)
 from Screen import Screen
 from Components.ActionMap import ActionMap
+from Components.Button import Button
 from Components.Label import Label
-from Components.ProgressBar import ProgressBar
-from enigma import eWidget, eServiceEventPtr, eLabel
-
-class EventView(Screen):
-       def __init__(self, session, Event, callback):
-               Screen.__init__(self, session)
+from Components.ScrollLabel import ScrollLabel
+from enigma import eServiceEventPtr, eEPGCachePtr, eEPGCache
+from ServiceReference import ServiceReference
+from RecordTimer import RecordTimerEntry, parseEvent
+from TimerEntry import TimerEntry
+from time import localtime, asctime
 
+class EventViewBase:
+       def __init__(self, Event, Ref, callback=None):
                self.cbFunc = callback
-               print self.cbFunc
-
-               self["epg_description"] = Label()
+               self.currentService=Ref
+               self.isRecording = len(Ref.ref.getPath())
+               self.event = Event
+               self["epg_description"] = ScrollLabel()
                self["datetime"] = Label()
                self["channel"] = Label()
-               self["scrollbar"] = ProgressBar()
                self["duration"] = Label()
-
+               self["key_red"] = Button("")
+               if self.isRecording:
+                       self["key_green"] = Button("")
+               else:
+                       self["key_green"] = Button(_("Add timer"))
+               self["key_yellow"] = Button("")
+               self["key_blue"] = Button("")
                self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
                        {
                                "cancel": self.close,
                                "ok": self.close,
-                               "scrollUp": self.scrollUp,
-                               "scrollDown": self.scrollDown,
+                               "pageUp": self.pageUp,
+                               "pageDown": self.pageDown,
                                "prevEvent": self.prevEvent,
-                               "nextEvent": self.nextEvent
+                               "nextEvent": self.nextEvent,
+                               "timerAdd": self.timerAdd
                        })
-               self.setEvent(Event)
+               self.onShown.append(self.onCreate)
+
+       def onCreate(self):
+               self.setService(self.currentService)
+               self.setEvent(self.event)
 
        def prevEvent(self):
                if self.cbFunc is not None:
-                       self.cbFunc(self.setEvent, -1)
+                       self.cbFunc(self.setEvent, self.setService, -1)
 
        def nextEvent(self):
                if self.cbFunc is not None:
-                       self.cbFunc(self.setEvent, +1)
+                       self.cbFunc(self.setEvent, self.setService, +1)
+
+       def timerAdd(self):
+               if not self.isRecording:
+                       newEntry = RecordTimerEntry(self.currentService, *parseEvent(self.event))
+                       self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
+
+       def timerEditFinished(self, answer):
+               if (answer[0]):
+                       self.session.nav.RecordTimer.record(answer[1])
+               else:
+                       print "Timeredit aborted"
+
+       def setService(self, service):
+               
+               self.currentService=service
+               if self.isRecording:
+                       self["channel"].setText(_("Recording"))
+               else:
+                       name = self.currentService.getServiceName()
+                       if name is not None:
+                               self["channel"].setText(name)
+                       else:
+                               self["channel"].setText(_("unknown service"))
+
+       def sort_func(self,x,y):
+               if x[1] < y[1]:
+                       return -1
+               elif x[1] == y[1]:
+                       return 0
+               else:
+                       return 1
 
        def setEvent(self, event):
-               text = event.getShortDescription()
-               if len(text) > 0:
-                       text = text + '\n\n'
-               text = text + event.getExtendedDescription()
+               self.event = event
+               id = event.getEventId()
+
+               refstr = str(self.currentService)
+               epgcache = eEPGCache.getInstance()
+               text = event.getEventName()
+               short = event.getShortDescription()
+               ext = event.getExtendedDescription()
+               if len(short) > 0 and short != text:
+                       text = text + '\n\n' + short
+               if len(ext) > 0:
+                       if len(text) > 0:
+                               text = text + '\n\n'
+                       text = text + ext
+
+        # search similar broadcastings
+               ret = epgcache.search(('NB', 100, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, id))
+               if ret is not None:
+                       text += '\n\n' + _('Similar broadcasts:')
+                       ret.sort(self.sort_func)
+                       for x in ret:
+                               t = localtime(x[1])
+                               text += '\n%d.%d.%d, %02d:%02d  -  %s'%(t[2], t[1], t[0], t[3], t[4], x[0])
+
+               self.setTitle(event.getEventName())
                self["epg_description"].setText(text)
                self["datetime"].setText(event.getBeginTimeString())
-               self["channel"].setText("Unknown Service")
-               self["duration"].setText("%d min"%(event.getDuration()/60))
+               self["duration"].setText(_("%d min")%(event.getDuration()/60))
 
-       def scrollUp(self):
-               print "scrollUp"
+       def pageUp(self):
+               self["epg_description"].pageUp()
 
-       def scrollDown(self):
-               print "scrollDown"
+       def pageDown(self):
+               self["epg_description"].pageDown()
+
+class EventViewSimple(Screen, EventViewBase):
+       def __init__(self, session, Event, Ref, callback=None):
+               Screen.__init__(self, session)
+               self.skinName = "EventView"
+               EventViewBase.__init__(self, Event, Ref, callback)
+
+class EventViewEPGSelect(Screen, EventViewBase):
+       def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None):
+               Screen.__init__(self, session)
+               self.skinName = "EventView"
+               EventViewBase.__init__(self, Event, Ref, callback)
+               self["key_yellow"].setText(_("Single EPG"))
+               self["key_blue"].setText(_("Multi EPG"))
+               self["epgactions"] = ActionMap(["EventViewEPGActions"],
+                       {
+                               "openSingleServiceEPG": singleEPGCB,
+                               "openMultiServiceEPG": multiEPGCB
+                       })