handle cuesheets
[enigma2.git] / lib / python / Components / ServicePosition.py
index 462102f..349ee39 100644 (file)
@@ -1,8 +1,7 @@
 from PerServiceDisplay import *
 from enigma import eTimer
 
-
-from enigma import pNavigation, iSeekableServicePtr
+from enigma import iPlayableService, iSeekableServicePtr, ePositionGauge
 
 class ServicePosition(PerServiceDisplay):
        TYPE_LENGTH = 0,
@@ -14,8 +13,8 @@ class ServicePosition(PerServiceDisplay):
                self.updateTimer.timeout.get().append(self.update)
                PerServiceDisplay.__init__(self, navcore,
                        {
-                               pNavigation.evNewService: self.newService,
-                               pNavigation.evStopService: self.stopEvent
+                               iPlayableService.evStart: self.newService,
+                               iPlayableService.evEnd: self.stopEvent
                        })
                self.type = type
 #              self.setType(type)
@@ -26,50 +25,98 @@ class ServicePosition(PerServiceDisplay):
        def setType(self, type):
                self.type = type
                
-               seek = iSeekableServicePtr()
-               service = self.navcore.getCurrentService()
-               
-               self.updateTimer.stop()
-               self.available = 0
-               
-               if service != None:
-                       if not service.seek(seek):
-                               if self.type != self.TYPE_LENGTH:
-                                       self.updateTimer.start(500)
-                               
-                               self.length = self.get(self.TYPE_LENGTH)
-                               self.available = 1
-
+               self.updateTimer.start(500)
                self.update()
        
        def get(self, what):
-               seek = iSeekableServicePtr()
                service = self.navcore.getCurrentService()
-               
-               if service != None:
-                       if not service.seek(seek):
-                               if what == self.TYPE_LENGTH:
-                                       r = seek.getLength()
-                               elif what == self.TYPE_POSITION:
-                                       r = seek.getPlayPosition()
-                               if not r[0]:
-                                       return r[1] / 90000
+               seek = service and service.seek()
+               if seek != None:
+                       if what == self.TYPE_LENGTH:
+                               r = seek.getLength()
+                       elif what == self.TYPE_POSITION:
+                               r = seek.getPlayPosition()
+                       if not r[0]:
+                               return r[1] / 90000
                
                return -1
        
        def update(self):
-               if self.available:
+               seek = None
+               service = self.navcore.getCurrentService()
+               if service != None:
+                       seek = service.seek()
+
+               if seek is not None:
                        if self.type == self.TYPE_LENGTH:
-                               l = self.length
+                               l = self.get(self.TYPE_LENGTH)
                        elif self.type == self.TYPE_POSITION:
                                l = self.get(self.TYPE_POSITION)
                        elif self.type == self.TYPE_REMAINING:
-                               l = self.length - self.get(self.TYPE_POSITION)
+                               l = self.get(self.TYPE_LENGTH) - self.get(self.TYPE_POSITION)
                        
                        self.setText("%d:%02d" % (l/60, l%60))
+                       self.updateTimer.start(500)
                else:
+                       self.updateTimer.start(10000)
                        self.setText("-:--")
        
        def stopEvent(self):
                self.updateTimer.stop()
                self.setText("");
+
+class ServicePositionGauge(PerServiceBase):
+       def __init__(self, navcore):
+               PerServiceBase.__init__(self, navcore,
+                       {
+                               iPlayableService.evStart: self.newService,
+                               iPlayableService.evEnd: self.stopEvent,
+                               iPlayableService.evCuesheetChanged: self.newCuesheet
+                       })
+               self.instance = None
+
+       def newService(self):
+               if self.get() is None:  
+                       self.disablePolling()
+               else:
+                       self.enablePolling(interval=500)
+                       self.newCuesheet()
+       
+       def get(self):
+               service = self.navcore.getCurrentService()
+               seek = service and service.seek()
+               if seek is None:
+                       return None
+
+               len = seek.getLength()
+               pos = seek.getPlayPosition()
+               
+               if len[0] or pos[0]:
+                       return (0, 0)
+               return (len[1], pos[1])
+       
+       def poll(self):
+               data = self.get()
+               if data is None:
+                       return
+
+               if self.instance is not None:
+                       self.instance.setLength(data[0])
+                       self.instance.setPosition(data[1])
+               
+       def stopEvent(self):
+               self.disablePolling()
+
+       def GUIcreate(self, parent):
+               self.instance = ePositionGauge(parent)
+               self.newService()
+       
+       def GUIdelete(self):
+               self.instance = None
+
+       def newCuesheet(self):
+               service = self.navcore.getCurrentService()
+               cue = service and service.cueSheet()
+               cutlist = (cue and cue.getCutList()) or [ ]
+               if self.instance is not None:
+                       self.instance.setInOutList(cutlist)