nicer
[enigma2.git] / lib / python / Components / MovieList.py
index 003302b314f44dd7b68ee435d3cbb06ac41e7a2a..ff047225ecdf4e9880c30a290c7465ebd157583d 100644 (file)
@@ -1,14 +1,14 @@
 from HTMLComponent import *
 from GUIComponent import *
+from Tools.FuzzyDate import FuzzyTime
+from ServiceReference import ServiceReference
 
-from enigma import eListboxPythonMultiContent, eListbox, gFont
+from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation
 
 from enigma import eServiceReference, eServiceCenter, \
        eServiceCenterPtr, iListableServicePtr, \
        iStaticServiceInformationPtr
 
-
-
 RT_HALIGN_LEFT = 0
 RT_HALIGN_RIGHT = 1
 RT_HALIGN_CENTER = 2
@@ -27,11 +27,10 @@ RT_WRAP = 32
 def MovieListEntry(serviceref, serviceHandler):
        res = [ serviceref ]
 
-       info = iStaticServiceInformationPtr()
-
-       if serviceHandler.info(serviceref, info):
+       info = serviceHandler.info(serviceref)
+       
+       if info is None:
                # ignore service which refuse to info
-               del info
                return
        
        len = info.getLength(serviceref)
@@ -40,10 +39,19 @@ def MovieListEntry(serviceref, serviceHandler):
        else:
                len = "?:??"
        
-       res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref)))
-       res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, "Toller Film"))
-       res.append((0, 50, 200, 20, 1, RT_HALIGN_LEFT, "Aufgenommen: irgendwann"))
-       res.append((200, 50, 200, 20, 1, RT_HALIGN_RIGHT, len))
+       res.append((0, 0, 0, 560, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref)))
+       
+       description = info.getInfoString(serviceref, iServiceInformation.sDescription)
+       begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
+       
+       begin_string = ""
+       if begin > 0:
+               t = FuzzyTime(begin)
+               begin_string = t[0] + ", " + t[1]
+       
+       res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT, description))
+       res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 270, 20, 1, RT_HALIGN_LEFT, begin_string))
+       res.append((eListboxPythonMultiContent.TYPE_TEXT, 290, 50, 270, 20, 1, RT_HALIGN_RIGHT, len))
        
        return res
 
@@ -51,11 +59,17 @@ class MovieList(HTMLComponent, GUIComponent):
        def __init__(self, root):
                GUIComponent.__init__(self)
                self.l = eListboxPythonMultiContent()
-               self.load(root)
-               self.l.setList(self.list)
-               self.l.setFont(0, gFont("Arial", 30))
-               self.l.setFont(1, gFont("Arial", 18))
-       
+               if root is not None:
+                       self.reload(root)
+               self.l.setFont(0, gFont("Regular", 30))
+               self.l.setFont(1, gFont("Regular", 18))
+               
+       def moveToIndex(self, index):
+               self.instance.moveSelectionTo(index)
+
+       def getCurrentIndex(self):
+               return self.instance.getCurrentIndex()
+
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
@@ -68,24 +82,30 @@ class MovieList(HTMLComponent, GUIComponent):
                self.instance.setContent(None)
                self.instance = None
 
+       def reload(self, root = None):
+               if root is not None:
+                       self.load(root)
+               else:
+                       self.load(self.root)
+               self.l.setList(self.list)
+
        def load(self, root):
                # this lists our root service, then building a 
                # nice list
                
                self.list = [ ]
+               self.root = root
                
-               serviceHandler = eServiceCenterPtr()
-               eServiceCenter.getInstance(serviceHandler)
-               list = iListableServicePtr()
+               serviceHandler = eServiceCenter.getInstance()
+               list = serviceHandler.list(root)
                
-               if serviceHandler.list(root, list):
+               if list is None:
                        raise "listing of movies failed"
 
                movieList = [ ]
                while 1:
-                       s = eServiceReference()
-                       if list.getNext(s):
-                               del s
+                       s = list.getNext()
+                       if not s.valid():
                                del list
                                break
                        movieList.append(s)
@@ -93,3 +113,15 @@ class MovieList(HTMLComponent, GUIComponent):
                # now process them...
                for ref in movieList:
                        self.list.append(MovieListEntry(ref, serviceHandler))
+                       
+       def moveTo(self, serviceref):
+               found = 0
+               count = 0
+               for x in self.list:
+                       if str(ServiceReference(x[0])) == str(ServiceReference(serviceref)):
+                               found = count
+                       count += 1
+               self.instance.moveSelectionTo(found)
+
+       def moveDown(self):
+               self.instance.moveSelection(self.instance.moveDown)