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 # Check if any match is set
528 if not self.match.value.strip():
531 _("The match attribute is mandatory."),
532 type = MessageBox.TYPE_ERROR,
535 # Check if we have a trailing whitespace
536 elif self.match.value[-1:] == " ":
537 self.session.openWithCallback(
540 _('You entered "%s" as Text to match.\nDo you want to remove trailing whitespaces?') % (self.match.value)
546 def saveCallback(self, ret):
549 self.match.value = self.match.value.rstrip()
551 # Don't to anything if MessageBox was canceled!
555 self.timer.match = self.match.value
558 self.timer.name = self.name.value.strip() or self.timer.match
561 self.timer.enabled = self.enabled.value
564 self.timer.justplay = self.justplay.value == "zap"
567 if self.timespan.value:
568 start = self.timespanbegin.value
569 end = self.timespanend.value
570 self.timer.timespan = (start, end)
572 self.timer.timespan = None
575 if self.serviceRestriction:
576 self.timer.services = self.services
577 self.timer.bouquets = self.bouquets
579 self.timer.services = None
580 self.timer.bouquets = None
583 if self.offset.value:
584 self.timer.offset = (self.offsetbegin.value*60, self.offsetend.value*60)
586 self.timer.offset = None
589 if self.afterevent.value == "default":
590 self.timer.afterevent = []
593 "nothing": AFTEREVENT.NONE,
594 "deepstandby": AFTEREVENT.DEEPSTANDBY,
595 "standby": AFTEREVENT.STANDBY,
596 "auto": AFTEREVENT.AUTO
597 }[self.afterevent.value]
598 # AfterEvent Timespan
599 if self.afterevent_timespan.value:
600 start = self.afterevent_timespanbegin.value
601 end = self.afterevent_timespanend.value
602 self.timer.afterevent = [(afterevent, (start, end))]
604 self.timer.afterevent = [(afterevent, None)]
607 if self.duration.value:
608 self.timer.maxduration = self.durationlength.value*60
610 self.timer.maxduration = None
614 self.timer.exclude = self.excludes
615 self.timer.include = self.includes
617 self.timer.exclude = None
618 self.timer.include = None
621 if self.counter.value:
622 self.timer.matchCount = self.counter.value
623 if self.counterLeft.value <= self.counter.value:
624 self.timer.matchLeft = self.counterLeft.value
626 self.timer.matchLeft = self.counter.value
627 if self.counterFormatString.value:
628 self.timer.matchFormatString = self.counterFormatString.value
630 self.timer.matchFormatString = ''
632 self.timer.matchCount = 0
633 self.timer.matchLeft = 0
634 self.timer.matchFormatString = ''
636 self.timer.avoidDuplicateDescription = int(self.avoidDuplicateDescription.value)
638 if self.useDestination.value:
639 self.timer.destination = self.destination.value
641 self.timer.destination = None
643 self.timer.tags = self.timerentry_tags
646 self.close(self.timer)
648 class AutoTimerFilterEditor(Screen, ConfigListScreen):
649 """Edit AutoTimer Filter"""
651 skin = """<screen name="AutoFilterEditor" title="Edit AutoTimer Filters" position="75,150" size="565,245">
652 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
653 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
654 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
655 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
656 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
657 <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" />
658 <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" />
659 <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" />
660 <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" />
663 def __init__(self, session, filterset, excludes, includes):
664 Screen.__init__(self, session)
667 self.setup_title = _("AutoTimer Filters")
668 self.onChangedEntry = []
670 self.typeSelection = ConfigSelection(choices = [("title", _("in Title")), ("short", _("in Shortdescription")), ("desc", _("in Description")), ("day", _("on Weekday"))])
671 self.typeSelection.addNotifier(self.refresh, initial_call = False)
673 self.enabled = ConfigEnableDisable(default = filterset)
675 self.excludes = excludes
676 self.includes = includes
680 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
683 self["key_red"] = Button(_("Cancel"))
684 self["key_green"] = Button(_("Save"))
685 self["key_yellow"] = Button(_("delete"))
686 self["key_blue"] = Button(_("New"))
689 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
691 "cancel": self.cancel,
693 "yellow": self.remove,
701 self.onLayoutFinish.append(self.setCustomTitle)
703 def setCustomTitle(self):
704 self.setTitle(_("Edit AutoTimer Filters"))
708 for x in self.onChangedEntry:
714 def getCurrentEntry(self):
715 return self["config"].getCurrent()[0]
717 def getCurrentValue(self):
718 return str(self["config"].getCurrent()[1].getText())
720 def createSummary(self):
723 def saveCurrent(self):
724 del self.excludes[self.idx][:]
725 del self.includes[self.idx][:]
727 # Warning, accessing a ConfigListEntry directly might be considered evil!
730 for item in self["config"].getList()[:]:
732 # Skip empty entries (and those which are no filters)
733 if item[1].value == "" or idx < 2:
735 elif idx < self.lenExcludes:
736 self.excludes[self.idx].append(item[1].value.encode("UTF-8"))
738 self.includes[self.idx].append(item[1].value.encode("UTF-8"))
740 def refresh(self, *args, **kwargs):
744 self["config"].setList(self.list)
746 def reloadList(self):
748 getConfigListEntry(_("Enable Filtering"), self.enabled),
749 getConfigListEntry(_("Filter"), self.typeSelection)
752 if self.typeSelection.value == "day":
755 # Weekdays are presented as ConfigSelection
757 getConfigListEntry(_("Exclude"), ConfigSelection(choices = weekdays, default = x))
758 for x in self.excludes[3]
760 self.lenExcludes = len(self.list)
762 getConfigListEntry(_("Include"), ConfigSelection(choices = weekdays, default = x))
763 for x in self.includes[3]
766 elif self.typeSelection.value == "title":
768 elif self.typeSelection.value == "short":
770 else: # self.typeSelection.value == "desc":
774 getConfigListEntry(_("Exclude"), ExtendedConfigText(default = x, fixed_size = False))
775 for x in self.excludes[self.idx]
777 self.lenExcludes = len(self.list)
779 getConfigListEntry(_("Include"), ExtendedConfigText(default = x, fixed_size = False))
780 for x in self.includes[self.idx]
784 idx = self["config"].getCurrentIndex()
786 if idx < self.lenExcludes:
787 self.lenExcludes -= 1
789 list = self["config"].getList()
790 list.remove(self["config"].getCurrent())
791 self["config"].setList(list)
794 self.session.openWithCallback(
797 _("Select type of Filter"),
804 def typeSelected(self, ret):
806 list = self["config"].getList()
809 pos = self.lenExcludes
810 self.lenExcludes += 1
816 if self.typeSelection.value == "day":
817 entry = getConfigListEntry(text, ConfigSelection(choices = weekdays))
819 entry = getConfigListEntry(text, ExtendedConfigText(fixed_size = False))
821 list.insert(pos, entry)
822 self["config"].setList(list)
825 if self["config"].isChanged():
826 self.session.openWithCallback(
829 _("Really close without saving settings?")
834 def cancelConfirm(self, ret):
847 class AutoTimerServiceEditor(Screen, ConfigListScreen):
848 """Edit allowed Services of a AutoTimer"""
850 skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="75,150" size="565,245">
851 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
852 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
853 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
854 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
855 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
856 <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" />
857 <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" />
858 <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" />
859 <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" />
862 def __init__(self, session, servicerestriction, servicelist, bouquetlist):
863 Screen.__init__(self, session)
866 self.setup_title = _("AutoTimer Services")
867 self.onChangedEntry = []
874 self.enabled = ConfigEnableDisable(default = servicerestriction)
875 self.typeSelection = ConfigSelection(choices = [("channels", _("Channels")), ("bouquets", _("Bouquets"))])
876 self.typeSelection.addNotifier(self.refresh, initial_call = False)
880 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
883 self["key_red"] = Button(_("Cancel"))
884 self["key_green"] = Button(_("OK"))
885 self["key_yellow"] = Button(_("delete"))
886 self["key_blue"] = Button(_("New"))
889 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
891 "cancel": self.cancel,
893 "yellow": self.remove,
901 self.onLayoutFinish.append(self.setCustomTitle)
903 def setCustomTitle(self):
904 self.setTitle(_("Edit AutoTimer Services"))
906 def saveCurrent(self):
907 del self.services[self.idx][:]
909 # Warning, accessing a ConfigListEntry directly might be considered evil!
911 myl = self["config"].getList()[:]
915 self.services[self.idx].append(item[1].value)
917 def refresh(self, *args, **kwargs):
921 self["config"].setList(self.list)
923 def reloadList(self):
925 getConfigListEntry(_("Enable Service Restriction"), self.enabled),
926 getConfigListEntry(_("Editing"), self.typeSelection)
929 if self.typeSelection.value == "channels":
931 else: # self.typeSelection.value == "bouquets":
935 getConfigListEntry(_("Record on"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
936 for x in self.services[self.idx]
940 for x in self.onChangedEntry:
946 def getCurrentEntry(self):
947 return self["config"].getCurrent()[0]
949 def getCurrentValue(self):
950 return str(self["config"].getCurrent()[1].getText())
952 def createSummary(self):
956 if self["config"].getCurrentIndex() != 0:
957 list = self["config"].getList()
958 list.remove(self["config"].getCurrent())
959 self["config"].setList(list)
962 if self.typeSelection.value == "channels":
963 self.session.openWithCallback(
964 self.finishedServiceSelection,
965 SimpleChannelSelection,
966 _("Select channel to record on")
968 else: # self.typeSelection.value == "bouquets":
969 self.session.openWithCallback(
970 self.finishedServiceSelection,
971 SimpleBouquetSelection,
972 _("Select bouquet to record on")
975 def finishedServiceSelection(self, *args):
977 list = self["config"].getList()
978 sname = args[0].toString()
980 if self.typeSelection.value == "channels":
981 # strip all after last : when adding a channel
982 pos = sname.rfind(':')
984 sname = sname[:pos+1]
986 list.append(getConfigListEntry(_("Record on"), ConfigSelection(choices = [(sname, ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))
987 self["config"].setList(list)
990 if self["config"].isChanged():
991 self.session.openWithCallback(
994 _("Really close without saving settings?")
999 def cancelConfirm(self, ret):
1011 def addAutotimerFromEvent(session, evt = None, service = None):
1012 from AutoTimerComponent import AutoTimerComponent
1013 from AutoTimerImporter import AutoTimerImporter
1014 from plugin import autotimer
1016 # Create instance if needed
1017 if autotimer is None:
1018 from AutoTimer import AutoTimer
1019 autotimer = AutoTimer()
1022 match = evt and evt.getEventName() or ""
1023 name = match or "New AutoTimer"
1025 if service is not None:
1026 service = str(service)
1027 # strip all after last :
1028 pos = service.rfind(':')
1030 service = service[:pos+1]
1032 sref = ServiceReference(service)
1034 # timespan defaults to +- 1h
1035 begin = evt.getBeginTime()-3600
1036 end = begin + evt.getDuration()+7200
1040 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1042 session.openWithCallback(
1046 autotimer.getUniqueId(), # Id
1051 match, # Proposed Match
1052 begin, # Proposed Begin
1054 None, # Proposed Disabled
1055 sref, # Proposed ServiceReference
1056 None, # Proposed afterEvent
1057 None, # Proposed justplay
1058 None, # Proposed dirname, can we get anything useful here?
1062 def addAutotimerFromService(session, service = None):
1063 from AutoTimerComponent import AutoTimerComponent
1064 from AutoTimerImporter import AutoTimerImporter
1065 from plugin import autotimer
1067 # Create instance if needed
1068 if autotimer is None:
1069 from AutoTimer import AutoTimer
1070 autotimer = AutoTimer()
1073 serviceHandler = eServiceCenter.getInstance()
1074 info = serviceHandler.info(service)
1076 match = info and info.getName(service) or ""
1077 name = match or "New AutoTimer"
1078 sref = info and info.getInfoString(service, iServiceInformation.sServiceref)
1080 # strip all after last :
1081 pos = sref.rfind(':')
1085 sref = ServiceReference(sref)
1087 begin = info.getInfo(service, iServiceInformation.sTimeCreate)
1088 end = begin + info.getLength(service)
1092 from os.path import dirname
1093 path = dirname(service.getPath())
1097 tags = info.getInfoString(service, iServiceInformation.sTags)
1098 tags = tags and tags.split(' ') or []
1100 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-)
1102 session.openWithCallback(
1106 autotimer.getUniqueId(), # Id
1111 match, # Proposed Match
1112 begin, # Proposed Begin
1114 None, # Proposed Disabled
1115 sref, # Proposed ServiceReference
1116 None, # Proposed afterEvent
1117 None, # Proposed justplay
1118 path, # Proposed dirname
1119 tags # Proposed tags
1122 def importerCallback(ret):
1126 session.openWithCallback(
1132 # Remove instance if not running in background
1133 if not config.plugins.autotimer.autopoll.value:
1134 from plugin import autotimer
1137 def editorCallback(ret):
1139 from plugin import autotimer
1141 # Create instance if needed (should have been created by addAutotimerFrom* above though)
1142 if autotimer is None:
1143 from AutoTimer import AutoTimer
1144 autotimer = AutoTimer()
1150 autotimer.writeXml()
1152 # Remove instance if not running in background
1153 if not config.plugins.autotimer.autopoll.value: