1 # -*- coding: UTF-8 -*-
2 # for localized messages
6 from Screens.Screen import Screen
7 from Components.ConfigList import ConfigListScreen
8 from Screens.ChannelSelection import SimpleChannelSelection
9 from Screens.EpgSelection import EPGSelection
10 from Screens.MessageBox import MessageBox
11 from Screens.ChoiceBox import ChoiceBox
14 from Screens.Setup import SetupSummary
17 from Components.ActionMap import ActionMap
18 from Components.Button import Button
21 from Components.config import getConfigListEntry, ConfigEnableDisable, \
22 ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection, \
26 from RecordTimer import AFTEREVENT
28 # Needed to convert our timestamp back and forth
29 from time import localtime, mktime
31 # Show ServiceName instead of ServiceReference
32 from ServiceReference import ServiceReference
34 # addAutotimerFromService
35 from enigma import eServiceCenter, iServiceInformation
37 # Default Record Directory
38 from Tools import Directories
41 from Screens.MovieSelection import getPreferredTagEditor
46 ("2", _("Wednesday")),
51 ("weekend", _("Weekend")),
52 ("weekday", _("Weekday"))
55 class ExtendedConfigText(ConfigText):
56 def __init__(self, default = "", fixed_size = True, visible_width = False):
57 ConfigText.__init__(self, default = default, fixed_size = fixed_size, visible_width = visible_width)
59 # Workaround some characters currently not "typeable" using NumericalTextInput
60 mapping = self.mapping
62 if "&" not in mapping[0]:
64 if ";" not in mapping[0]:
66 if "%" not in mapping[0]:
69 class SimpleBouquetSelection(SimpleChannelSelection):
70 def __init__(self, session, title):
71 SimpleChannelSelection.__init__(self, session, title)
72 self.skinName = "SimpleChannelSelection"
74 def channelSelected(self): # just return selected service
75 ref = self.getCurrentSelection()
76 if (ref.flags & 7) == 7:
79 # We return the currently active path here
80 # Asking the user if this is what he wants might be better though
81 self.close(self.servicePath[-1])
83 class AutoTimerEPGSelection(EPGSelection):
84 def __init__(self, *args):
85 EPGSelection.__init__(self, *args)
86 self.skinName = "EPGSelection"
88 def infoKeyPressed(self):
92 cur = self["list"].getCurrent()
98 addAutotimerFromEvent(self.session, evt = evt, service = sref)
100 class AutoTimerEditorBase:
101 """ Base Class for all Editors """
102 def __init__(self, timer, editingDefaults = False):
105 self.editingDefaults = editingDefaults
107 # See if we are filtering some strings
109 timer.getExcludedTitle(),
110 timer.getExcludedShort(),
111 timer.getExcludedDescription(),
112 timer.getExcludedDays()
115 timer.getIncludedTitle(),
116 timer.getIncludedShort(),
117 timer.getIncludedDescription(),
118 timer.getIncludedDays()
120 if len(self.excludes[0]) or len(self.excludes[1]) \
121 or len(self.excludes[2]) or len(self.excludes[3]) \
122 or len(self.includes[0]) or len(self.includes[1]) \
123 or len(self.includes[2]) or len(self.includes[3]):
124 self.filterSet = True
126 self.filterSet = False
128 # See if services are restricted
129 self.services = timer.getServices()
130 self.bouquets = timer.getBouquets()
131 if len(self.services) or len(self.bouquets):
132 self.serviceRestriction = True
134 self.serviceRestriction = False
136 self.createSetup(timer)
138 def createSetup(self, timer):
140 self.name = ExtendedConfigText(default = timer.name, fixed_size = False)
143 self.match = ExtendedConfigText(default = timer.match, fixed_size = False)
144 self.match.setUseableChars('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789-_?!.:;,&%()\'"+/$@') # XXX: what exactly is useable? :-)
147 self.justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[int(timer.justplay)])
150 now = [x for x in localtime()]
151 if timer.hasTimespan():
153 now[3] = timer.timespan[0][0]
154 now[4] = timer.timespan[0][1]
156 now[3] = timer.timespan[1][0]
157 now[4] = timer.timespan[1][1]
167 self.timespan = ConfigEnableDisable(default = default)
168 self.timespanbegin = ConfigClock(default = begin)
169 self.timespanend = ConfigClock(default = end)
171 # Services have their own Screen
174 if timer.hasOffset():
176 begin = timer.getOffsetBegin()
177 end = timer.getOffsetEnd()
182 self.offset = ConfigEnableDisable(default = default)
183 self.offsetbegin = ConfigNumber(default = begin)
184 self.offsetend = ConfigNumber(default = end)
187 if timer.hasAfterEvent():
190 AFTEREVENT.NONE: "nothing",
191 AFTEREVENT.DEEPSTANDBY: "deepstandby",
192 AFTEREVENT.STANDBY: "standby",
193 AFTEREVENT.AUTO: "auto"
194 }[timer.afterevent[0][0]]
196 afterevent = "default"
197 self.afterevent = ConfigSelection(choices = [("default", _("standard")), ("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby")), ("auto", _("auto"))], default = afterevent)
199 # AfterEvent (Timespan)
200 if timer.hasAfterEvent() and timer.afterevent[0][1][0] is not None:
202 now[3] = timer.afterevent[0][1][0][0]
203 now[4] = timer.afterevent[0][1][0][1]
205 now[3] = timer.afterevent[0][1][1][0]
206 now[4] = timer.afterevent[0][1][1][1]
216 self.afterevent_timespan = ConfigEnableDisable(default = default)
217 self.afterevent_timespanbegin = ConfigClock(default = begin)
218 self.afterevent_timespanend = ConfigClock(default = end)
221 self.enabled = ConfigYesNo(default = timer.enabled)
224 if timer.hasDuration():
226 duration = timer.getDuration()
230 self.duration = ConfigEnableDisable(default = default)
231 self.durationlength = ConfigNumber(default = duration)
234 if timer.hasCounter():
235 default = timer.matchCount
238 self.counter = ConfigNumber(default = default)
239 self.counterLeft = ConfigNumber(default = timer.matchLeft)
240 selection = [("", _("Never")), ("%m", _("Monthly")), ("%U", _("Weekly (Sunday)")), ("%W", _("Weekly (Monday)"))]
241 if timer.getCounterFormatString() not in ["", "%m", "%U", "%W"]:
242 selection.append((timer.getCounterFormatString(), _("Custom (%s)") % (timer.getCounterFormatString())))
243 self.counterFormatString = ConfigSelection(selection, default = timer.getCounterFormatString())
245 # Avoid Duplicate Description
246 self.avoidDuplicateDescription = ConfigSelection([
248 ("1", _("On same service")),
249 ("2", _("On any service")),
251 default = str(timer.getAvoidDuplicateDescription())
255 if timer.hasDestination():
260 self.useDestination = ConfigYesNo(default = default)
262 default = timer.destination or Directories.resolveFilename(Directories.SCOPE_HDD)
263 choices = config.movielist.videodirs.value
265 if default not in choices:
266 choices.append(default)
267 self.destination = ConfigSelection(default = default, choices = choices)
270 self.timerentry_tags = timer.tags
271 self.tags = ConfigSelection(choices = [len(self.timerentry_tags) == 0 and _("None") or ' '.join(self.timerentry_tags)])
273 def pathSelected(self, res):
275 if res not in self.destination.choices:
276 self.destination.choices.append(res)
277 self.destination.description[res] = res
278 self.destination.value = res
280 def chooseDestination(self):
281 from Screens.LocationBox import MovieLocationBox
283 self.session.openWithCallback(
286 _("Choose target folder"),
287 self.destination.value,
288 minFree = 100 # Same requirement as in Screens.TimerEntry
291 def tagEditFinished(self, ret):
293 self.timerentry_tags = ret
294 self.tags.setChoices([len(ret) == 0 and _("None") or ' '.join(ret)])
296 def chooseTags(self):
297 preferredTagEditor = getPreferredTagEditor()
298 if preferredTagEditor:
299 self.session.openWithCallback(
300 self.tagEditFinished,
305 class AutoTimerEditor(Screen, ConfigListScreen, AutoTimerEditorBase):
308 skin = """<screen name="AutoTimerEdit" title="Edit AutoTimer" position="75,155" size="565,280">
309 <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
310 <ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
311 <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
312 <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
313 <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
314 <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
315 <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
316 <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
317 <widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
320 def __init__(self, session, timer, editingDefaults = False):
321 Screen.__init__(self, session)
323 AutoTimerEditorBase.__init__(self, timer, editingDefaults)
326 self.setup_title = _("AutoTimer Editor")
327 self.onChangedEntry = []
329 # We might need to change shown items, so add some notifiers
330 self.timespan.addNotifier(self.reloadList, initial_call = False)
331 self.offset.addNotifier(self.reloadList, initial_call = False)
332 self.duration.addNotifier(self.reloadList, initial_call = False)
333 self.afterevent.addNotifier(self.reloadList, initial_call = False)
334 self.afterevent_timespan.addNotifier(self.reloadList, initial_call = False)
335 self.counter.addNotifier(self.reloadList, initial_call = False)
336 self.useDestination.addNotifier(self.reloadList, initial_call = False)
340 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
343 self["key_red"] = Button(_("Cancel"))
344 self["key_green"] = Button(_("OK"))
345 self["key_yellow"] = Button()
346 self["key_blue"] = Button()
349 self.renameServiceButton()
350 self.renameFilterButton()
353 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
355 "cancel": self.cancel,
356 "save": self.maybeSave,
358 "yellow": self.editFilter,
359 "blue": self.editServices
366 self.onLayoutFinish.append(self.setCustomTitle)
368 def setCustomTitle(self):
369 self.setTitle(_("Edit AutoTimer"))
371 def renameFilterButton(self):
373 self["key_yellow"].setText(_("Edit Filters"))
375 self["key_yellow"].setText(_("Add Filters"))
377 def renameServiceButton(self):
378 if self.serviceRestriction:
379 self["key_blue"].setText(_("Edit Services"))
381 self["key_blue"].setText(_("Add Services"))
384 for x in self.onChangedEntry:
390 def getCurrentEntry(self):
391 return self["config"].getCurrent()[0]
393 def getCurrentValue(self):
394 return str(self["config"].getCurrent()[1].getText())
396 def createSummary(self):
400 # First three entries are only showed when not editing defaults
402 if not self.editingDefaults:
404 getConfigListEntry(_("Enabled"), self.enabled),
405 getConfigListEntry(_("Description"), self.name),
406 getConfigListEntry(_("Match Title"), self.match),
410 getConfigListEntry(_("Timer Type"), self.justplay),
411 getConfigListEntry(_("Only match during Timespan"), self.timespan)
414 # Only allow editing timespan when it's enabled
415 if self.timespan.value:
417 getConfigListEntry(_("Begin of Timespan"), self.timespanbegin),
418 getConfigListEntry(_("End of Timespan"), self.timespanend)
421 self.list.append(getConfigListEntry(_("Custom offset"), self.offset))
423 # Only allow editing offsets when it's enabled
424 if self.offset.value:
426 getConfigListEntry(_("Offset before recording (in m)"), self.offsetbegin),
427 getConfigListEntry(_("Offset after recording (in m)"), self.offsetend)
430 self.list.append(getConfigListEntry(_("Set maximum Duration"), self.duration))
432 # Only allow editing maxduration when it's enabled
433 if self.duration.value:
434 self.list.append(getConfigListEntry(_("Maximum Duration (in m)"), self.durationlength))
436 self.list.append(getConfigListEntry(_("After event"), self.afterevent))
438 # Only allow setting afterevent timespan when afterevent is active
439 if self.afterevent.value != "default":
440 self.list.append(getConfigListEntry(_("Execute after Event during Timespan"), self.afterevent_timespan))
442 # Only allow editing timespan when it's enabled
443 if self.afterevent_timespan.value:
445 getConfigListEntry(_("Begin of after Event Timespan"), self.afterevent_timespanbegin),
446 getConfigListEntry(_("End of after Event Timespan"), self.afterevent_timespanend)
449 self.list.append(getConfigListEntry(_("Record a maximum of x times"), self.counter))
451 # Only allow setting matchLeft when counting hits
452 if self.counter.value:
453 if not self.editingDefaults:
454 self.list.append(getConfigListEntry(_("Ammount of recordings left"), self.counterLeft))
455 self.list.append(getConfigListEntry(_("Reset Count"), self.counterFormatString))
457 self.list.append(getConfigListEntry(_("Require Description to be unique"), self.avoidDuplicateDescription))
459 # We always add this option though its expert only in enigma2
460 self.list.append(getConfigListEntry(_("Use a custom location"), self.useDestination))
461 if self.useDestination.value:
462 self.list.append(getConfigListEntry(_("Custom Location"), self.destination))
464 self.list.append(getConfigListEntry(_("Tags"), self.tags))
466 def reloadList(self, value):
468 self["config"].setList(self.list)
470 def editFilter(self):
471 self.session.openWithCallback(
472 self.editFilterCallback,
473 AutoTimerFilterEditor,
479 def editFilterCallback(self, ret):
481 self.filterSet = ret[0]
482 self.excludes = ret[1]
483 self.includes = ret[2]
484 self.renameFilterButton()
486 def editServices(self):
487 self.session.openWithCallback(
488 self.editServicesCallback,
489 AutoTimerServiceEditor,
490 self.serviceRestriction,
495 def editServicesCallback(self, ret):
497 self.serviceRestriction = ret[0]
498 self.services = ret[1][0]
499 self.bouquets = ret[1][1]
500 self.renameServiceButton()
503 cur = self["config"].getCurrent()
505 if cur == self.destination:
506 self.chooseDestination()
507 elif cur == self.tags:
510 ConfigListScreen.keyOK(self)
513 if self["config"].isChanged():
514 self.session.openWithCallback(
517 _("Really close without saving settings?")
522 def cancelConfirm(self, ret):
527 if self.editingDefaults:
530 # Check if any match is set
531 if not self.match.value.strip():
534 _("The match attribute is mandatory."),
535 type = MessageBox.TYPE_ERROR,
538 # Check if we have a trailing whitespace
539 elif self.match.value[-1:] == " ":
540 self.session.openWithCallback(
543 _('You entered "%s" as Text to match.\nDo you want to remove trailing whitespaces?') % (self.match.value)
549 def saveCallback(self, ret):
552 self.match.value = self.match.value.rstrip()
554 # Don't to anything if MessageBox was canceled!
558 self.timer.match = self.match.value
561 self.timer.name = self.name.value.strip() or self.timer.match
564 self.timer.enabled = self.enabled.value
567 self.timer.justplay = self.justplay.value == "zap"
570 if self.timespan.value:
571 start = self.timespanbegin.value
572 end = self.timespanend.value
573 self.timer.timespan = (start, end)
575 self.timer.timespan = None
578 if self.serviceRestriction:
579 self.timer.services = self.services
580 self.timer.bouquets = self.bouquets
582 self.timer.services = None
583 self.timer.bouquets = None
586 if self.offset.value:
587 self.timer.offset = (self.offsetbegin.value*60, self.offsetend.value*60)
589 self.timer.offset = None
592 if self.afterevent.value == "default":
593 self.timer.afterevent = []
596 "nothing": AFTEREVENT.NONE,
597 "deepstandby": AFTEREVENT.DEEPSTANDBY,
598 "standby": AFTEREVENT.STANDBY,
599 "auto": AFTEREVENT.AUTO
600 }[self.afterevent.value]
601 # AfterEvent Timespan
602 if self.afterevent_timespan.value:
603 start = self.afterevent_timespanbegin.value
604 end = self.afterevent_timespanend.value
605 self.timer.afterevent = [(afterevent, (start, end))]
607 self.timer.afterevent = [(afterevent, None)]
610 if self.duration.value:
611 self.timer.maxduration = self.durationlength.value*60
613 self.timer.maxduration = None
617 self.timer.exclude = self.excludes
618 self.timer.include = self.includes
620 self.timer.exclude = None
621 self.timer.include = None
624 if self.counter.value:
625 self.timer.matchCount = self.counter.value
626 if self.counterLeft.value <= self.counter.value:
627 self.timer.matchLeft = self.counterLeft.value
629 self.timer.matchLeft = self.counter.value
630 if self.counterFormatString.value:
631 self.timer.matchFormatString = self.counterFormatString.value
633 self.timer.matchFormatString = ''
635 self.timer.matchCount = 0
636 self.timer.matchLeft = 0
637 self.timer.matchFormatString = ''
639 self.timer.avoidDuplicateDescription = int(self.avoidDuplicateDescription.value)
641 if self.useDestination.value:
642 self.timer.destination = self.destination.value
644 self.timer.destination = None
646 self.timer.tags = self.timerentry_tags
649 self.close(self.timer)
651 class AutoTimerFilterEditor(Screen, ConfigListScreen):
652 """Edit AutoTimer Filter"""
654 skin = """<screen name="AutoFilterEditor" title="Edit AutoTimer Filters" position="75,150" size="565,245">
655 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
656 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
657 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
658 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
659 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
660 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
661 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
662 <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
663 <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
666 def __init__(self, session, filterset, excludes, includes):
667 Screen.__init__(self, session)
670 self.setup_title = _("AutoTimer Filters")
671 self.onChangedEntry = []
673 self.typeSelection = ConfigSelection(choices = [("title", _("in Title")), ("short", _("in Shortdescription")), ("desc", _("in Description")), ("day", _("on Weekday"))])
674 self.typeSelection.addNotifier(self.refresh, initial_call = False)
676 self.enabled = ConfigEnableDisable(default = filterset)
678 self.excludes = excludes
679 self.includes = includes
683 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
686 self["key_red"] = Button(_("Cancel"))
687 self["key_green"] = Button(_("Save"))
688 self["key_yellow"] = Button(_("delete"))
689 self["key_blue"] = Button(_("New"))
692 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
694 "cancel": self.cancel,
696 "yellow": self.remove,
704 self.onLayoutFinish.append(self.setCustomTitle)
706 def setCustomTitle(self):
707 self.setTitle(_("Edit AutoTimer Filters"))
711 for x in self.onChangedEntry:
717 def getCurrentEntry(self):
718 return self["config"].getCurrent()[0]
720 def getCurrentValue(self):
721 return str(self["config"].getCurrent()[1].getText())
723 def createSummary(self):
726 def saveCurrent(self):
727 del self.excludes[self.idx][:]
728 del self.includes[self.idx][:]
730 # Warning, accessing a ConfigListEntry directly might be considered evil!
733 for item in self["config"].getList()[:]:
735 # Skip empty entries (and those which are no filters)
736 if item[1].value == "" or idx < 2:
738 elif idx < self.lenExcludes:
739 self.excludes[self.idx].append(item[1].value.encode("UTF-8"))
741 self.includes[self.idx].append(item[1].value.encode("UTF-8"))
743 def refresh(self, *args, **kwargs):
747 self["config"].setList(self.list)
749 def reloadList(self):
751 getConfigListEntry(_("Enable Filtering"), self.enabled),
752 getConfigListEntry(_("Filter"), self.typeSelection)
755 if self.typeSelection.value == "day":
758 # Weekdays are presented as ConfigSelection
760 getConfigListEntry(_("Exclude"), ConfigSelection(choices = weekdays, default = x))
761 for x in self.excludes[3]
763 self.lenExcludes = len(self.list)
765 getConfigListEntry(_("Include"), ConfigSelection(choices = weekdays, default = x))
766 for x in self.includes[3]
769 elif self.typeSelection.value == "title":
771 elif self.typeSelection.value == "short":
773 else: # self.typeSelection.value == "desc":
777 getConfigListEntry(_("Exclude"), ExtendedConfigText(default = x, fixed_size = False))
778 for x in self.excludes[self.idx]
780 self.lenExcludes = len(self.list)
782 getConfigListEntry(_("Include"), ExtendedConfigText(default = x, fixed_size = False))
783 for x in self.includes[self.idx]
787 idx = self["config"].getCurrentIndex()
789 if idx < self.lenExcludes:
790 self.lenExcludes -= 1
792 list = self["config"].getList()
793 list.remove(self["config"].getCurrent())
794 self["config"].setList(list)
797 self.session.openWithCallback(
800 _("Select type of Filter"),
807 def typeSelected(self, ret):
809 list = self["config"].getList()
812 pos = self.lenExcludes
813 self.lenExcludes += 1
819 if self.typeSelection.value == "day":
820 entry = getConfigListEntry(text, ConfigSelection(choices = weekdays))
822 entry = getConfigListEntry(text, ExtendedConfigText(fixed_size = False))
824 list.insert(pos, entry)
825 self["config"].setList(list)
828 if self["config"].isChanged():
829 self.session.openWithCallback(
832 _("Really close without saving settings?")
837 def cancelConfirm(self, ret):
850 class AutoTimerServiceEditor(Screen, ConfigListScreen):
851 """Edit allowed Services of a AutoTimer"""
853 skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="75,150" size="565,245">
854 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
855 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
856 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
857 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
858 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
859 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
860 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
861 <widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
862 <widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
865 def __init__(self, session, servicerestriction, servicelist, bouquetlist):
866 Screen.__init__(self, session)
869 self.setup_title = _("AutoTimer Services")
870 self.onChangedEntry = []
877 self.enabled = ConfigEnableDisable(default = servicerestriction)
878 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
879 self.typeSelection.addNotifier(self.refresh, initial_call = False)
883 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
886 self["key_red"] = Button(_("Cancel"))
887 self["key_green"] = Button(_("OK"))
888 self["key_yellow"] = Button(_("delete"))
889 self["key_blue"] = Button(_("New"))
892 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
894 "cancel": self.cancel,
896 "yellow": self.remove,
904 self.onLayoutFinish.append(self.setCustomTitle)
906 def setCustomTitle(self):
907 self.setTitle(_("Edit AutoTimer Services"))
909 def saveCurrent(self):
910 del self.services[self.idx][:]
912 # Warning, accessing a ConfigListEntry directly might be considered evil!
914 myl = self["config"].getList()[:]
918 self.services[self.idx].append(item[1].value)
920 def refresh(self, *args, **kwargs):
924 self["config"].setList(self.list)
926 def reloadList(self):
928 getConfigListEntry(_("Enable Service Restriction"), self.enabled),
929 getConfigListEntry(_("Editing"), self.typeSelection)
932 if self.typeSelection.value == "channels":
934 else: # self.typeSelection.value == "bouquets":
938 getConfigListEntry(_("Record on"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
939 for x in self.services[self.idx]
943 for x in self.onChangedEntry:
949 def getCurrentEntry(self):
950 return self["config"].getCurrent()[0]
952 def getCurrentValue(self):
953 return str(self["config"].getCurrent()[1].getText())
955 def createSummary(self):
959 if self["config"].getCurrentIndex() != 0:
960 list = self["config"].getList()
961 list.remove(self["config"].getCurrent())
962 self["config"].setList(list)
965 if self.typeSelection.value == "channels":
966 self.session.openWithCallback(
967 self.finishedServiceSelection,
968 SimpleChannelSelection,
969 _("Select channel to record on")
971 else: # self.typeSelection.value == "bouquets":
972 self.session.openWithCallback(
973 self.finishedServiceSelection,
974 SimpleBouquetSelection,
975 _("Select bouquet to record on")
978 def finishedServiceSelection(self, *args):
980 list = self["config"].getList()
981 sname = args[0].toString()
983 if self.typeSelection.value == "channels":
984 # strip all after last : when adding a channel
985 pos = sname.rfind(':')
987 sname = sname[:pos+1]
989 list.append(getConfigListEntry(_("Record on"), ConfigSelection(choices = [(sname, ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))
990 self["config"].setList(list)
993 if self["config"].isChanged():
994 self.session.openWithCallback(
997 _("Really close without saving settings?")
1002 def cancelConfirm(self, ret):
1014 def addAutotimerFromEvent(session, evt = None, service = None):
1015 from AutoTimerComponent import AutoTimerComponent
1016 from AutoTimerImporter import AutoTimerImporter
1017 from plugin import autotimer
1019 # Create instance if needed
1020 if autotimer is None:
1021 from AutoTimer import AutoTimer
1022 autotimer = AutoTimer()
1025 match = evt and evt.getEventName() or ""
1026 name = match or "New AutoTimer"
1028 if service is not None:
1029 service = str(service)
1030 # strip all after last :
1031 pos = service.rfind(':')
1033 service = service[:pos+1]
1035 sref = ServiceReference(service)
1037 # timespan defaults to +- 1h
1038 begin = evt.getBeginTime()-3600
1039 end = begin + evt.getDuration()+7200
1043 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1045 session.openWithCallback(
1049 autotimer.getUniqueId(), # Id
1054 match, # Proposed Match
1055 begin, # Proposed Begin
1057 None, # Proposed Disabled
1058 sref, # Proposed ServiceReference
1059 None, # Proposed afterEvent
1060 None, # Proposed justplay
1061 None, # Proposed dirname, can we get anything useful here?
1065 def addAutotimerFromService(session, service = None):
1066 from AutoTimerComponent import AutoTimerComponent
1067 from AutoTimerImporter import AutoTimerImporter
1068 from plugin import autotimer
1070 # Create instance if needed
1071 if autotimer is None:
1072 from AutoTimer import AutoTimer
1073 autotimer = AutoTimer()
1076 serviceHandler = eServiceCenter.getInstance()
1077 info = serviceHandler.info(service)
1079 match = info and info.getName(service) or ""
1080 name = match or "New AutoTimer"
1081 sref = info and info.getInfoString(service, iServiceInformation.sServiceref)
1083 # strip all after last :
1084 pos = sref.rfind(':')
1088 sref = ServiceReference(sref)
1090 begin = info.getInfo(service, iServiceInformation.sTimeCreate)
1091 end = begin + info.getLength(service)
1095 from os.path import dirname
1096 path = dirname(service.getPath())
1100 tags = info.getInfoString(service, iServiceInformation.sTags)
1101 tags = tags and tags.split(' ') or []
1103 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1105 session.openWithCallback(
1109 autotimer.getUniqueId(), # Id
1114 match, # Proposed Match
1115 begin, # Proposed Begin
1117 None, # Proposed Disabled
1118 sref, # Proposed ServiceReference
1119 None, # Proposed afterEvent
1120 None, # Proposed justplay
1121 path, # Proposed dirname
1122 tags # Proposed tags
1125 def importerCallback(ret):
1129 session.openWithCallback(
1135 # Remove instance if not running in background
1136 if not config.plugins.autotimer.autopoll.value:
1137 from plugin import autotimer
1140 def editorCallback(ret):
1142 from plugin import autotimer
1144 # Create instance if needed (should have been created by addAutotimerFrom* above though)
1145 if autotimer is None:
1146 from AutoTimer import AutoTimer
1147 autotimer = AutoTimer()
1153 autotimer.writeXml()
1155 # Remove instance if not running in background
1156 if not config.plugins.autotimer.autopoll.value: