add ability to enable/disable "change to next/prev bouquet when quickzap is used...
[enigma2.git] / lib / python / Screens / EpgSelection.py
index 4d288b0047ec8a6fb0aab1b5cb86aa20fe520723..c8db81b33ba4ed8662f5f2409f013a9add88ff10 100644 (file)
 from Screen import Screen
 from Components.Button import Button
-from Components.EpgList import EPGList
+from Components.Pixmap import Pixmap
+from Components.Label import Label
+from Components.EpgList import *
 from Components.ActionMap import ActionMap
-from Screens.EventView import EventView
+from Components.ScrollLabel import ScrollLabel
+from Screens.EventView import EventViewSimple
 from enigma import eServiceReference, eServiceEventPtr
 from Screens.FixedMenu import FixedMenu
 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
 
 import xml.dom.minidom
 
 class EPGSelection(Screen):
-       def __init__(self, session, root):
+       def __init__(self, session, service, zapFunc=None):
                Screen.__init__(self, session)
+               self["key_red"] = Button("")
+               self.closeRecursive = False
+               if isinstance(service, eServiceReference):
+                       self.type = EPG_TYPE_SINGLE
+                       self["key_yellow"] = Button()
+                       self["key_blue"] = Button()
+                       self.currentService=ServiceReference(service)
+               else:
+                       self.skinName = "EPGSelectionMulti"
+                       self.type = EPG_TYPE_MULTI
+                       self["key_yellow"] = Button(_("Prev"))
+                       self["key_blue"] = Button(_("Next"))
+                       self["now_button"] = Pixmap()
+                       self["next_button"] = Pixmap()
+                       self["more_button"] = Pixmap()
+                       self["now_button_sel"] = Pixmap()
+                       self["next_button_sel"] = Pixmap()
+                       self["more_button_sel"] = Pixmap()
+                       self["now_text"] = Label()
+                       self["next_text"] = Label()
+                       self["more_text"] = Label()
+                       self["date"] = Label()
+                       self.services = service
+                       self.zapFunc = zapFunc
 
-               self["list"] = EPGList()
+               self["key_green"] = Button(_("Add timer"))
+               self["list"] = EPGList(self.type, self.onSelectionChanged)
 
                class ChannelActionMap(ActionMap):
                        def action(self, contexts, action):
-                                       ActionMap.action(self, contexts, action)
-                                       
-               self["key_red"] = Button("")
-               self["key_green"] = Button(_("Add timer"))
-               self["key_yellow"] = Button("")
-               self["key_blue"] = Button("")
+                               ActionMap.action(self, contexts, action)
 
-               self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"], 
+               self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
                        {
-                               "cancel": self.close,
+                               "cancel": self.closeScreen,
                                "ok": self.eventSelected,
-                               "timerAdd": self.timerAdd
+                               "timerAdd": self.timerAdd,
+                               "yellow": self.yellowButtonPressed,
+                               "blue": self.blueButtonPressed,
+                               "info": self.infoKeyPressed,
+                               "zapTo": self.zapTo
                        })
                self["actions"].csel = self
-               self.setRoot(root)
 
-       def eventViewCallback(self, setEvent, val):
+               self.onLayoutFinish.append(self.onCreate)
+
+       def closeScreen(self):
+               self.close(self.closeRecursive or self.type == EPG_TYPE_SINGLE)
+
+       def infoKeyPressed(self):
+               if self.type == EPG_TYPE_MULTI:
+                       cur = self["list"].getCurrent()
+                       event = cur[0]
+                       service = cur[1]
+               else:
+                       event = self["list"].getCurrent()
+                       service = self.currentService
+               if event is not None:
+                       self.session.open(EventViewSimple, event, service, self.eventViewCallback)
+
+       #just used in multipeg
+       def onCreate(self):
+               l = self["list"]
+               if self.type == EPG_TYPE_MULTI:
+                       l.recalcEntrySize()
+                       l.fillMultiEPG(self.services)
+               else:
+                       if SINGLE_CPP == 0:
+                               l.recalcEntrySize()
+                       l.fillSingleEPG(self.currentService)
+
+       def eventViewCallback(self, setEvent, setService, val):
+               l = self["list"]
+               old = l.getCurrent()
                if val == -1:
                        self.moveUp()
-                       setEvent(self["list"].getCurrent())
                elif val == +1:
                        self.moveDown()
-                       setEvent(self["list"].getCurrent())
+               cur = l.getCurrent()
+               if self.type == EPG_TYPE_SINGLE:
+                       setEvent(cur)
+               else:
+                       if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
+                               self.eventViewCallback(setEvent, setService, val)
+                       else:
+                               setEvent(cur[0])
+                               setService(cur[1])
+
+       def zapTo(self): # just used in multiepg
+               if self.zapFunc != None:
+                       self.closeRecursive = True
+                       ref = self["list"].getCurrent()[1]
+                       self.zapFunc(ref.ref)
 
        def eventSelected(self):
-               event = self["list"].getCurrent()
-               self.session.open(EventView, event, self.currentService, self.eventViewCallback)
-       
+               if self.type == EPG_TYPE_SINGLE:
+                       self.infoKeyPressed()
+               else: # EPG_TYPE_MULTI
+                       self.zapTo()
+
+       def yellowButtonPressed(self):
+               if self.type == EPG_TYPE_MULTI:
+                       self["list"].updateMultiEPG(-1)
+
+       def blueButtonPressed(self):
+               if self.type == EPG_TYPE_MULTI:
+                       self["list"].updateMultiEPG(1)
+
        def timerAdd(self):
-               event = self["list"].getCurrent()
-               
+               if self.type == EPG_TYPE_SINGLE:
+                       event = self["list"].getCurrent()
+                       serviceref = self.currentService
+               else:
+                       cur = self["list"].getCurrent()
+                       event = cur[0]
+                       serviceref = cur[1]
                if event is None:
                        return
-               
-               # FIXME only works if already playing a service
-               serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
-               
                newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
                self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
-       
+
        def timerEditFinished(self, answer):
-               if (answer[0]):
+               if answer[0]:
                        self.session.nav.RecordTimer.record(answer[1])
                else:
                        print "Timeredit aborted"       
 
-       def setRoot(self, root):
-               self.currentService=ServiceReference(root)
-               self["list"].setRoot(root)
-
        def moveUp(self):
                self["list"].moveUp()
 
        def moveDown(self):
                self["list"].moveDown()
+
+       def applyButtonState(self, state):
+               if state == 1:
+                       self["now_button_sel"].showWidget()
+                       self["now_button"].hideWidget()
+               else:
+                       self["now_button"].showWidget()
+                       self["now_button_sel"].hideWidget()
+
+               if state == 2:
+                       self["next_button_sel"].showWidget()
+                       self["next_button"].hideWidget()
+               else:
+                       self["next_button"].showWidget()
+                       self["next_button_sel"].hideWidget()
+
+               if state == 3:
+                       self["more_button_sel"].showWidget()
+                       self["more_button"].hideWidget()
+               else:
+                       self["more_button"].showWidget()
+                       self["more_button_sel"].hideWidget()
+
+       def onSelectionChanged(self):
+               if self.type == EPG_TYPE_MULTI:
+                       count = self["list"].getCurrentChangeCount()
+                       if count > 1:
+                               self.applyButtonState(3)
+                       elif count > 0:
+                               self.applyButtonState(2)
+                       else:
+                               self.applyButtonState(1)
+                       days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
+                       datastr = ""
+                       event = self["list"].getCurrent()[0]
+                       if event is not None:
+                               now = time()
+                               beg = event.getBeginTime()
+                               nowTime = localtime(now)
+                               begTime = localtime(beg)
+                               if nowTime[2] != begTime[2]:
+                                       datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
+                               else:
+                                       datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
+                       self["date"].setText(datestr)