don't reload list on movie delete
[enigma2.git] / lib / python / Components / MovieList.py
index 7ec8a9ff3ae9fd91709f22926fb45d0c3d1ae899..666067fc3fb4e8121112b573618eaa269dae5b47 100644 (file)
@@ -25,25 +25,28 @@ RT_WRAP = 32
 # | name of movie              |
 #
 def MovieListEntry(serviceref, serviceHandler):
-       res = [ serviceref ]
+       if serviceref.flags & eServiceReference.mustDescent:
+               return None
 
        info = serviceHandler.info(serviceref)
        
        if info is None:
                # ignore service which refuse to info
-               return
+               return None
        
        len = info.getLength(serviceref)
-       if len:
+       if len > 0:
                len = "%d:%02d" % (len / 60, len % 60)
        else:
                len = "?:??"
        
+       begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
+       res = [ (serviceref, begin) ]
+
        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)
@@ -59,11 +62,11 @@ class MovieList(HTMLComponent, GUIComponent):
        def __init__(self, root):
                GUIComponent.__init__(self)
                self.l = eListboxPythonMultiContent()
-               self.load(root)
-               self.l.setList(self.list)
+               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)
 
@@ -71,7 +74,7 @@ class MovieList(HTMLComponent, GUIComponent):
                return self.instance.getCurrentIndex()
 
        def getCurrent(self):
-               return self.l.getCurrentSelection()
+               return self.l.getCurrentSelection()[0]
        
        def GUIcreate(self, parent):
                self.instance = eListbox(parent)
@@ -82,6 +85,19 @@ 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 removeService(self, service):
+               for l in self.list[:]:
+                       if l[0][0] == service:
+                               self.list.remove(l)
+               self.l.setList(self.list)
+
        def load(self, root):
                # this lists our root service, then building a 
                # nice list
@@ -105,20 +121,20 @@ class MovieList(HTMLComponent, GUIComponent):
                
                # now process them...
                for ref in movieList:
-                       self.list.append(MovieListEntry(ref, serviceHandler))
-                       
+                       a = MovieListEntry(ref, serviceHandler)
+                       if a is not None:
+                               self.list.append(a)
+               
+               self.list.sort(key=lambda x: -x[0][1])
+
        def moveTo(self, serviceref):
                found = 0
                count = 0
                for x in self.list:
-                       if str(ServiceReference(x[0])) == str(ServiceReference(serviceref)):
+                       if str(ServiceReference(x[0][0])) == str(ServiceReference(serviceref)):
                                found = count
                        count += 1
                self.instance.moveSelectionTo(found)
 
-       def reload(self):
-               self.load(self.root)
-               self.l.setList(self.list)
-
        def moveDown(self):
                self.instance.moveSelection(self.instance.moveDown)