some work on the timer sanity check (overlapping timers solver)
[enigma2.git] / lib / python / Screens / MovieSelection.py
index f5f2652824023453e6a607e492cef67782487d4c..effb5389222a8e423a1a208de638f8dfa11b73e9 100644 (file)
@@ -3,27 +3,113 @@ 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 Components.Label import Label
 
-from enigma import eServiceReference
+from Screens.MessageBox import MessageBox
+from Screens.FixedMenu import FixedMenu
 
+from Tools.Directories import *
+
+from enigma import eServiceReference, eServiceCenter, eTimer
+
+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!"), MessageBox.TYPE_ERROR)
+
+       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!"), MessageBox.TYPE_ERROR)
+               else:
+                       list = self.csel["list"]
+                       currentIndex = list.getCurrentIndex()
+                       list.moveDown()
+                       if list.getCurrentIndex() == currentIndex:
+                               currentIndex -= 1
+                       list.reload()
+                       list.moveToIndex(currentIndex)
+                       self.close()
 class MovieSelection(Screen):
-       def __init__(self, session):
+       def __init__(self, session, selectedmovie = None):
                Screen.__init__(self, session)
                
                self.movemode = False
                self.bouquet_mark_edit = False
                
-               self["list"] = MovieList(eServiceReference("2:0:1:0:0:0:0:0:0:0:/"))
+               self.delayTimer = eTimer()
+               self.delayTimer.timeout.get().append(self.updateHDDData)
+               
+               self["waitingtext"] = Label(_("Please wait... Loading list..."))
+               
+               self["list"] = MovieList(None)
+               self.selectedmovie = selectedmovie
                
                #self["okbutton"] = Button("ok", [self.channelSelected])
+               self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False)
                
-               self["actions"] = ActionMap(["OkCancelActions"], 
+               self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions"],
                        {
-                               "cancel": self.close,
+                               "cancel": self.abort,
                                "ok": self.movieSelected,
+                               "contextMenu": self.doContext,
                        })
                self["actions"].csel = self
+               self.onShown.append(self.go)
+               
+       def go(self):
+               self.delayTimer.start(0, 1)
+
+       def updateHDDData(self):
+               self["list"].reload(eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)))
+               if (self.selectedmovie is not None):
+                       self.moveTo()
+               self["waitingtext"].instance.hide()
+                                               
+               self["freeDiskSpace"].update()
+
+       def moveTo(self):
+               self["list"].moveTo(self.selectedmovie)
+
+       def getCurrent(self):
+               return self["list"].getCurrent()[0]
 
        def movieSelected(self):
-#              self.session.nav.playService(self["list"].getCurrent())
-               self.close()
+               self.close(self.getCurrent())
+
+       def doContext(self):
+               self.session.open(ChannelContextMenu, self, self.getCurrent())
+
+       def abort(self):
+               self.close(None)