fix
[enigma2.git] / lib / python / Screens / MovieSelection.py
index d3a86899b0d51c5d24a11a07b05ad75088fa957c..ce3a9732b2a51d9b409faa38ab04a10592b282f5 100644 (file)
@@ -3,9 +3,56 @@ from Components.Button import Button
 from Components.ServiceList import ServiceList
 from Components.ActionMap import ActionMap
 from Components.MovieList import MovieList
+from Components.DiskInfo import DiskInfo
 
-from enigma import eServiceReference
+from Screens.MessageBox import MessageBox
+from Screens.FixedMenu import FixedMenu
 
+from enigma import eServiceReference, eServiceCenter
+
+class ChannelContextMenu(FixedMenu):
+       def __init__(self, session, csel, service):
+               self.csel = csel
+               self.service = service
+               
+               menu = [("back", self.close), ("delete...", self.delete)]
+               
+               FixedMenu.__init__(self, session, "Movie Menu", menu)
+               self.skinName = "Menu"
+
+       def delete(self):
+               serviceHandler = eServiceCenter.getInstance()
+               offline = serviceHandler.offlineOperations(self.service)
+               result = False
+               if offline is not None:
+                       # simulate first
+                       if not offline.deleteFromDisk(1):
+                               result = True
+               
+               if result == True:
+                       self.session.openWithCallback(self.deleteConfirmed, MessageBox, "Do you really want to delete this recording?")
+               else:
+                       self.session.openWithCallback(self.close, MessageBox, "You cannot delete this!")
+
+       def deleteConfirmed(self, confirmed):
+               if not confirmed:
+                       return self.close()
+                       
+               serviceHandler = eServiceCenter.getInstance()
+               offline = serviceHandler.offlineOperations(self.service)
+               result = False
+               if offline is not None:
+                       # really delete!
+                       if not offline.deleteFromDisk(0):
+                               result = True
+               
+               if result == False:
+                       self.session.openWithCallback(self.close, MessageBox, "Delete failed!")
+               else:
+                       self.csel["list"].reload()
+                       self.close()
+               
 class MovieSelection(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
@@ -16,14 +63,24 @@ class MovieSelection(Screen):
                self["list"] = MovieList(eServiceReference("2:0:1:0:0:0:0:0:0:0:/hdd/movies/"))
                
                #self["okbutton"] = Button("ok", [self.channelSelected])
+               self["freeDiskSpace"] = DiskInfo("/hdd/movies", DiskInfo.FREE)
                
-               self["actions"] = ActionMap(["OkCancelActions"], 
+               self["actions"] = ActionMap(["OkCancelActions", "ContextMenuActions"],
                        {
-                               "cancel": self.close,
+                               "cancel": self.abort,
                                "ok": self.movieSelected,
+                               "contextMenu": self.doContext,
                        })
                self["actions"].csel = self
 
+       def getCurrent(self):
+               return self["list"].getCurrent()[0]
+
        def movieSelected(self):
-               self.session.nav.playService(self["list"].getCurrent()[0])
-               self.close()
+               self.close(self.getCurrent())
+
+       def doContext(self):
+               self.session.open(ChannelContextMenu, self, self.getCurrent())
+
+       def abort(self):
+               self.close(None)