1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import config, ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
5 from Components.ActionMap import NumberActionMap
6 from Components.ConfigList import ConfigListScreen
7 from Components.MenuList import MenuList
8 from Components.Button import Button
9 from Components.Label import Label
10 from Components.Pixmap import Pixmap
11 from Components.SystemInfo import SystemInfo
12 from Components.UsageConfig import defaultMoviePath
13 from Screens.MovieSelection import getPreferredTagEditor
14 from Screens.LocationBox import MovieLocationBox
15 from Screens.ChoiceBox import ChoiceBox
16 from RecordTimer import AFTEREVENT
17 from enigma import eEPGCache
18 from time import localtime, mktime, time, strftime
19 from datetime import datetime
21 class TimerEntry(Screen, ConfigListScreen):
22 def __init__(self, session, timer):
23 Screen.__init__(self, session)
27 self.entryService = None
29 self["oktext"] = Label(_("OK"))
30 self["canceltext"] = Label(_("Cancel"))
32 self["cancel"] = Pixmap()
36 self["actions"] = NumberActionMap(["SetupActions", "GlobalActions", "PiPSetupActions"],
40 "cancel": self.keyCancel,
41 "volumeUp": self.incrementStart,
42 "volumeDown": self.decrementStart,
43 "size+": self.incrementEnd,
44 "size-": self.decrementEnd
48 ConfigListScreen.__init__(self, self.list, session = session)
49 self.createSetup("config")
51 def createConfig(self):
52 justplay = self.timer.justplay
55 AFTEREVENT.NONE: "nothing",
56 AFTEREVENT.DEEPSTANDBY: "deepstandby",
57 AFTEREVENT.STANDBY: "standby",
58 AFTEREVENT.AUTO: "auto"
59 }[self.timer.afterEvent]
61 weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
63 # calculate default values
66 for x in (0, 1, 2, 3, 4, 5, 6):
68 if self.timer.repeated: # repeated
70 if (self.timer.repeated == 31): # Mon-Fri
72 elif (self.timer.repeated == 127): # daily
75 flags = self.timer.repeated
78 for x in (0, 1, 2, 3, 4, 5, 6):
79 if flags == 1: # weekly
80 print "Set to weekday " + str(x)
82 if flags & 1 == 1: # set user defined flags
93 weekday = (int(strftime("%w", localtime(self.timer.begin))) - 1) % 7
96 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
97 if SystemInfo["DeepstandbySupport"]:
98 shutdownString = _("go to deep standby")
100 shutdownString = _("shut down")
101 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", shutdownString), ("auto", _("auto"))], default = afterevent)
102 self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
103 self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
104 self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
105 self.timerentry_tags = self.timer.tags[:]
106 self.timerentry_tagsset = ConfigSelection(choices = [not self.timerentry_tags and "None" or " ".join(self.timerentry_tags)])
108 self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
110 self.timerentry_date = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
111 self.timerentry_starttime = ConfigClock(default = self.timer.begin)
112 self.timerentry_endtime = ConfigClock(default = self.timer.end)
114 default = self.timer.dirname or defaultMoviePath()
115 tmp = config.movielist.videodirs.value
116 if default not in tmp:
118 self.timerentry_dirname = ConfigSelection(default = default, choices = tmp)
120 self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
122 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
124 self.timerentry_day = ConfigSubList()
125 for x in (0, 1, 2, 3, 4, 5, 6):
126 self.timerentry_day.append(ConfigYesNo(default = day[x]))
128 # FIXME some service-chooser needed here
130 try: # no current service available?
131 servicename = str(self.timer.service_ref.getServiceName())
134 self.timerentry_service_ref = self.timer.service_ref
135 self.timerentry_service = ConfigSelection([servicename])
137 def createSetup(self, widget):
139 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
140 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
141 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
142 self.list.append(self.timerJustplayEntry)
143 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), self.timerentry_type)
144 self.list.append(self.timerTypeEntry)
146 if self.timerentry_type.value == "once":
147 self.frequencyEntry = None
149 self.frequencyEntry = getConfigListEntry(_("Repeats"), self.timerentry_repeated)
150 self.list.append(self.frequencyEntry)
151 self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
152 self.list.append(self.repeatedbegindateEntry)
153 if self.timerentry_repeated.value == "daily":
155 if self.timerentry_repeated.value == "weekdays":
157 if self.timerentry_repeated.value == "weekly":
158 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
160 if self.timerentry_repeated.value == "user":
161 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
162 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
163 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
164 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
165 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
166 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
167 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
169 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
170 if self.timerentry_type.value == "once":
171 self.list.append(self.entryDate)
173 self.entryStartTime = getConfigListEntry(_("StartTime"), self.timerentry_starttime)
174 self.list.append(self.entryStartTime)
175 if self.timerentry_justplay.value != "zap":
176 self.entryEndTime = getConfigListEntry(_("EndTime"), self.timerentry_endtime)
177 self.list.append(self.entryEndTime)
179 self.entryEndTime = None
180 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
181 self.list.append(self.channelEntry)
183 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
184 self.tagsSet = getConfigListEntry(_("Tags"), self.timerentry_tagsset)
185 if self.timerentry_justplay.value != "zap":
186 if config.usage.setup_level.index >= 2: # expert+
187 self.list.append(self.dirname)
188 if getPreferredTagEditor():
189 self.list.append(self.tagsSet)
190 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
192 self[widget].list = self.list
193 self[widget].l.setList(self.list)
196 print "newConfig", self["config"].getCurrent()
197 if self["config"].getCurrent() == self.timerTypeEntry:
198 self.createSetup("config")
199 if self["config"].getCurrent() == self.timerJustplayEntry:
200 self.createSetup("config")
201 if self["config"].getCurrent() == self.frequencyEntry:
202 self.createSetup("config")
205 if self["config"].getCurrent() in (self.channelEntry, self.tagsSet):
208 ConfigListScreen.keyLeft(self)
212 if self["config"].getCurrent() in (self.channelEntry, self.tagsSet):
215 ConfigListScreen.keyRight(self)
219 cur = self["config"].getCurrent()
220 if cur == self.channelEntry:
221 self.session.openWithCallback(
222 self.finishedChannelSelection,
223 ChannelSelection.SimpleChannelSelection,
224 _("Select channel to record from")
226 elif config.usage.setup_level.index >= 2 and cur == self.dirname:
227 self.session.openWithCallback(
230 _("Choose target folder"),
231 self.timerentry_dirname.value,
232 minFree = 100 # We require at least 100MB free space
234 elif getPreferredTagEditor() and cur == self.tagsSet:
235 self.session.openWithCallback(
236 self.tagEditFinished,
237 getPreferredTagEditor(),
243 def finishedChannelSelection(self, *args):
245 self.timerentry_service_ref = ServiceReference(args[0])
246 self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
247 self["config"].invalidate(self.channelEntry)
249 def getTimestamp(self, date, mytime):
251 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
252 return int(mktime(dt.timetuple()))
254 def getBeginEnd(self):
255 date = self.timerentry_date.value
256 endtime = self.timerentry_endtime.value
257 starttime = self.timerentry_starttime.value
259 begin = self.getTimestamp(date, starttime)
260 end = self.getTimestamp(date, endtime)
262 # if the endtime is less than the starttime, add 1 day.
268 self.timer.name = self.timerentry_name.value
269 self.timer.description = self.timerentry_description.value
270 self.timer.justplay = self.timerentry_justplay.value == "zap"
271 self.timer.resetRepeated()
272 self.timer.afterEvent = {
273 "nothing": AFTEREVENT.NONE,
274 "deepstandby": AFTEREVENT.DEEPSTANDBY,
275 "standby": AFTEREVENT.STANDBY,
276 "auto": AFTEREVENT.AUTO
277 }[self.timerentry_afterevent.value]
278 self.timer.service_ref = self.timerentry_service_ref
279 self.timer.tags = self.timerentry_tags
281 if self.timer.dirname or self.timerentry_dirname.value != defaultMoviePath():
282 self.timer.dirname = self.timerentry_dirname.value
283 config.movielist.last_timer_videodir.value = self.timer.dirname
284 config.movielist.last_timer_videodir.save()
286 if self.timerentry_type.value == "once":
287 self.timer.begin, self.timer.end = self.getBeginEnd()
288 if self.timerentry_type.value == "repeated":
289 if self.timerentry_repeated.value == "daily":
290 for x in (0, 1, 2, 3, 4, 5, 6):
291 self.timer.setRepeated(x)
293 if self.timerentry_repeated.value == "weekly":
294 self.timer.setRepeated(self.timerentry_weekday.index)
296 if self.timerentry_repeated.value == "weekdays":
297 for x in (0, 1, 2, 3, 4):
298 self.timer.setRepeated(x)
300 if self.timerentry_repeated.value == "user":
301 for x in (0, 1, 2, 3, 4, 5, 6):
302 if self.timerentry_day[x].value:
303 self.timer.setRepeated(x)
305 self.timer.repeatedbegindate = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
306 if self.timer.repeated:
307 self.timer.begin = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
308 self.timer.end = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_endtime.value)
310 self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
311 self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
313 # when a timer end is set before the start, add 1 day
314 if self.timer.end < self.timer.begin:
315 self.timer.end += 86400
317 if self.timer.eit is not None:
318 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
320 n = event.getNumOfLinkageServices()
323 ref = self.session.nav.getCurrentlyPlayingServiceReference()
324 parent = self.timer.service_ref.ref
327 i = event.getLinkageService(parent, x)
328 if i.toString() == ref.toString():
330 tlist.append((i.getName(), i))
331 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
334 parent = self.timer.service_ref.ref
335 self.timer.service_ref = ServiceReference(event.getLinkageService(parent, 0))
337 self.close((True, self.timer))
339 def incrementStart(self):
340 self.timerentry_starttime.increment()
341 self["config"].invalidate(self.entryStartTime)
343 def decrementStart(self):
344 self.timerentry_starttime.decrement()
345 self["config"].invalidate(self.entryStartTime)
347 def incrementEnd(self):
348 if self.entryEndTime is not None:
349 self.timerentry_endtime.increment()
350 self["config"].invalidate(self.entryEndTime)
352 def decrementEnd(self):
353 if self.entryEndTime is not None:
354 self.timerentry_endtime.decrement()
355 self["config"].invalidate(self.entryEndTime)
357 def subserviceSelected(self, service):
358 if not service is None:
359 self.timer.service_ref = ServiceReference(service[1])
361 self.close((True, self.timer))
364 self.session.nav.RecordTimer.saveTimer()
369 def pathSelected(self, res):
371 if config.movielist.videodirs.value != self.timerentry_dirname.choices:
372 self.timerentry_dirname.setChoices(config.movielist.videodirs.value, default=res)
373 self.timerentry_dirname.value = res
375 def tagEditFinished(self, ret):
377 self.timerentry_tags = ret
378 self.timerentry_tagsset.setChoices([not ret and "None" or " ".join(ret)])
379 self["config"].invalidate(self.tagsSet)
381 class TimerLog(Screen):
382 def __init__(self, session, timer):
383 Screen.__init__(self, session)
385 self.log_entries = self.timer.log_entries[:]
389 self["loglist"] = MenuList(self.list)
390 self["logentry"] = Label()
392 self["key_red"] = Button(_("Delete entry"))
393 self["key_green"] = Button()
394 self["key_yellow"] = Button("")
395 self["key_blue"] = Button(_("Clear log"))
397 self.onShown.append(self.updateText)
399 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
402 "cancel": self.keyClose,
407 "red": self.deleteEntry,
408 "blue": self.clearLog
411 def deleteEntry(self):
412 cur = self["loglist"].getCurrent()
415 self.log_entries.remove(cur[1])
417 self["loglist"].l.setList(self.list)
420 def fillLogList(self):
421 self.list = [(str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x) for x in self.log_entries]
424 self.log_entries = []
426 self["loglist"].l.setList(self.list)
430 if self.timer.log_entries != self.log_entries:
431 self.timer.log_entries = self.log_entries
432 self.close((True, self.timer))
437 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
441 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
445 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
449 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
452 def updateText(self):
454 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
456 self["logentry"].setText("")