add a "nothing connected" option to the sat setup for nim b
[enigma2.git] / RecordTimer.py
index 1a64c5e..85e9d17 100644 (file)
@@ -1,11 +1,12 @@
 import time
 import codecs
 #from time import datetime
-from Tools import Directories
+from Tools import Directories, Notifications
 
 import timer
 import xml.dom.minidom
 
+from Screens.MessageBox import MessageBox
 import NavigationInstance
 
 from Tools.XMLTools import elementsWithTag
@@ -29,6 +30,8 @@ class RecordTimerEntry(timer.TimerEntry):
                self.description = description
                self.timer = None
                self.record_service = None
+               self.wantStart = False
+               self.prepareOK = False
                
        def calculateFilename(self):
                service_name = self.service_ref.getServiceName()
@@ -55,31 +58,59 @@ class RecordTimerEntry(timer.TimerEntry):
 #              
 #              print "------------ record filename: %s" % (self.Filename)
        
-       
+       def tryPrepare(self):
+               self.calculateFilename()
+               self.record_service = NavigationInstance.instance.recordService(self.service_ref)
+               if self.record_service == None:
+                       return False
+               else:   
+                       if self.record_service.prepare(self.Filename + ".ts"):
+                               self.record_service = None
+                               return False
+
+                       f = open(self.Filename + ".ts.meta", "w")
+                       f.write(str(self.service_ref) + "\n")
+                       f.write(self.epg_data + "\n")
+                       del f
+                       return True
+
        def activate(self, event):
                if event == self.EventPrepare:
-                       self.calculateFilename()
-                       self.record_service = NavigationInstance.instance.recordService(self.service_ref)
-                       if self.record_service == None:
-                               print "timer record failed."
-                       else:   
-                               self.record_service.prepare(self.Filename + ".ts")
-                               f = open(self.Filename + ".ts.meta", "w")
-                               f.write(str(self.service_ref) + "\n")
-                               f.write(self.epg_data + "\n")
-                               del f
-                               
-               elif self.record_service == None:
-                       if event != self.EventAbort:
-                               print "timer record start failed, can't finish recording."
+                       self.prepareOK = False
+                       if self.tryPrepare():
+                               self.prepareOK = True
+                       else:
+                               # error.
+                               Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"))
                elif event == self.EventStart:
-                       self.record_service.start()
-                       print "timer started!"
+                       if self.prepareOK:
+                               self.record_service.start()
+                               print "timer started!"
+                       else:
+                               print "prepare failed, thus start failed, too."
+                               self.wantStart = True
                elif event == self.EventEnd or event == self.EventAbort:
-                       self.record_service.stop()
-                       self.record_service = None
-                       print "Timer successfully ended"
+                       self.wantStart = False
+                       if self.prepareOK:
+                               self.record_service.stop()
+                               self.record_service = None
+                               print "Timer successfully ended"
+                       else:
+                               print "prepare failed, thus nothing was recorded."
 
+       def abort():
+               # fixme
+               pass
+
+       def failureCB(self, answer):
+               if answer == True:
+                       NavigationInstance.instance.stopUserServices()
+                       self.activate(self.EventPrepare)
+                       if self.wantStart:
+                               print "post-activating record"
+                               self.activate(self.EventStart)
+               else:
+                       print "user killed record"
 
 def createTimer(xml):
        begin = int(xml.getAttribute("begin"))
@@ -97,7 +128,7 @@ class RecordTimer(timer.Timer):
        def __init__(self):
                timer.Timer.__init__(self)
                
-               self.Filename = Directories.resolveFilename(Directories.SCOPE_USERETC, "timers.xml")
+               self.Filename = Directories.resolveFilename(Directories.SCOPE_CONFIG, "timers.xml")
                
                try:
                        self.loadTimer()
@@ -138,7 +169,7 @@ class RecordTimer(timer.Timer):
                        t.setAttribute("serviceref", str(timer.service_ref))
                        t.setAttribute("repeated", str(timer.repeated))                 
                        #t.setAttribute("epgdata", timer.)
-                       t.setAttribute("description", timer.description)
+                       t.setAttribute("description", "no description") # timer.description)
                        root_element.appendChild(t)
                        t = doc.createTextNode("\n")
                        root_element.appendChild(t)
@@ -155,6 +186,10 @@ class RecordTimer(timer.Timer):
 
        def removeEntry(self, entry):
                print "[Timer] Remove " + str(entry)
+               
+               entry.repeated = False
+
+               entry.repeated = False
 
                if entry.state == timer.TimerEntry.StateRunning:
                        print "remove running timer."