add support for custom destinations directories to gui,
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Wed, 20 Feb 2008 16:54:58 +0000 (16:54 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Wed, 20 Feb 2008 16:54:58 +0000 (16:54 +0000)
fix crash when shutting down while in editor

autotimer/src/AutoTimer.py
autotimer/src/AutoTimerComponent.py
autotimer/src/AutoTimerEditor.py
autotimer/src/plugin.py

index acf3449..28abdac 100644 (file)
@@ -151,7 +151,7 @@ class AutoTimer:
                                if maxlen:
                                        maxlen = int(maxlen)*60
 
-                               # Read out recording path (needs my Location-select patch)
+                               # Read out recording path
                                destination = timer.getAttribute("destination").encode("UTF-8") or None
 
                                # Read out offset
@@ -244,6 +244,15 @@ class AutoTimer:
                                        except KeyError, ke:
                                                pass
 
+                               # Read out recording tags (needs my enhanced tag support patch)
+                               tags = []
+                               for tag in timer.getElementsByTagName("tag"):
+                                       value = getValue(tag, None)
+                                       if not value:
+                                               continue
+
+                                       tags.append(value.encode("UTF-8"))
+
                                # Finally append tuple
                                self.timers.append(AutoTimerComponent(
                                                self.uniqueTimerId,
@@ -265,7 +274,8 @@ class AutoTimer:
                                                lastBegin = lastBegin,
                                                justplay = justplay,
                                                avoidDuplicateDescription = avoidDuplicateDescription,
-                                               bouquets = bouquets
+                                               bouquets = bouquets,
+                                               tags = tags
                                ))
 
        def getTimerList(self):
@@ -389,6 +399,10 @@ class AutoTimer:
                        for day in timer.getIncludedDays():
                                list.extend(['  <include where="dayofweek">', day, '</include>\n'])
 
+                       # Tags
+                       for tag in timer.tags:
+                               list.extend(['  <tag>', str(tag), '</tag>\n'])
+
                        # End of Timer
                        list.append(' </timer>\n\n')
 
@@ -548,13 +562,9 @@ class AutoTimer:
                                        if afterEvent is not None:
                                                newEntry.afterEvent = afterEvent
 
-                               # Set custom destination directory (needs my Location-select patch)
-                               if timer.hasDestination():
-                                       # TODO: add warning when patch not installed?
-                                       newEntry.dirname = timer.destination
-                               # Make this timer a zap-timer if wanted
-                               newEntry.justplay = timer.justplay
+                               newEntry.dirname = timer.destination
+                               newEntry.justplay = timer.justplay
+                               newEntry.tags = timer.tags # This needs my enhanced tag support patch to work
  
                                # Do a sanity check, although it does not do much right now
                                timersanitycheck = TimerSanityCheck(NavigationInstance.instance.RecordTimer.timer_list, newEntry)
index 6cd6f80..53c04c9 100644 (file)
@@ -24,7 +24,8 @@ class AutoTimerComponent(object):
        def setValues(self, name, match, enabled, timespan = None, services = None, offset = None, \
                        afterevent = [], exclude = None, maxduration = None, destination = None, \
                        include = None, matchCount = 0, matchLeft = 0, matchLimit = '', matchFormatString = '', \
-                       lastBegin = 0, justplay = False, avoidDuplicateDescription = False, bouquets = None):
+                       lastBegin = 0, justplay = False, avoidDuplicateDescription = False, bouquets = None, \
+                       tags = None):
                self.name = name
                self.match = match
                self.timespan = timespan
@@ -44,6 +45,7 @@ class AutoTimerComponent(object):
                self.justplay = justplay
                self.avoidDuplicateDescription = avoidDuplicateDescription
                self.bouquets = bouquets
+               self.tags = tags or []
 
        def calculateDayspan(self, begin, end):
                if end[0] < begin[0] or (end[0] == begin[0] and end[1] <= begin[1]):
@@ -383,6 +385,9 @@ class AutoTimerComponent(object):
        def getAvoidDuplicateDescription(self):
                return self.avoidDuplicateDescription
 
+       def hasTags(self):
+               return len(self.tags) > 0
+
        def __repr__(self):
                return ''.join([
                        '<AutomaticTimer ',
index 4ec7ac8..807f319 100644 (file)
@@ -134,9 +134,10 @@ class AutoTimerEditor(Screen, ConfigListScreen):
                        {
                                "cancel": self.cancel,
                                "save": self.maybeSave,
+                               "ok": self.ok,
                                "yellow": self.editFilter,
                                "blue": self.editServices
-                       }
+                       }, -2
                )
 
                # Trigger change
@@ -273,6 +274,9 @@ class AutoTimerEditor(Screen, ConfigListScreen):
                # Avoid Duplicate Description
                self.avoidDuplicateDescription = ConfigEnableDisable(default = timer.getAvoidDuplicateDescription())
 
+               # Custom Location
+               self.destination = ConfigSelection(choices = [timer.destination or "/hdd/movie"])
+
        def refresh(self):
                # First four entries are always shown
                self.list = [
@@ -329,6 +333,9 @@ class AutoTimerEditor(Screen, ConfigListScreen):
 
                self.list.append(getConfigListEntry(_("Require Description to be unique"), self.avoidDuplicateDescription))
 
+               # We always add this option though its actually expert only
+               self.list.append(getConfigListEntry(_("Custom Location"), self.destination))
+
        def reloadList(self, value):
                self.refresh()
                self["config"].setList(self.list)
@@ -365,6 +372,26 @@ class AutoTimerEditor(Screen, ConfigListScreen):
                        self.bouquets = ret[1][1]
                        self.renameServiceButton()
 
+       def ok(self):
+               cur = self["config"].getCurrent()
+               cur = cur and cur[1]
+               if cur == self.destination:
+                       from Screens.LocationBox import LocationBox
+
+                       self.session.openWithCallback(
+                               self.pathSelected,
+                               LocationBox,
+                               text = _("Choose target folder"),
+                               filename = "",
+                               currDir = self.destination.value
+                       )
+
+       def pathSelected(self, res):
+               if res is not None:
+                       self.destination.choices.append(res)
+                       self.destination.description[res] = res
+                       self.destination.value = res
+
        def cancel(self):
                if self["config"].isChanged():
                        self.session.openWithCallback(
@@ -477,6 +504,7 @@ class AutoTimerEditor(Screen, ConfigListScreen):
                        self.timer.matchFormatString = ''
 
                self.timer.avoidDuplicateDescription = self.avoidDuplicateDescription.value
+               self.timer.destination = self.destination.value
 
                # Close
                self.close(self.timer)
index 59cff86..52dc16c 100644 (file)
@@ -40,7 +40,11 @@ def autostart(reason, **kwargs):
        elif reason == 1:
                # Stop Poller
                if autopoller is not None:
-                       autopoller.stop()
+                       # We might shutdown when configuring, timer won't be runnign then
+                       try:
+                               autopoller.stop()
+                       except ValueError, ve:
+                               pass
 
                        autopoller = None