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
self.description = description
self.timer = None
self.record_service = None
+ self.wantStart = False
def calculateFilename(self):
service_name = self.service_ref.getServiceName()
#
# 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"))
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()
except:
print "unable to load timers from file!"
+
+ def isRecording(self):
+ isRunning = False
+ for timer in self.timer_list:
+ if timer.isRunning():
+ isRunning = True
+ return isRunning
def loadTimer(self):
# TODO: PATH!
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)
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."
elif entry.state != timer.TimerEntry.StateEnded:
entry.activate(timer.TimerEntry.EventAbort)
self.timer_list.remove(entry)
+
self.calcNextActivation()
print "timer did not yet start - removing"
+
+ # the timer was aborted, and removed.
+ return
else:
print "timer did already end - doing nothing."