Merge commit 'origin/bug_351_softwaremanager_save_config_before_backup' into experimental
[enigma2.git] / lib / python / Screens / LocationBox.py
index 132f14014f2cb901e2f4e61bcd64fd27c9b5bb0d..29d94f553fef38bd347ad1db29b57edc0ff14f36 100644 (file)
@@ -12,8 +12,7 @@ from Screens.ChoiceBox import ChoiceBox
 # Generic
 from Tools.BoundFunction import boundFunction
 from Tools.Directories import *
-from Components.config import config, configfile, ConfigSubList, ConfigSubsection, \
-               ConfigText, ConfigNumber, ConfigBoolean
+from Components.config import config
 import os
 
 # Quickselect
@@ -126,7 +125,7 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                                "up": self.up,
                                "down": self.down,
                                "ok": (self.ok, _("select")),
-                               "back": (self.cancel, _("cancel")),
+                               "back": (self.cancel, _("Cancel")),
                        }, -2)
 
                self["ColorActions"] = LocationBoxActionMap(self, "ColorActions",
@@ -164,11 +163,11 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                })
 
                # Run some functions when shown
-               self.onShown.extend([
+               self.onShown.extend((
                        boundFunction(self.setTitle, windowTitle),
                        self.updateTarget,
                        self.showHideRename,
-               ])
+               ))
 
                self.onLayoutFinish.append(self.switchToFileListOnStart)
  
@@ -242,7 +241,7 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                        )
 
        def createDirCallback(self, res):
-               if res is not None and len(res):
+               if res:
                        path = os.path.join(self["filelist"].current_directory, res)
                        if not pathExists(path):
                                if not createDir(path):
@@ -290,6 +289,11 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                        else:
                                self["filelist"].refresh()
                                self.removeBookmark(name, True)
+                               val = self.realBookmarks and self.realBookmarks.value
+                               if val and name in val:
+                                       val.remove(name)
+                                       self.realBookmarks.value = val
+                                       self.realBookmarks.save()
 
        def up(self):
                self[self.currList].up()
@@ -325,12 +329,17 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                else:
                        return self["booklist"].getCurrent()
 
-       def selectConfirmed(self, res):
-               if res:
-                       ret = ''.join([self.getPreferredFolder(), self.filename])
-                       if self.realBookmarks and self.autoAdd and not ret in self.bookmarks:
-                               self.bookmarks.append(self.getPreferredFolder())
-                               self.bookmarks.sort()
+       def selectConfirmed(self, ret):
+               if ret:
+                       ret = ''.join((self.getPreferredFolder(), self.filename))
+                       if self.realBookmarks:
+                               if self.autoAdd and not ret in self.bookmarks:
+                                       self.bookmarks.append(self.getPreferredFolder())
+                                       self.bookmarks.sort()
+
+                               if self.bookmarks != self.realBookmarks.value:
+                                       self.realBookmarks.value = self.bookmarks
+                                       self.realBookmarks.save()
                        self.close(ret)
 
        def select(self):
@@ -355,16 +364,10 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                                        _("There might not be enough Space on the selected Partition.\nDo you really want to continue?"),
                                        type = MessageBox.TYPE_YESNO
                                )
-                               # No minimum free Space means we can safely close
+                       # No minimum free Space means we can safely close
                        else:
                                self.selectConfirmed(True)
 
-       def close(self, ret):
-               if ret and self.realBookmarks and self.bookmarks != self.realBookmarks.value:
-                       self.realBookmarks.value = self.bookmarks
-                       self.realBookmarks.save()
-               Screen.close(self, ret)
-
        def changeName(self):
                if self.filename != "":
                        # TODO: Add Information that changing extension is bad? disallow?
@@ -392,23 +395,28 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                # Write Combination of Folder & Filename when Folder is valid
                currFolder = self.getPreferredFolder()
                if currFolder is not None:
-                       self["target"].setText(''.join([currFolder, self.filename]))
+                       self["target"].setText(''.join((currFolder, self.filename)))
                # Display a Warning otherwise
                else:
                        self["target"].setText(_("Invalid Location"))
 
        def showMenu(self):
                if not self.userMode and self.realBookmarks:
-                       menu = []
                        if self.currList == "filelist":
-                               menu.append((_("switch to bookmarks"), self.switchToBookList))
-                               menu.append((_("add bookmark"), self.AddRemoveBookmark))
+                               menu = [
+                                       (_("switch to bookmarks"), self.switchToBookList),
+                                       (_("add bookmark"), self.addRemoveBookmark)
+                               ]
                                if self.editDir:
-                                       menu.append((_("create directory"), self.createDir))
-                                       menu.append((_("remove directory"), self.removeDir))
+                                       menu.extend((
+                                               (_("create directory"), self.createDir),
+                                               (_("remove directory"), self.removeDir)
+                                       ))
                        else:
-                               menu.append((_("switch to filelist"), self.switchToFileList))
-                               menu.append((_("remove bookmark"), self.AddRemoveBookmark))
+                               menu = (
+                                       (_("switch to filelist"), self.switchToFileList),
+                                       (_("remove bookmark"), self.addRemoveBookmark)
+                               )
 
                        self.session.openWithCallback(
                                self.menuCallback,
@@ -451,7 +459,7 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
 
        def selectByStart(self):
                # Don't do anything on initial call
-               if not len(self.quickselect):
+               if not self.quickselect:
                        return
 
                # Don't select if no dir
@@ -501,7 +509,33 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
 
 class MovieLocationBox(LocationBox):
        def __init__(self, session, text, dir, minFree = None):
-               inhibitMounts = []
-               if config.usage.setup_level.index < 2: # -expert
-                       inhibitMounts.append("/")
-               LocationBox.__init__(self, session, text = text, currDir = dir, bookmarks = config.movielist.videodirs, autoAdd = True, editDir = True, inhibitMounts = inhibitMounts, minFree = minFree)
+               inhibitDirs = ["/bin", "/boot", "/dev", "/etc", "/lib", "/proc", "/sbin", "/sys", "/usr", "/var"]
+               LocationBox.__init__(self, session, text = text, currDir = dir, bookmarks = config.movielist.videodirs, autoAdd = True, editDir = True, inhibitDirs = inhibitDirs, minFree = minFree)
+               self.skinName = "LocationBox"
+
+class TimeshiftLocationBox(LocationBox):
+       def __init__(self, session):
+               inhibitDirs = ["/bin", "/boot", "/dev", "/etc", "/lib", "/proc", "/sbin", "/sys", "/usr", "/var"]
+               LocationBox.__init__(
+                               self,
+                               session,
+                               text = _("Where to save temporary timeshift recordings?"),
+                               currDir = config.usage.timeshift_path.value,
+                               bookmarks = config.usage.allowed_timeshift_paths,
+                               autoAdd = True,
+                               editDir = True,
+                               inhibitDirs = inhibitDirs,
+                               minFree = 1024 # the same requirement is hardcoded in servicedvb.cpp
+               )
+               self.skinName = "LocationBox"
+
+       def cancel(self):
+               config.usage.timeshift_path.cancel()
+               LocationBox.cancel(self)
+
+       def selectConfirmed(self, ret):
+               if ret:
+                       config.usage.timeshift_path.value = self.getPreferredFolder()
+                       config.usage.timeshift_path.save()
+                       LocationBox.selectConfirmed(self, ret)
+