1 from Components.ActionMap import ActionMap
2 from Components.Button import Button
3 from Components.config import config
4 from Components.MenuList import MenuList
5 from Components.TimerList import TimerList
6 from Components.TimerSanityCheck import TimerSanityCheck
7 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
8 from Screen import Screen
9 from Screens.ChoiceBox import ChoiceBox
10 from Screens.MessageBox import MessageBox
11 from ServiceReference import ServiceReference
12 from TimerEntry import TimerEntry, TimerLog
13 from Tools.BoundFunction import boundFunction
16 class TimerEditList(Screen):
23 def __init__(self, session):
24 Screen.__init__(self, session)
30 print "EMPTY:",self.EMPTY
31 print "ENABLE:",self.ENABLE
32 print "DISABLE:",self.DISABLE
33 print "CLEANUP:",self.CLEANUP
34 print "DELETE:",self.DELETE
36 self["timerlist"] = TimerList(list)
38 self.key_red_choice = self.EMPTY
39 self.key_yellow_choice = self.EMPTY
40 self.key_blue_choice = self.EMPTY
42 self["key_red"] = Button(" ")
43 self["key_green"] = Button(_("Add"))
44 self["key_yellow"] = Button(" ")
45 self["key_blue"] = Button(" ")
47 print "key_red_choice:",self.key_red_choice
49 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
53 "green": self.addCurrentTimer,
60 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
61 self.onShown.append(self.updateState)
64 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
68 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
72 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
76 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
79 def toggleDisabledState(self):
80 cur=self["timerlist"].getCurrent()
84 print "try to ENABLE timer"
86 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, cur)
87 if not timersanitycheck.check():
89 print "Sanity check failed"
90 self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
92 print "Sanity check passed"
93 if timersanitycheck.doubleCheck():
99 list.append((_("Stop current event but not coming events"), "stoponlycurrent"))
100 list.append((_("Stop current event and disable coming events"), "stopall"))
101 list.append((_("Don't stop current event but disable coming events"), "stoponlycoming"))
102 self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
105 self.session.nav.RecordTimer.timeChanged(t)
109 def runningEventCallback(self, t, result):
110 if result is not None:
111 if result[1] == "stoponlycurrent" or result[1] == "stopall":
113 t.processRepeated(findRunningEvent = False)
114 self.session.nav.RecordTimer.doActivate(t)
115 if result[1] == "stoponlycoming" or result[1] == "stopall":
117 self.session.nav.RecordTimer.timeChanged(t)
121 def removeAction(self, descr):
122 actions = self["actions"].actions
126 def updateState(self):
127 cur = self["timerlist"].getCurrent()
129 if self.key_red_choice != self.DELETE:
130 self["actions"].actions.update({"red":self.removeTimerQuestion})
131 self["key_red"].setText(_("Delete"))
132 self.key_red_choice = self.DELETE
134 if cur.disabled and (self.key_yellow_choice != self.ENABLE):
135 self["actions"].actions.update({"yellow":self.toggleDisabledState})
136 self["key_yellow"].setText(_("Enable"))
137 self.key_yellow_choice = self.ENABLE
138 elif cur.isRunning() and not cur.repeated and (self.key_yellow_choice != self.EMPTY):
139 self.removeAction("yellow")
140 self["key_yellow"].setText(" ")
141 self.key_yellow_choice = self.EMPTY
142 elif ((not cur.isRunning())or cur.repeated ) and (not cur.disabled) and (self.key_yellow_choice != self.DISABLE):
143 self["actions"].actions.update({"yellow":self.toggleDisabledState})
144 self["key_yellow"].setText(_("Disable"))
145 self.key_yellow_choice = self.DISABLE
147 if self.key_red_choice != self.EMPTY:
148 self.removeAction("red")
149 self["key_red"].setText(" ")
150 self.key_red_choice = self.EMPTY
151 if self.key_yellow_choice != self.EMPTY:
152 self.removeAction("yellow")
153 self["key_yellow"].setText(" ")
154 self.key_yellow_choice = self.EMPTY
158 if (not x[0].disabled) and (x[1] == True):
163 if showCleanup and (self.key_blue_choice != self.CLEANUP):
164 self["actions"].actions.update({"blue":self.cleanupQuestion})
165 self["key_blue"].setText(_("Cleanup"))
166 self.key_blue_choice = self.CLEANUP
167 elif (not showCleanup) and (self.key_blue_choice != self.EMPTY):
168 self.removeAction("blue")
169 self["key_blue"].setText(" ")
170 self.key_blue_choice = self.EMPTY
172 def fillTimerList(self):
175 for timer in self.session.nav.RecordTimer.timer_list:
176 self.list.append((timer, False))
178 for timer in self.session.nav.RecordTimer.processed_timers:
179 self.list.append((timer, True))
180 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
183 cur=self["timerlist"].getCurrent()
185 self.session.openWithCallback(self.finishedEdit, TimerLog, cur)
188 cur=self["timerlist"].getCurrent()
190 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur)
192 def cleanupQuestion(self):
193 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
195 def cleanupTimer(self, delete):
197 self.session.nav.RecordTimer.cleanup()
201 def removeTimerQuestion(self):
202 if not self["timerlist"].getCurrent():
204 self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
206 def removeTimer(self, result):
209 list = self["timerlist"]
210 cur = list.getCurrent()
213 timer.afterEvent = AFTEREVENT.NONE
214 self.session.nav.RecordTimer.removeEntry(timer)
215 if not timer.dontSave:
216 for timer in self.session.nav.RecordTimer.timer_list:
217 if timer.dontSave and timer.autoincrease:
218 timer.end = timer.begin + (3600 * 24 * 356 * 1)
219 self.session.nav.RecordTimer.timeChanged(timer)
220 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list,timer)
221 if not timersanitycheck.check():
222 tsc_list = timersanitycheck.getSimulTimerList()
223 if len(tsc_list) > 1:
224 timer.end = tsc_list[1].begin - 30
225 self.session.nav.RecordTimer.timeChanged(timer)
232 oldsize = len(self.list)
234 lst = self["timerlist"]
235 newsize = len(self.list)
236 if oldsize and oldsize != newsize:
237 idx = lst.getCurrentIndex()
238 lst.entryRemoved(idx)
242 def addCurrentTimer(self):
244 service = self.session.nav.getCurrentService()
245 if service is not None:
246 info = service.info()
248 event = info.getEvent(0)
250 # FIXME only works if already playing a service
251 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
254 data = (int(time()), int(time() + 60), "", "", None)
256 data = parseEvent(event, description = False)
258 self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, dirname = config.movielist.last_timer_videodir.value, *data))
260 def addTimer(self, timer):
261 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
263 def finishedEdit(self, answer):
264 print "finished edit"
269 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, entry)
270 if not timersanitycheck.check():
271 simulTimerList = timersanitycheck.getSimulTimerList()
272 if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
273 simulTimerList[1].end = entry.begin - 30
274 self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
275 self.session.nav.RecordTimer.timeChanged(entry)
277 print "Sanity check failed"
278 self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
280 print "Sanity check passed"
281 if not timersanitycheck.doubleCheck():
282 self.session.nav.RecordTimer.timeChanged(entry)
286 print "Timeredit aborted"
288 def finishedAdd(self, answer):
292 simulTimerList = self.session.nav.RecordTimer.record(entry)
293 if simulTimerList is not None:
294 if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
295 simulTimerList[1].end = entry.begin - 30
296 self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
297 self.session.nav.RecordTimer.record(entry)
299 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
303 print "Timeredit aborted"
305 def finishSanityCorrection(self, answer):
306 self.finishedAdd(answer)
309 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
312 def onStateChange(self, entry):
316 class TimerSanityConflict(Screen):
321 def __init__(self, session, timer):
322 Screen.__init__(self, session)
324 print "TimerSanityConflict"
326 self["timer1"] = TimerList(self.getTimerList(timer[0]))
332 self.list.append((_("Conflicting timer") + " " + str(count), x))
333 self.list2.append((timer[count], False))
336 self["list"] = MenuList(self.list)
337 self["timer2"] = TimerList(self.list2)
339 self["key_red"] = Button("Edit")
340 self["key_green"] = Button(" ")
341 self["key_yellow"] = Button("Edit")
342 self["key_blue"] = Button(" ")
344 self.key_green_choice = self.EMPTY
345 self.key_blue_choice = self.EMPTY
347 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
350 "cancel": self.leave_cancel,
351 "red": self.editTimer1,
355 self.onShown.append(self.updateState)
357 def getTimerList(self, timer):
358 return [(timer, False)]
360 def editTimer1(self):
361 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent())
363 def toggleTimer1(self):
364 if self.timer[0].disabled:
365 self.timer[0].disabled = False
367 if not self.timer[0].isRunning():
368 self.timer[0].disabled = True
369 self.finishedEdit((True, self.timer[0]))
371 def editTimer2(self):
372 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer2"].getCurrent())
374 def toggleTimer2(self):
375 x = self["list"].getSelectedIndex() + 1 # the first is the new timer so we do +1 here
376 if self.timer[x].disabled:
377 self.timer[x].disabled = False
378 elif not self.timer[x].isRunning():
379 self.timer[x].disabled = True
380 self.finishedEdit((True, self.timer[0]))
382 def finishedEdit(self, answer):
386 self.close((True, self.timer[0]))
388 def leave_cancel(self):
389 self.close((False, self.timer[0]))
392 self["list"].instance.moveSelection(self["list"].instance.moveUp)
393 self["timer2"].moveToIndex(self["list"].getSelectedIndex())
396 self["list"].instance.moveSelection(self["list"].instance.moveDown)
397 self["timer2"].moveToIndex(self["list"].getSelectedIndex())
399 def removeAction(self, descr):
400 actions = self["actions"].actions
404 def updateState(self):
405 if self.timer[0] is not None:
406 if self.timer[0].disabled and self.key_green_choice != self.ENABLE:
407 self["actions"].actions.update({"green":self.toggleTimer1})
408 self["key_green"].setText(_("Enable"))
409 self.key_green_choice = self.ENABLE
410 elif self.timer[0].isRunning() and not timer[0].repeated and self.key_green_choice != self.EMPTY:
411 self.removeAction("green")
412 self["key_green"].setText(" ")
413 self.key_green_choice = self.EMPTY
414 elif (not self.timer[0].isRunning() or self.timer[0].repeated ) and self.key_green_choice != self.DISABLE:
415 self["actions"].actions.update({"green":self.toggleTimer1})
416 self["key_green"].setText(_("Disable"))
417 self.key_green_choice = self.DISABLE
418 if len(self.timer) > 1:
419 x = self["list"].getSelectedIndex()
420 if self.timer[x] is not None:
421 if self.timer[x].disabled and self.key_blue_choice != self.ENABLE:
422 self["actions"].actions.update({"blue":self.toggleTimer2})
423 self["key_blue"].setText(_("Enable"))
424 self.key_blue_choice = self.ENABLE
425 elif self.timer[x].isRunning() and not timer[x].repeated and self.key_blue_choice != self.EMPTY:
426 self.removeAction("blue")
427 self["key_blue"].setText(" ")
428 self.key_blue_choice = self.EMPTY
429 elif (not self.timer[x].isRunning() or self.timer[x].repeated ) and self.key_blue_choice != self.DISABLE:
430 self["actions"].actions.update({"blue":self.toggleTimer2})
431 self["key_blue"].setText(_("Disable"))
432 self.key_blue_choice = self.DISABLE
434 #FIXME.... this doesnt hide the buttons self.... just the text
435 self.removeAction("yellow")
436 self["key_yellow"].setText(" ")
437 self.key_yellow_choice = self.EMPTY
438 self.removeAction("blue")
439 self["key_blue"].setText(" ")
440 self.key_blue_choice = self.EMPTY