Frequency -> Repeats (thanks to Timo Jarvenpaa)
[enigma2.git] / lib / python / Screens / TimerEntry.py
index fe44d9a3fe36a77be86a3a88f5137f37259e4f18..e550519faec556615005a16e20e7ec749bc775a0 100644 (file)
@@ -1,15 +1,14 @@
 from Screen import Screen
+from LocationBox import LocationBox
 import ChannelSelection
 from ServiceReference import ServiceReference
-from Components.config import ConfigSelection, ConfigText, ConfigSubList, ConfigSubsection, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
-from Components.ActionMap import ActionMap, NumberActionMap
-from Components.ConfigList import ConfigList, ConfigListScreen
+from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
+from Components.ActionMap import NumberActionMap
+from Components.ConfigList import ConfigListScreen
 from Components.MenuList import MenuList
 from Components.Button import Button
-from Components.NimManager import nimmanager
 from Components.Label import Label
 from Components.Pixmap import Pixmap
-from Screens.MessageBox import MessageBox
 from Screens.ChoiceBox import ChoiceBox
 from RecordTimer import AFTEREVENT
 from enigma import eEPGCache
@@ -27,22 +26,32 @@ class TimerEntry(Screen, ConfigListScreen):
                
                self["oktext"] = Label(_("OK"))
                self["canceltext"] = Label(_("Cancel"))
+               self["locationtext"] = Label(_("Choose Location"))
                self["ok"] = Pixmap()
                self["cancel"] = Pixmap()
+               self["location"] = Pixmap()
 
                self.createConfig()
 
-               self["actions"] = NumberActionMap(["SetupActions"],
+               self["actions"] = NumberActionMap(["SetupActions", "ColorActions"],
                {
                        "ok": self.keySelect,
                        "save": self.keyGo,
                        "cancel": self.keyCancel,
+                       "yellow": self.selectPath,
                }, -2)
 
                self.list = []
                ConfigListScreen.__init__(self, self.list, session = session)
                self.createSetup("config")
 
+               self.onLayoutFinish.append(self.handleLocation)
+
+       def handleLocation(self):
+               if config.usage.setup_level.index < 2: # -expert
+                       self["locationtext"].hide()
+                       self["location"].hide()
+
        def createConfig(self):
                        justplay = self.timer.justplay
                                
@@ -83,11 +92,11 @@ class TimerEntry(Screen, ConfigListScreen):
                                weekday = (int(time.strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
                                day[weekday] = 1
                        
-                       self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "record"}[justplay])
+                       self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
                        self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby"))], default = afterevent)
                        self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
-                       self.timerentry_name = ConfigText(default = self.timer.name, fixed_size = False)
-                       self.timerentry_description = ConfigText(default = self.timer.description, fixed_size = False)
+                       self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
+                       self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
 
                        self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
 
@@ -97,6 +106,10 @@ class TimerEntry(Screen, ConfigListScreen):
                        self.timerentry_enddate = ConfigDateTime(default = self.timer.end, formatstring =  _("%d.%B %Y"), increment = 86400)
                        self.timerentry_endtime = ConfigClock(default = self.timer.end)
 
+                       self.timerentry_dirname = ConfigSelection(choices = [self.timer.dirname or "/hdd/movie/"])
+
+                       self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
+
                        self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
 
                        self.timerentry_day = ConfigSubList()
@@ -109,6 +122,7 @@ class TimerEntry(Screen, ConfigListScreen):
                                servicename = str(self.timer.service_ref.getServiceName())
                        except:
                                pass
+                       self.timerentry_service_ref = self.timer.service_ref
                        self.timerentry_service = ConfigSelection([servicename])
                        
                        self.timerentry_startdate.addNotifier(self.checkDate)
@@ -136,8 +150,10 @@ class TimerEntry(Screen, ConfigListScreen):
                if self.timerentry_type.value == "once":
                        self.frequencyEntry = None
                else: # repeated
-                       self.frequencyEntry = getConfigListEntry(_("Frequency"), self.timerentry_repeated)
+                       self.frequencyEntry = getConfigListEntry(_("Repeats"), self.timerentry_repeated)
                        self.list.append(self.frequencyEntry)
+                       self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
+                       self.list.append(self.repeatedbegindateEntry)
                        if self.timerentry_repeated.value == "daily":
                                pass
                        if self.timerentry_repeated.value == "weekdays":
@@ -174,6 +190,8 @@ class TimerEntry(Screen, ConfigListScreen):
                                self.list.append(getConfigListEntry(_("EndTime"), self.timerentry_endtime))
 
                if self.timerentry_justplay.value != "zap":
+                       if config.usage.setup_level.index >= 2: # expert+
+                               self.list.append(getConfigListEntry(_("Location"), self.timerentry_dirname))
                        self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
 
                self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
@@ -213,8 +231,8 @@ class TimerEntry(Screen, ConfigListScreen):
 
        def finishedChannelSelection(self, *args):
                if len(args):
-                       self.timer.service_ref = ServiceReference(args[0])
-                       self.timerentry_service.setCurrentText(self.timer.service_ref.getServiceName())
+                       self.timerentry_service_ref = ServiceReference(args[0])
+                       self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
                        self["config"].invalidate(self.channelEntry)
 
        def getTimestamp(self, date, mytime):
@@ -222,6 +240,11 @@ class TimerEntry(Screen, ConfigListScreen):
                dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
                return int(time.mktime(dt.timetuple()))
 
+       def buildRepeatedBegin(self, rep_time, start_time):
+               d = time.localtime(rep_time)
+               dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, start_time[0], start_time[1])
+               return int(time.mktime(dt.timetuple()))
+
        def getBeginEnd(self):
                enddate = self.timerentry_enddate.value
                endtime = self.timerentry_endtime.value
@@ -245,7 +268,14 @@ class TimerEntry(Screen, ConfigListScreen):
                self.timer.justplay = self.timerentry_justplay.value == "zap"
                self.timer.resetRepeated()
                self.timer.afterEvent = {"nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY}[self.timerentry_afterevent.value]
-               
+               self.timer.service_ref = self.timerentry_service_ref
+
+               # TODO: fix that thing with none (this might as well just be ignored)
+               if self.timerentry_dirname.value == "/hdd/movie/":
+                       self.timer.dirname = None
+               else:
+                       self.timer.dirname = self.timerentry_dirname.value
+
                if self.timerentry_type.value == "once":
                        self.timer.begin, self.timer.end = self.getBeginEnd()
                if self.timerentry_type.value == "repeated":
@@ -265,6 +295,7 @@ class TimerEntry(Screen, ConfigListScreen):
                                        if self.timerentry_day[x].value:
                                                self.timer.setRepeated(x)
 
+                       self.timer.repeatedbegindate = self.buildRepeatedBegin(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
                        self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
                        self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
                        
@@ -288,16 +319,40 @@ class TimerEntry(Screen, ConfigListScreen):
                                                tlist.append((i.getName(), i))
                                        self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
                                        return
+
+               self.saveTimer()
                self.close((True, self.timer))
 
        def subserviceSelected(self, service):
                if not service is None:
                        self.timer.service_ref = ServiceReference(service[1])
+               self.saveTimer()
                self.close((True, self.timer))
 
+       def saveTimer(self):
+               self.session.nav.RecordTimer.saveTimer()
+
        def keyCancel(self):
                self.close((False,))
-               
+
+       def selectPath(self):
+               if config.usage.setup_level.index < 2: #-expert
+                       return
+               self.session.openWithCallback(
+                       self.pathSelected,
+                       LocationBox,
+                       text = _("Choose target folder"),
+                       filename = "",
+                       currDir = None, # TODO: fix FileList to correctly determine mountpoint
+                       minFree = 100
+               )
+
+       def pathSelected(self, res):
+               if res is not None:
+                       self.timerentry_dirname.choices.append(res)
+                       self.timerentry_dirname.description[res] = res
+                       self.timerentry_dirname.value = res
+
 class TimerLog(Screen):
        def __init__(self, session, timer):
                Screen.__init__(self, session)
@@ -329,7 +384,10 @@ class TimerLog(Screen):
                }, -1)
 
        def deleteEntry(self):
-               self.log_entries.remove(self["loglist"].getCurrent()[1])
+               cur = self["loglist"].getCurrent()
+               if cur is None:
+                       return 
+               self.log_entries.remove(cur[1])
                self.fillLogList()
                self["loglist"].l.setList(self.list)
                self.updateText()