+ self.backoff *= 2
+ if self.backoff > 100:
+ self.backoff = 100
+ self.log(10, "backoff: retry in %d seconds" % self.backoff)
+
+ def activate(self):
+ next_state = self.state + 1
+ self.log(5, "activating state %d" % next_state)
+
+ if next_state == self.StatePrepared:
+ if self.tryPrepare():
+ self.log(6, "prepare ok, waiting for begin")
+ # fine. it worked, resources are allocated.
+ self.next_activation = self.begin
+ self.backoff = 0
+ return True
+
+ self.log(7, "prepare failed")
+ if self.first_try_prepare:
+ self.first_try_prepare = False
+ if not config.recording.asktozap.value:
+ self.log(8, "asking user to zap away")
+ Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=20)
+ else: # zap without asking
+ self.log(9, "zap without asking")
+ Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_INFO, timeout=20)
+ self.failureCB(True)
+
+ self.do_backoff()
+ # retry
+ self.start_prepare = time.time() + self.backoff
+ return False
+ elif next_state == self.StateRunning:
+ # if this timer has been cancelled, just go to "end" state.
+ if self.cancelled:
+ return True
+
+ if self.justplay:
+ if Screens.Standby.inStandby:
+ self.log(11, "wakeup and zap")
+ #set service to zap after standby
+ Screens.Standby.inStandby.prev_running_service = self.service_ref.ref
+ #wakeup standby
+ Screens.Standby.inStandby.Power()
+ else:
+ self.log(11, "zapping")
+ NavigationInstance.instance.playService(self.service_ref.ref)
+ return True
+ else:
+ self.log(11, "start recording")
+ record_res = self.record_service.start()
+
+ if record_res:
+ self.log(13, "start record returned %d" % record_res)
+ self.do_backoff()
+ # retry
+ self.begin = time.time() + self.backoff
+ return False
+
+ return True
+ elif next_state == self.StateEnded:
+ self.log(12, "stop recording")
+ if not self.justplay:
+ NavigationInstance.instance.stopRecordService(self.record_service)
+ self.record_service = None
+ if self.afterEvent == AFTEREVENT.STANDBY:
+ if not Screens.Standby.inStandby: # not already in standby
+ Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
+ if self.afterEvent == AFTEREVENT.DEEPSTANDBY:
+ if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
+ if Screens.Standby.inStandby: # not in standby
+ RecordTimerEntry.TryQuitMainloop() # start shutdown handling without screen
+ else:
+ Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
+ return True
+
+ def sendStandbyNotification(self, answer):
+ if answer:
+ Notifications.AddNotification(Screens.Standby.Standby)
+
+ def sendTryQuitMainloopNotification(self, answer):
+ if answer:
+ Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
+
+ def getNextActivation(self):
+ if self.state == self.StateEnded:
+ return self.end
+
+ next_state = self.state + 1
+
+ return {self.StatePrepared: self.start_prepare,
+ self.StateRunning: self.begin,
+ self.StateEnded: self.end }[next_state]
+
+ def failureCB(self, answer):
+ if answer == True:
+ self.log(13, "ok, zapped away")
+ #NavigationInstance.instance.stopUserServices()
+ NavigationInstance.instance.playService(self.service_ref.ref)
+ else:
+ self.log(14, "user didn't want to zap away, record will probably fail")
+
+ def timeChanged(self):
+ old_prepare = self.start_prepare
+ self.start_prepare = self.begin - self.prepare_time
+ self.backoff = 0
+
+ if int(old_prepare) != int(self.start_prepare):
+ self.log(15, "record time changed, start prepare is now: %s" % time.ctime(self.start_prepare))
+
+def createTimer(xml):
+ begin = int(xml.getAttribute("begin"))
+ end = int(xml.getAttribute("end"))
+ serviceref = ServiceReference(xml.getAttribute("serviceref").encode("utf-8"))
+ description = xml.getAttribute("description").encode("utf-8")
+ repeated = xml.getAttribute("repeated").encode("utf-8")
+ disabled = long(xml.getAttribute("disabled") or "0")
+ justplay = long(xml.getAttribute("justplay") or "0")
+ afterevent = str(xml.getAttribute("afterevent") or "nothing")
+ afterevent = { "nothing": AFTEREVENT.NONE, "standby": AFTEREVENT.STANDBY, "deepstandby": AFTEREVENT.DEEPSTANDBY }[afterevent]
+ if xml.hasAttribute("eit") and xml.getAttribute("eit") != "None":
+ eit = long(xml.getAttribute("eit"))
+ else:
+ eit = None
+
+ name = xml.getAttribute("name").encode("utf-8")
+ #filename = xml.getAttribute("filename").encode("utf-8")
+ entry = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled, justplay, afterevent)
+ entry.repeated = int(repeated)
+
+ for l in elementsWithTag(xml.childNodes, "log"):
+ time = int(l.getAttribute("time"))
+ code = int(l.getAttribute("code"))
+ msg = mergeText(l.childNodes).strip().encode("utf-8")
+ entry.log_entries.append((time, code, msg))
+
+ return entry
+
+class RecordTimer(timer.Timer):