allow gstreamer to signalize missing plugins to the gui (requires reconfiguring enigm...
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / plugin.py
index 1db873761d5f8794b6c792c02be83f9cefd25fc2..b201d2c6df682a8a2e006e4dec01bdce6965525d 100644 (file)
@@ -12,6 +12,7 @@ from Components.MenuList import MenuList
 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
 from Components.config import config
 from Tools.Directories import pathExists, fileExists
 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
 from Components.config import config
 from Tools.Directories import pathExists, fileExists
+from Components.Harddisk import harddiskmanager
 
 import servicedvd # load c++ part of dvd player plugin
 
 
 import servicedvd # load c++ part of dvd player plugin
 
@@ -22,15 +23,13 @@ class FileBrowser(Screen):
        <screen name="FileBrowser" position="100,100" size="520,376" title="DVD File Browser" >
                <widget name="filelist" position="0,0" size="520,376" scrollbarMode="showOnDemand" />
        </screen>"""
        <screen name="FileBrowser" position="100,100" size="520,376" title="DVD File Browser" >
                <widget name="filelist" position="0,0" size="520,376" scrollbarMode="showOnDemand" />
        </screen>"""
-       def __init__(self, session, dvd_filelist = None):
+       def __init__(self, session, dvd_filelist = [ ]):
                Screen.__init__(self, session)
 
                Screen.__init__(self, session)
 
-               if dvd_filelist:
-                       self.dvd_filelist = dvd_filelist
+               self.dvd_filelist = dvd_filelist
+               if len(dvd_filelist):   
                        self["filelist"] = MenuList(self.dvd_filelist)
                        self["filelist"] = MenuList(self.dvd_filelist)
-
                else:
                else:
-                       self.dvd_filelist = None
                        global lastpath
                        if lastpath is not None:
                                currDir = lastpath + "/"
                        global lastpath
                        if lastpath is not None:
                                currDir = lastpath + "/"
@@ -49,24 +48,31 @@ class FileBrowser(Screen):
                        })
 
        def ok(self):
                        })
 
        def ok(self):
-               if self.dvd_filelist:
+               if len(self.dvd_filelist):
                        print "OK " + self["filelist"].getCurrent()
                        self.close(self["filelist"].getCurrent())
                else:
                        global lastpath
                        filename = self["filelist"].getFilename()
                        if filename is not None:
                        print "OK " + self["filelist"].getCurrent()
                        self.close(self["filelist"].getCurrent())
                else:
                        global lastpath
                        filename = self["filelist"].getFilename()
                        if filename is not None:
-                               lastpath = filename[0:filename.rfind("/")]
                                if filename.upper().endswith("VIDEO_TS/"):
                                        print "dvd structure found, trying to open..."
                                if filename.upper().endswith("VIDEO_TS/"):
                                        print "dvd structure found, trying to open..."
-                                       self.close(filename[0:-9])
+                                       dvdpath = filename[0:-9]
+                                       lastpath = (dvdpath.rstrip("/").rsplit("/",1))[0]
+                                       print "lastpath video_ts/=", lastpath
+                                       self.close(dvdpath)
+                                       return
                        if self["filelist"].canDescent(): # isDir
                                self["filelist"].descent()
                                pathname = self["filelist"].getCurrentDirectory() or ""
                                if fileExists(pathname+"VIDEO_TS.IFO"):
                                        print "dvd structure found, trying to open..."
                        if self["filelist"].canDescent(): # isDir
                                self["filelist"].descent()
                                pathname = self["filelist"].getCurrentDirectory() or ""
                                if fileExists(pathname+"VIDEO_TS.IFO"):
                                        print "dvd structure found, trying to open..."
+                                       lastpath = (pathname.rstrip("/").rsplit("/",1))[0]
+                                       print "lastpath video_ts.ifo=", lastpath
                                        self.close(pathname)
                        else:
                                        self.close(pathname)
                        else:
+                               lastpath = filename[0:filename.rfind("/")]
+                               print "lastpath directory=", lastpath
                                self.close(filename)
 
        def exit(self):
                                self.close(filename)
 
        def exit(self):
@@ -228,7 +234,7 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                config.seek.stepwise_repeat.value = self.saved_config_seek_stepwise_repeat
                config.seek.on_pause.value = self.saved_config_seek_on_pause
 
                config.seek.stepwise_repeat.value = self.saved_config_seek_stepwise_repeat
                config.seek.on_pause.value = self.saved_config_seek_on_pause
 
-       def __init__(self, session, dvd_device = None, dvd_filelist = None, args = None):
+       def __init__(self, session, dvd_device = None, dvd_filelist = [ ], args = None):
                Screen.__init__(self, session)
                InfoBarBase.__init__(self)
                InfoBarNotifications.__init__(self)
                Screen.__init__(self, session)
                InfoBarBase.__init__(self)
                InfoBarNotifications.__init__(self)
@@ -246,6 +252,8 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                self["audioLabel"] = Label("n/a")
                self["subtitleLabel"] = Label("")
                self["chapterLabel"] = Label("")
                self["audioLabel"] = Label("n/a")
                self["subtitleLabel"] = Label("")
                self["chapterLabel"] = Label("")
+               self.last_audioTuple = None
+               self.last_subtitleTuple = None
                self.totalChapters = 0
                self.currentChapter = 0
                self.totalTitles = 0
                self.totalChapters = 0
                self.currentChapter = 0
                self.totalTitles = 0
@@ -268,13 +276,13 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                                iPlayableService.evUser+12: self.__menuClosed
                        })
 
                                iPlayableService.evUser+12: self.__menuClosed
                        })
 
-               self["DVDPlayerDirectionActions"] = HelpableActionMap(self, "DirectionActions",
+               self["DVDPlayerDirectionActions"] = ActionMap(["DirectionActions"],
                        {
                                #MENU KEY DOWN ACTIONS
                        {
                                #MENU KEY DOWN ACTIONS
-                               "left": (self.keyLeft, _("DVD left key")),
-                               "right": (self.keyRight, _("DVD right key")),
-                               "up": (self.keyUp, _("DVD up key")),
-                               "down": (self.keyDown, _("DVD down key")),
+                               "left": self.keyLeft,
+                               "right": self.keyRight,
+                               "up": self.keyUp,
+                               "down": self.keyDown,
 
                                #MENU KEY REPEATED ACTIONS
                                "leftRepeated": self.doNothing,
 
                                #MENU KEY REPEATED ACTIONS
                                "leftRepeated": self.doNothing,
@@ -287,13 +295,13 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                                "rightUp": self.doNothing,
                                "upUp": self.doNothing,
                                "downUp": self.doNothing,
                                "rightUp": self.doNothing,
                                "upUp": self.doNothing,
                                "downUp": self.doNothing,
-                       }, -2)
+                       })
 
 
-               self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
+               self["OkCancelActions"] = ActionMap(["OkCancelActions"],
                        {
                        {
-                               "ok": (self.keyOk, _("DVD ENTER key")),
+                               "ok": self.keyOk,
                                "cancel": self.keyCancel,
                                "cancel": self.keyCancel,
-                       }, -2)
+                       })
 
                self["DVDPlayerPlaybackActions"] = HelpableActionMap(self, "DVDPlayerActions",
                        {
 
                self["DVDPlayerPlaybackActions"] = HelpableActionMap(self, "DVDPlayerActions",
                        {
@@ -308,7 +316,7 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                                "dvdAudioMenu": (self.enterDVDAudioMenu, _("(show optional DVD audio menu)")),
                                "nextAudioTrack": (self.nextAudioTrack, _("switch to the next audio track")),
                                "nextSubtitleTrack": (self.nextSubtitleTrack, _("switch to the next subtitle language")),
                                "dvdAudioMenu": (self.enterDVDAudioMenu, _("(show optional DVD audio menu)")),
                                "nextAudioTrack": (self.nextAudioTrack, _("switch to the next audio track")),
                                "nextSubtitleTrack": (self.nextSubtitleTrack, _("switch to the next subtitle language")),
-                               "seekBeginning": (self.seekBeginning, _("Jump to video title 1 (play movie from start)")),
+                               "seekBeginning": self.seekBeginning,
                        }, -2)
                        
                self["NumberActions"] = NumberActionMap( [ "NumberActions"],
                        }, -2)
                        
                self["NumberActions"] = NumberActionMap( [ "NumberActions"],
@@ -331,9 +339,9 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                                self.dvd_device = dvd_device
                                self.physicalDVD = True
                else:
                                self.dvd_device = dvd_device
                                self.physicalDVD = True
                else:
-                       if fileExists("/dev/cdroms/cdrom0"):
-                               print "physical dvd found (/dev/cdroms/cdrom0)"
-                               self.dvd_device = "/dev/cdroms/cdrom0"
+                       if fileExists(harddiskmanager.getCD()):
+                               print "physical dvd found:", harddiskmanager.getCD()
+                               self.dvd_device = harddiskmanager.getCD()
                                self.physicalDVD = True
                        else:
                                self.dvd_device = None
                                self.physicalDVD = True
                        else:
                                self.dvd_device = None
@@ -422,20 +430,24 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
        def __osdAudioInfoAvail(self):
                audioTuple = self.service.info().getInfoObject(iServiceInformation.sUser+6)
                print "AudioInfoAvail ", repr(audioTuple)
        def __osdAudioInfoAvail(self):
                audioTuple = self.service.info().getInfoObject(iServiceInformation.sUser+6)
                print "AudioInfoAvail ", repr(audioTuple)
-               audioString = "%d: %s (%s)" % (audioTuple[0],audioTuple[1],audioTuple[2])
-               self["audioLabel"].setText(audioString)
-               if not self.in_menu:
-                       self.doShow()
+               if audioTuple:
+                       audioString = "%d: %s (%s)" % (audioTuple[0],audioTuple[1],audioTuple[2])
+                       self["audioLabel"].setText(audioString)
+                       if audioTuple != self.last_audioTuple and not self.in_menu:
+                               self.doShow()
+                       self.last_audioTuple = audioTuple
 
        def __osdSubtitleInfoAvail(self):
                subtitleTuple = self.service.info().getInfoObject(iServiceInformation.sUser+7)
                print "SubtitleInfoAvail ", repr(subtitleTuple)
 
        def __osdSubtitleInfoAvail(self):
                subtitleTuple = self.service.info().getInfoObject(iServiceInformation.sUser+7)
                print "SubtitleInfoAvail ", repr(subtitleTuple)
-               subtitleString = ""
-               if subtitleTuple[0] is not 0:
-                       subtitleString = "%d: %s" % (subtitleTuple[0],subtitleTuple[1])
-               self["subtitleLabel"].setText(subtitleString)
-               if not self.in_menu:
-                       self.doShow()
+               if subtitleTuple:
+                       subtitleString = ""
+                       if subtitleTuple[0] is not 0:
+                               subtitleString = "%d: %s" % (subtitleTuple[0],subtitleTuple[1])
+                       self["subtitleLabel"].setText(subtitleString)
+                       if subtitleTuple != self.last_subtitleTuple and not self.in_menu:
+                               self.doShow()
+                       self.last_subtitleTuple = subtitleTuple
 
        def __chapterUpdated(self):
                self.currentChapter = self.service.info().getInfo(iServiceInformation.sCurrentChapter)
 
        def __chapterUpdated(self):
                self.currentChapter = self.service.info().getInfo(iServiceInformation.sCurrentChapter)
@@ -452,10 +464,10 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                        self.doShow()
                
        def askLeavePlayer(self):
                        self.doShow()
                
        def askLeavePlayer(self):
-               if self.physicalDVD:
-                       self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list=[(_("Continue playing"), "play"), (_("Exit"), "exit")])
-               else:
-                       self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list=[(_("Continue playing"), "play"), (_("Return to file browser"), "browser"), (_("Exit"), "exit")])
+               choices = [(_("Continue playing"), "play"), (_("Exit"), "exit")]
+               if not self.physicalDVD:
+                       choices.insert(1,(_("Return to file browser"), "browser"))                      
+               self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list = choices)
 
        def nextAudioTrack(self):
                if self.service:
 
        def nextAudioTrack(self):
                if self.service:
@@ -529,11 +541,13 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                self.askLeavePlayer()
 
        def showFileBrowser(self):
                self.askLeavePlayer()
 
        def showFileBrowser(self):
-               if self.physicalDVD:
-                       if self.dvd_device == "/dev/cdroms/cdrom0":
+               if self.physicalDVD and len(self.dvd_filelist) == 0:
+                       if self.dvd_device == harddiskmanager.getCD():
                                self.session.openWithCallback(self.DVDdriveCB, MessageBox, text=_("Do you want to play DVD in drive?"), timeout=5 )
                        else:
                                self.DVDdriveCB(True)
                                self.session.openWithCallback(self.DVDdriveCB, MessageBox, text=_("Do you want to play DVD in drive?"), timeout=5 )
                        else:
                                self.DVDdriveCB(True)
+               elif len(self.dvd_filelist) == 1:
+                       self.FileBrowserClosed(self.dvd_filelist[0])
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, self.dvd_filelist)
        
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, self.dvd_filelist)
        
@@ -542,6 +556,7 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                        self.FileBrowserClosed(self.dvd_device)
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser)
                        self.FileBrowserClosed(self.dvd_device)
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser)
+                       self.physicalDVD = False
 
        def FileBrowserClosed(self, val):
                curref = self.session.nav.getCurrentlyPlayingServiceReference()
 
        def FileBrowserClosed(self, val):
                curref = self.session.nav.getCurrentlyPlayingServiceReference()
@@ -585,7 +600,10 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                print "playLastCB", answer, self.resume_point
                if self.service:
                        seek = self.service.seek()
                print "playLastCB", answer, self.resume_point
                if self.service:
                        seek = self.service.seek()
-                       seek.seekTo(self.resume_point)
+                       if answer == True:
+                               seek.seekTo(self.resume_point)
+                       pause = self.service.pause()
+                       pause.unpause()
                self.hideAfterResume()
 
        def showAfterCuesheetOperation(self):
                self.hideAfterResume()
 
        def showAfterCuesheetOperation(self):