add missing import
[enigma2.git] / lib / python / Screens / TimerEdit.py
index 233bfe2d3000d5e2d73b4e785f24713d004cf26c..4f5039ec9bacaa74d3a8cf82017739ed6f81a208 100644 (file)
@@ -9,61 +9,16 @@ from TimerEntry import TimerEntry
 from RecordTimer import RecordTimerEntry
 from time import *
 from ServiceReference import ServiceReference
+from Components.config import *
 
-class TimerEdit(Screen):
-       def __init__(self, session, entry):
-               Screen.__init__(self, session)
-
-               self["actions"] = ActionMap(["OkCancelActions"], 
-                       {
-                               "ok": self.apply,
-                               "cancel": self.close
-                       })
-               
-               self["shortcuts"] = ActionMap(["ShortcutActions"],
-                       {
-                               "red": self.beginFocus,
-                               "yellow": self.endFocus,
-                               "green": self.descFocus
-                       })
-               
-               self.entry = entry
-               # begin, end, description, service
-               self["begin"] = TimeInput()
-               self["end"] = TimeInput()
-               
-               self["lbegin"] = Label("Begin")
-               self["lend"] = Label("End")
-               
-               self["description"] = TextInput()
-               self["apply"] = Button("Apply")
-               self["service"] = Button()
-               
-               self["description"].setText(entry.description);
-       
-       def beginFocus(self):
-               self.setFocus(self["begin"])
-       
-       def endFocus(self):
-               self.setFocus(self["end"])
-       
-       def descFocus(self):
-               self.setFocus(self["description"])
-       
-       def apply(self):
-               print "applied!"
-       
 class TimerEditList(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
                
                list = [ ]
-               for timer in session.nav.RecordTimer.timer_list:
-                       list.append(TimerEntryComponent(timer, 0))
-               
-               for timer in session.nav.RecordTimer.processed_timers:
-                       list.append(TimerEntryComponent(timer, 1))
-               
+               self.list = list
+               self.fillTimerList()
+
                self["timerlist"] = TimerList(list)
                
                self["key_red"] = Button("Delete")
@@ -76,17 +31,29 @@ class TimerEditList(Screen):
                                "ok": self.openEdit,
                                "cancel": self.close,
                                "red": self.removeTimer,
-                               "green": self.addTimer
+                               "green": self.addCurrentTimer
                        })
 
+       def fillTimerList(self):
+               del self.list[:]
+               
+               for timer in self.session.nav.RecordTimer.timer_list:
+                       self.list.append(TimerEntryComponent(timer, 0))
+               
+               for timer in self.session.nav.RecordTimer.processed_timers:
+                       self.list.append(TimerEntryComponent(timer, 1))
+
        def openEdit(self):
-               self.session.open(TimerEntry, self["timerlist"].getCurrent()[0])
+               self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
                #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
                
        def removeTimer(self):
+               # FIXME doesn't work...
                self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
+               self.fillTimerList()
+               self["timerlist"].invalidate()
        
-       def addTimer(self):
+       def addCurrentTimer(self):
                begin = time()
                end = time() + 60
                
@@ -114,6 +81,21 @@ class TimerEditList(Screen):
                # FIXME only works if already playing a service
                serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
                
-               newEntry = RecordTimerEntry(begin, end, serviceref, epg, description)
-               self.session.open(TimerEntry, newEntry)
+               self.addTimer(RecordTimerEntry(begin, end, serviceref, epg, description))
+               
+       def addTimer(self, timer):
+               self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
                
+       def finishedEdit(self, answer):
+               if (answer[0]):
+                       print "Edited timer"
+                       self.fillTimerList()
+               else:
+                       print "Timeredit aborted"
+                       
+       def finishedAdd(self, answer):
+               if (answer[0]):
+                       self.session.nav.RecordTimer.record(answer[1])
+                       self.fillTimerList()
+               else:
+                       print "Timeredit aborted"