new option for "Location"
authorDima73 <Dima-73@inbox.lv>
Tue, 23 Jun 2015 15:42:44 +0000 (18:42 +0300)
committerlittlesat <littlesat99@yahoo.com>
Wed, 24 Jun 2015 12:23:02 +0000 (14:23 +0200)
create a folder named timer for repeated timers

Signed-off-by: littlesat <littlesat99@yahoo.com>

lib/python/Screens/LocationBox.py
lib/python/Screens/TimerEntry.py

index 0a464aa..61ae482 100644 (file)
@@ -239,7 +239,7 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                                self.createDirCallback,
                                InputBox,
                                title = _("Please enter name of the new directory"),
-                               text = ""
+                               text = self.filename
                        )
 
        def createDirCallback(self, res):
@@ -336,12 +336,29 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
                        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.getPreferredFolder() not 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()
+
+                               if self.filename and not pathExists(ret):
+                                       menu = [(_("Create new folder and exit"), "folder"), (_("Save and exit"), "exit")]
+                                       text = _("Select action")
+                                       def dirAction(choice):
+                                               if choice:
+                                                       if choice[1] == "folder":
+                                                               if not createDir(ret):
+                                                                       self.session.open(MessageBox, _("Creating directory %s failed.") % (ret), type = MessageBox.TYPE_ERROR)
+                                                                       return
+                                                       self.close(ret)
+                                               else:
+                                                       self.cancel()
+                                       self.session.openWithCallback(dirAction, ChoiceBox, title=text, list=menu)
+                                       return
+
                        self.close(ret)
 
        def select(self):
@@ -509,8 +526,8 @@ class LocationBox(Screen, NumericalTextInput, HelpableScreen):
        def __repr__(self):
                return str(type(self)) + "(" + self.text + ")"
 
-def MovieLocationBox(session, text, dir, minFree = None):
-       return LocationBox(session, text = text, currDir = dir, bookmarks = config.movielist.videodirs, autoAdd = True, editDir = True, inhibitDirs = defaultInhibitDirs, minFree = minFree)
+def MovieLocationBox(session, text, dir, filename = "", minFree = None):
+       return LocationBox(session, text = text,  filename = filename, currDir = dir, bookmarks = config.movielist.videodirs, autoAdd = True, editDir = True, inhibitDirs = defaultInhibitDirs, minFree = minFree)
 
 class TimeshiftLocationBox(LocationBox):
        def __init__(self, session):
index 053d1d3..369ac06 100644 (file)
@@ -282,6 +282,16 @@ class TimerEntry(Screen, ConfigListScreen):
                        ConfigListScreen.handleKeyFileCallback(self, answer)
                        self.newConfig()
 
+       def openMovieLocationBox(self, answer=""):
+               self.session.openWithCallback(
+                       self.pathSelected,
+                       MovieLocationBox,
+                       _("Select target folder"),
+                       self.timerentry_dirname.value,
+                       filename = answer,
+                       minFree = 100 # We require at least 100MB free space
+                       )
+
        def keySelect(self):
                cur = self["config"].getCurrent()
                if cur == self.channelEntry:
@@ -292,13 +302,21 @@ class TimerEntry(Screen, ConfigListScreen):
                                currentBouquet=True
                        )
                elif config.usage.setup_level.index >= 2 and cur == self.dirname:
-                       self.session.openWithCallback(
-                               self.pathSelected,
-                               MovieLocationBox,
-                               _("Select target folder"),
-                               self.timerentry_dirname.value,
-                               minFree = 100 # We require at least 100MB free space
-                       )
+                       menu = [(_("Open select location"), "empty")]
+                       if self.timerentry_type.value == "repeated" and self.timerentry_name.value:
+                               menu.append((_("Open select location as timer name"), "timername"))
+                       if len(menu) == 1:
+                               self.openMovieLocationBox()
+                       elif len(menu) == 2:
+                               text = _("Select action")
+                               def selectAction(choice):
+                                       if choice:
+                                               if choice[1] == "timername":
+                                                       self.openMovieLocationBox(self.timerentry_name.value)
+                                               elif choice[1] == "empty":
+                                                       self.openMovieLocationBox()
+                               self.session.openWithCallback(selectAction, ChoiceBox, title=text, list=menu)
+
                elif getPreferredTagEditor() and cur == self.tagsSet:
                        self.session.openWithCallback(
                                self.tagEditFinished,