add timeroverlap detection made by adenin (thanks for the great work!)
[enigma2.git] / lib / python / Screens / EpgSelection.py
index ba49f3147ba5eecae70949485bdc9e661c45b0bc..6740bfb6d6ea0da297f3834d5556708e9149c18a 100644 (file)
@@ -1,22 +1,20 @@
 from Screen import Screen
+from Components.config import config, ConfigClock
 from Components.Button import Button
 from Components.Pixmap import Pixmap
 from Components.Label import Label
-from Components.EpgList import *
+from Components.EpgList import EPGList, EPG_TYPE_SINGLE, EPG_TYPE_SIMILAR, EPG_TYPE_MULTI
 from Components.ActionMap import ActionMap
-from Components.ScrollLabel import ScrollLabel
+from Screens.TimerEdit import TimerSanityConflict
 from Screens.EventView import EventViewSimple
 from TimeDateInput import TimeDateInput
-from enigma import eServiceReference, eServiceEventPtr
-from Screens.FixedMenu import FixedMenu
+from enigma import eServiceReference
 from RecordTimer import RecordTimerEntry, parseEvent
-from TimerEdit import TimerEditList
 from TimerEntry import TimerEntry
 from ServiceReference import ServiceReference
-from Components.config import config, currentConfigSelectionElement
 from time import localtime, time
 
-import xml.dom.minidom
+mepg_config_initialized = False
 
 class EPGSelection(Screen):
        def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
@@ -39,6 +37,8 @@ class EPGSelection(Screen):
                        self["key_blue"] = Button()
                        self.currentService=ServiceReference(service)
                        self.zapFunc = None
+                       self.sort_type = 0
+                       self.setSortDescription()
                else:
                        self.skinName = "EPGSelectionMulti"
                        self.type = EPG_TYPE_MULTI
@@ -60,11 +60,7 @@ class EPGSelection(Screen):
                self["key_green"] = Button(_("Add timer"))
                self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
 
-               class ChannelActionMap(ActionMap):
-                       def action(self, contexts, action):
-                               return ActionMap.action(self, contexts, action)
-
-               self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
+               self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
                        {
                                "cancel": self.closeScreen,
                                "ok": self.eventSelected,
@@ -91,7 +87,11 @@ class EPGSelection(Screen):
 
        def enterDateTime(self):
                if self.type == EPG_TYPE_MULTI:
-                       self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
+                       global mepg_config_initialized
+                       if not mepg_config_initialized:
+                               config.misc.prev_mepg_time=ConfigClock(default = time())
+                               mepg_config_initialized = True
+                       self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
 
        def onDateTimeInputClosed(self, ret):
                if len(ret) > 1:
@@ -159,6 +159,21 @@ class EPGSelection(Screen):
        def yellowButtonPressed(self):
                if self.type == EPG_TYPE_MULTI:
                        self["list"].updateMultiEPG(-1)
+               elif self.type == EPG_TYPE_SINGLE:
+                       if self.sort_type == 0:
+                               self.sort_type = 1
+                       else:
+                               self.sort_type = 0
+                       self["list"].sortSingleEPG(self.sort_type)
+                       self.setSortDescription()
+
+       def setSortDescription(self):
+               if self.sort_type == 1:
+                       # TRANSLATORS: This must fit into the header button in the EPG-List
+                       self["key_yellow"].setText(_("Sort Time"))
+               else:
+                       # TRANSLATORS: This must fit into the header button in the EPG-List
+                       self["key_yellow"].setText(_("Sort A-Z"))
 
        def blueButtonPressed(self):
                if self.type == EPG_TYPE_MULTI:
@@ -171,13 +186,25 @@ class EPGSelection(Screen):
                if event is None:
                        return
                newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
-               self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
+               self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
 
-       def timerEditFinished(self, answer):
+       def finishedAdd(self, answer):
+               print "finished add"
                if answer[0]:
-                       self.session.nav.RecordTimer.record(answer[1])
+                       entry = answer[1]
+                       simulTimerList = self.session.nav.RecordTimer.record(entry)
+                       if simulTimerList is not None:
+                               if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
+                                       simulTimerList[1].end = entry.begin - 30
+                                       self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
+                                       self.session.nav.RecordTimer.record(entry)
+                               else:
+                                       self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
                else:
-                       print "Timeredit aborted"       
+                       print "Timeredit aborted"               
+       
+       def finishSanityCorrection(self, answer):
+               self.finishedAdd(answer)
 
        def moveUp(self):
                self["list"].moveUp()