Merge branch 'bug_236_recordpath'
authorghost <andreas.monzner@multimedia-labs.de>
Tue, 22 Dec 2009 15:08:21 +0000 (16:08 +0100)
committerghost <andreas.monzner@multimedia-labs.de>
Tue, 22 Dec 2009 15:08:21 +0000 (16:08 +0100)
1  2 
data/menu.xml
lib/python/Components/FileList.py
lib/python/Components/config.py
lib/python/Screens/InfoBarGenerics.py
lib/python/Screens/TimerEntry.py

diff --combined data/menu.xml
@@@ -70,7 -70,7 +70,7 @@@
                                        <item level="1" text="Device Setup..." entryID="device_setup"><screen module="NetworkSetup" screen="NetworkAdapterSelection"/></item>
                                        <item level="1" text="Nameserver Setup..." entryID="dns_setup"><screen module="NetworkSetup" screen="NameserverSetup"/></item>
                                </menu>-->
-                               <item level="2" text="Timeshift path..." entryId="timeshift_path"><screen module="LocationBox" screen="TimeshiftLocationBox" /></item>
+                               <item level="2" text="Recording paths..." entryId="RecordPaths"><screen module="RecordPaths" screen="RecordPathsSettings" /></item>
                        </menu>
                        <item weight="10" level="1" text="Common Interface" entryID="ci_setup" requires="CommonInterface"><screen module="Ci" screen="CiSelection" /></item>
                        <item weight="15" level="0" text="Parental control" entryID="parental_setup"><screen module="ParentalControlSetup" screen="ParentalControlSetup" /></item>
@@@ -104,7 -104,6 +104,7 @@@ self.session.openWithCallback(msgClosed
                        <item text="Standby" entryID="standby"><screen module="Standby" screen="Standby"/></item>
                        <item text="Restart" entryID="restart"><screen module="Standby" screen="TryQuitMainloop">2</screen></item>
                        <item level="2" text="Restart GUI" entryID="restart_enigma"><screen module="Standby" screen="TryQuitMainloop">3</screen></item>
 -                      <item text="Deep Standby" entryID="deep_standby"><screen module="Standby" screen="TryQuitMainloop">1</screen></item>
 +                      <item text="Deep Standby" requires="DeepstandbySupport" entryID="deep_standby"><screen module="Standby" screen="TryQuitMainloop">1</screen></item>
 +                      <item text="Shutdown" requires="!DeepstandbySupport" entryID="deep_standby"><screen module="Standby" screen="TryQuitMainloop">1</screen></item>
                </menu>
  </menu>
@@@ -3,7 -3,7 +3,7 @@@ from os import path as os_path, listdi
  from MenuList import MenuList
  from Components.Harddisk import harddiskmanager
  
- from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
+ from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename, fileExists
  
  from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, \
        eServiceReference, eServiceCenter, gFont
@@@ -23,7 -23,6 +23,7 @@@ EXTENSIONS = 
                "ts": "movie",
                "avi": "movie",
                "divx": "movie",
 +              "m4v": "movie",
                "mpg": "movie",
                "mpeg": "movie",
                "mkv": "movie",
@@@ -160,8 -159,11 +160,11 @@@ class FileList(MenuList)
                        directories.sort()
                        files.sort()
                else:
-                       if os_path.exists(directory):
-                               files = listdir(directory)
+                       if fileExists(directory):
+                               try:
+                                       files = listdir(directory)
+                               except:
+                                       files = []
                                files.sort()
                                tmpfiles = files[:]
                                for x in tmpfiles:
@@@ -374,8 -376,11 +377,11 @@@ class MultiFileSelectList(FileList)
                        directories.sort()
                        files.sort()
                else:
-                       if os_path.exists(directory):
-                               files = listdir(directory)
+                       if fileExists(directory):
+                               try:
+                                       files = listdir(directory)
+                               except:
+                                       files = []
                                files.sort()
                                tmpfiles = files[:]
                                for x in tmpfiles:
@@@ -1,6 -1,6 +1,6 @@@
  from enigma import getPrevAsciiCode
  from Tools.NumericalTextInput import NumericalTextInput
- from Tools.Directories import resolveFilename, SCOPE_CONFIG
+ from Tools.Directories import resolveFilename, SCOPE_CONFIG, fileExists
  from Components.Harddisk import harddiskmanager
  from copy import copy as copy_copy
  from os import path as os_path
@@@ -1017,40 -1017,6 +1017,40 @@@ class ConfigPassword(ConfigText)
                ConfigText.onDeselect(self, session)
                self.hidden = True
  
 +# lets the user select between [min, min+stepwidth, min+(stepwidth*2)..., maxval] with maxval <= max depending
 +# on the stepwidth
 +# min, max, stepwidth, default are int values
 +# wraparound: pressing RIGHT key at max value brings you to min value and vice versa if set to True
 +class ConfigSelectionNumber(ConfigSelection):
 +      def __init__(self, min, max, stepwidth, default = None, wraparound = False):
 +              self.wraparound = wraparound
 +              if default is None:
 +                      default = min
 +              default = str(default)
 +              choices = []
 +              step = min
 +              while step <= max:
 +                      choices.append(str(step))
 +                      step += stepwidth
 +              
 +              ConfigSelection.__init__(self, choices, default)
 +
 +      def getValue(self):
 +              return int(ConfigSelection.getValue(self))
 +
 +      def setValue(self, val):
 +              ConfigSelection.setValue(self, str(val))
 +
 +      def handleKey(self, key):
 +              if not self.wraparound:
 +                      if key == KEY_RIGHT:
 +                              if len(self.choices) == (self.choices.index(self.value) + 1):
 +                                      return
 +                      if key == KEY_LEFT:
 +                              if self.choices.index(self.value) == 0:
 +                                      return
 +              ConfigSelection.handleKey(self, key)
 +
  class ConfigNumber(ConfigText):
        def __init__(self, default = 0):
                ConfigText.__init__(self, str(default), fixed_size = False)
@@@ -1283,7 -1249,6 +1283,6 @@@ class ConfigLocations(ConfigElement)
                self.default = default
                self.locations = []
                self.mountpoints = []
-               harddiskmanager.on_partition_list_change.append(self.mountpointsChanged)
                self.value = default[:]
  
        def setValue(self, value):
                locations = [[x, None, False, False] for x in tmp]
                self.refreshMountpoints()
                for x in locations:
-                       if os_path.exists(x[0]):
+                       if fileExists(x[0]):
                                x[1] = self.getMountpoint(x[0])
                                x[2] = True
                self.locations = locations
                        return False
                return self.tostring([x[0] for x in locations]) != sv
  
-       def mountpointsChanged(self, action, dev):
-               print "Mounts changed: ", action, dev
-               mp = dev.mountpoint+"/"
-               if action == "add":
-                       self.addedMount(mp)
-               elif action == "remove":
-                       self.removedMount(mp)
-               self.refreshMountpoints()
        def addedMount(self, mp):
                for x in self.locations:
                        if x[1] == mp:
                                x[2] = True
-                       elif x[1] == None and os_path.exists(x[0]):
+                       elif x[1] == None and fileExists(x[0]):
                                x[1] = self.getMountpoint(x[0])
                                x[2] = True
  
                                x[2] = False
  
        def refreshMountpoints(self):
-               self.mountpoints = [p.mountpoint + "/" for p in harddiskmanager.getMountedPartitions() if p.mountpoint != "/"]
+               self.mountpoints = [p.mountpoint for p in harddiskmanager.getMountedPartitions() if p.mountpoint != "/"]
                self.mountpoints.sort(key = lambda x: -len(x))
  
        def checkChangedMountpoints(self):
@@@ -10,6 -10,7 +10,7 @@@ from Components.ServiceEventTracker imp
  from Components.Sources.Boolean import Boolean
  from Components.config import config, ConfigBoolean, ConfigClock
  from Components.SystemInfo import SystemInfo
+ from Components.UsageConfig import preferredInstantRecordPath, defaultMoviePath
  from EpgSelection import EPGSelection
  from Plugins.Plugin import PluginDescriptor
  
@@@ -28,7 -29,7 +29,7 @@@ from Screens.TimeDateInput import TimeD
  from ServiceReference import ServiceReference
  
  from Tools import Notifications
- from Tools.Directories import SCOPE_HDD, resolveFilename, fileExists
+ from Tools.Directories import fileExists
  
  from enigma import eTimer, eServiceCenter, eDVBServicePMTHandler, iServiceInformation, \
        iPlayableService, eServiceReference, eEPGCache
@@@ -691,6 -692,8 +692,6 @@@ class InfoBarSeek
                                iPlayableService.evSOF: self.__evSOF,
                        })
  
 -              self.minSpeedBackward = useSeekBackHack and 16 or 0
 -
                class InfoBarSeekActionMap(HelpableActionMap):
                        def __init__(self, screen, *args, **kwargs):
                                HelpableActionMap.__init__(self, screen, *args, **kwargs)
                self.__seekableStatusChanged()
  
        def makeStateForward(self, n):
 -              minspeed = config.seek.stepwise_minspeed.value
 -              repeat = int(config.seek.stepwise_repeat.value)
 -              if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
 -                      return (0, n * repeat, repeat, ">> %dx" % n)
 -              else:
 +#             minspeed = config.seek.stepwise_minspeed.value
 +#             repeat = int(config.seek.stepwise_repeat.value)
 +#             if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
 +#                     return (0, n * repeat, repeat, ">> %dx" % n)
 +#             else:
                        return (0, n, 0, ">> %dx" % n)
  
        def makeStateBackward(self, n):
 -              minspeed = config.seek.stepwise_minspeed.value
 -              repeat = int(config.seek.stepwise_repeat.value)
 -              if self.minSpeedBackward and n < self.minSpeedBackward:
 -                      r = (self.minSpeedBackward - 1)/ n + 1
 -                      if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
 -                              r = max(r, repeat)
 -                      return (0, -n * r, r, "<< %dx" % n)
 -              elif minspeed != "Never" and n >= int(minspeed) and repeat > 1:
 -                      return (0, -n * repeat, repeat, "<< %dx" % n)
 -              else:
 +#             minspeed = config.seek.stepwise_minspeed.value
 +#             repeat = int(config.seek.stepwise_repeat.value)
 +#             if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
 +#                     return (0, -n * repeat, repeat, "<< %dx" % n)
 +#             else:
                        return (0, -n, 0, "<< %dx" % n)
  
        def makeStateSlowMotion(self, n):
                        if config.seek.on_pause.value == "play":
                                self.unPauseService()
                        elif config.seek.on_pause.value == "step":
 -                              self.doSeekRelative(0)
 +                              self.doSeekRelative(1)
                        elif config.seek.on_pause.value == "last":
                                self.setSeekState(self.lastseekstate)
                                self.lastseekstate = self.SEEK_STATE_PLAY
                        self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
                        self.doSeekRelative(-6)
                elif seekstate == self.SEEK_STATE_PAUSE:
 -                      self.doSeekRelative(-3)
 +                      self.doSeekRelative(-1)
                elif self.isStateForward(seekstate):
                        speed = seekstate[1]
                        if seekstate[2]:
@@@ -1205,7 -1213,10 +1206,7 @@@ class InfoBarTimeshift
                        self.setSeekState(self.SEEK_STATE_PAUSE)
  
                if back:
 -                      self.doSeek(-5) # seek some gops before end
                        self.ts_rewind_timer.start(200, 1)
 -              else:
 -                      self.doSeek(-1) # seek 1 gop before end
  
        def rewindService(self):
                self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
@@@ -1474,7 -1485,7 +1475,7 @@@ class InfoBarInstantRecord
                if isinstance(serviceref, eServiceReference):
                        serviceref = ServiceReference(serviceref)
  
-               recording = RecordTimerEntry(serviceref, begin, end, name, description, eventid, dirname = config.movielist.last_videodir.value)
+               recording = RecordTimerEntry(serviceref, begin, end, name, description, eventid, dirname = preferredInstantRecordPath())
                recording.dontSave = True
                
                if event is None or limitEvent == False:
                        self.session.nav.RecordTimer.timeChanged(entry)
  
        def instantRecord(self):
-               dir = config.movielist.last_videodir.value
-               if not fileExists(dir, 'w'):
-                       dir = resolveFilename(SCOPE_HDD)
+               dir = preferredInstantRecordPath()
+               if not dir or not fileExists(dir, 'w'):
+                       dir = defaultMoviePath()
                try:
                        stat = os_stat(dir)
                except:
@@@ -1659,46 -1670,17 +1660,46 @@@ class InfoBarAudioSelection
                                else:
                                        break
  
 +                      availableKeys = []
 +                      usedKeys = []
 +
                        if SystemInfo["CanDownmixAC3"]:
 -                              tlist = [(_("AC3 downmix") + " - " +(_("Off"), _("On"))[config.av.downmix_ac3.value and 1 or 0], "CALLFUNC", self.changeAC3Downmix),
 -                                      ((_("Left"), _("Stereo"), _("Right"))[self.audioChannel.getCurrentChannel()], "mode"),
 -                                      ("--", "")] + tlist
 -                              keys = [ "red", "green", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
 -                              selection += 3
 -                      else:
 -                              tlist = [((_("Left"), _("Stereo"), _("Right"))[self.audioChannel.getCurrentChannel()], "mode"), ("--", "")] + tlist
 -                              keys = [ "red", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
 +                              flist = [(_("AC3 downmix") + " - " +(_("Off"), _("On"))[config.av.downmix_ac3.value and 1 or 0], "CALLFUNC", self.changeAC3Downmix),
 +                                      ((_("Left"), _("Stereo"), _("Right"))[self.audioChannel.getCurrentChannel()], "mode")]
 +                              usedKeys.extend(["red", "green"])
 +                              availableKeys.extend(["yellow", "blue"])
                                selection += 2
 -                      self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection, keys = keys, skin_name = "AudioTrackSelection")
 +                      else:
 +                              flist = [((_("Left"), _("Stereo"), _("Right"))[self.audioChannel.getCurrentChannel()], "mode")]
 +                              usedKeys.extend(["red"])
 +                              availableKeys.extend(["green", "yellow", "blue"])
 +                              selection += 1
 +
 +                      if hasattr(self, "runPlugin"):
 +                              class PluginCaller:
 +                                      def __init__(self, fnc, *args):
 +                                              self.fnc = fnc
 +                                              self.args = args
 +                                      def __call__(self, *args, **kwargs):
 +                                              self.fnc(*self.args)
 +
 +                              Plugins = [ (p.name, PluginCaller(self.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
 +
 +                              for p in Plugins:
 +                                      selection += 1
 +                                      flist.append((p[0], "CALLFUNC", p[1]))
 +                                      if availableKeys:
 +                                              usedKeys.append(availableKeys[0])
 +                                              del availableKeys[0]
 +                                      else:
 +                                              usedKeys.append("")
 +
 +                      flist.append(("--", ""))
 +                      usedKeys.append("")
 +                      selection += 1
 +
 +                      keys = usedKeys + [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ] + [""] * n
 +                      self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = flist + tlist, selection = selection, keys = keys, skin_name = "AudioTrackSelection")
                else:
                        del self.audioTracks
  
@@@ -8,12 -8,11 +8,12 @@@ from Components.MenuList import MenuLis
  from Components.Button import Button
  from Components.Label import Label
  from Components.Pixmap import Pixmap
 +from Components.SystemInfo import SystemInfo
+ from Components.UsageConfig import defaultMoviePath
  from Screens.MovieSelection import getPreferredTagEditor
  from Screens.LocationBox import MovieLocationBox
  from Screens.ChoiceBox import ChoiceBox
  from RecordTimer import AFTEREVENT
- from Tools.Directories import resolveFilename, SCOPE_HDD
  from enigma import eEPGCache
  from time import localtime, mktime, time, strftime
  from datetime import datetime
@@@ -94,11 -93,7 +94,11 @@@ class TimerEntry(Screen, ConfigListScre
                                day[weekday] = 1
  
                        self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
 -                      self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
 +                      if SystemInfo["DeepstandbySupport"]:
 +                              shutdownString = _("go to deep standby")
 +                      else:
 +                              shutdownString = _("shut down")
 +                      self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", shutdownString), ("auto", _("auto"))], default = afterevent)
                        self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
                        self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
                        self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
                        self.timerentry_starttime = ConfigClock(default = self.timer.begin)
                        self.timerentry_endtime = ConfigClock(default = self.timer.end)
  
-                       default = self.timer.dirname or resolveFilename(SCOPE_HDD)
+                       default = self.timer.dirname or defaultMoviePath()
                        tmp = config.movielist.videodirs.value
                        if default not in tmp:
                                tmp.append(default)
                self.timer.service_ref = self.timerentry_service_ref
                self.timer.tags = self.timerentry_tags
  
-               self.timer.dirname = self.timerentry_dirname.value
-               config.movielist.last_timer_videodir.value = self.timer.dirname
-               config.movielist.last_timer_videodir.save()
+               if self.timer.dirname or self.timerentry_dirname.value != defaultMoviePath():
+                       self.timer.dirname = self.timerentry_dirname.value
+                       config.movielist.last_timer_videodir.value = self.timer.dirname
+                       config.movielist.last_timer_videodir.save()
  
                if self.timerentry_type.value == "once":
                        self.timer.begin, self.timer.end = self.getBeginEnd()