1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import NumberActionMap
5 from EpgSelection import EPGSelection
6 from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer
7 from Components.config import config, configElement, ConfigSubsection, configText
8 from Screens.FixedMenu import FixedMenu
9 from Tools.NumericalTextInput import NumericalTextInput
11 import xml.dom.minidom
13 class BouquetSelector(FixedMenu):
14 def __init__(self, session, bouquets, parent):
18 entrys.append((x[0], self.bouquetSelected, x[1]))
19 FixedMenu.__init__(self, session, "Bouquetlist", entrys)
20 self.skinName = "Menu"
22 def bouquetSelected(self):
23 self.parent.addCurrentServiceToBouquet(self["menu"].getCurrent()[2])
26 class ChannelContextMenu(FixedMenu):
27 def __init__(self, session, csel):
32 inBouquetRootList = csel.servicelist.getRoot().toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
33 inBouquet = csel.getMutableList() is not None
35 if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
36 menu.append(("add service to bouquet", self.addServiceToBouquetSelected))
38 menu.append(("remove service", self.removeCurrentService))
40 if inBouquet: # current list is editable?
41 if not csel.bouquet_mark_edit:
43 menu.append(("enable move mode", self.toggleMoveMode))
44 if not inBouquetRootList:
45 menu.append(("enable bouquet edit", self.bouquetMarkStart))
47 menu.append(("disable move mode", self.toggleMoveMode))
48 elif not inBouquetRootList:
49 menu.append(("end bouquet edit", self.bouquetMarkEnd))
50 menu.append(("abort bouquet edit", self.bouquetMarkAbort))
52 menu.append(("back", self.close))
54 FixedMenu.__init__(self, session, "Channel Selection", menu)
55 self.skinName = "Menu"
57 def addServiceToBouquetSelected(self):
59 serviceHandler = eServiceCenter.getInstance()
60 list = serviceHandler.list(self.csel.bouquet_root)
66 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
67 info = serviceHandler.info(s)
69 bouquets.append((info.getName(s), s))
71 if cnt > 1: # show bouquet list
72 self.session.open(BouquetSelector, bouquets, self)
73 elif cnt == 1: # add to only one existing bouquet
74 self.addCurrentServiceToBouquet(bouquet[0][1])
75 else: #no bouquets in root.. so assume only one favourite list is used
76 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
78 def addCurrentServiceToBouquet(self, dest):
79 self.csel.addCurrentServiceToBouquet(dest)
82 def removeCurrentService(self):
83 self.csel.removeCurrentService()
86 def toggleMoveMode(self):
87 self.csel.toggleMoveMode()
90 def bouquetMarkStart(self):
91 self.csel.startMarkedEdit()
94 def bouquetMarkEnd(self):
95 self.csel.endMarkedEdit(abort=False)
98 def bouquetMarkAbort(self):
99 self.csel.endMarkedEdit(abort=True)
102 class ChannelSelectionEdit:
104 self.entry_marked = False
105 self.movemode = False
106 self.bouquet_mark_edit = False
107 self.mutableList = None
110 def getMutableList(self, root=eServiceReference()):
111 if not self.mutableList is None:
112 return self.mutableList
113 serviceHandler = eServiceCenter.getInstance()
115 root=self.servicelist.getRoot()
116 list = serviceHandler.list(root)
118 return list.startEdit()
121 # multiple marked entry stuff ( edit mode, later multiepg selection )
122 def startMarkedEdit(self):
123 self.mutableList = self.getMutableList()
124 # add all services from the current list to internal marked set in listboxservicecontent
125 self.bouquetRoot = self.servicelist.getRoot()
126 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
127 self.bouquet_mark_edit = True
128 self.__marked = self.servicelist.getRootServices()
129 for x in self.__marked:
130 self.servicelist.addMarked(eServiceReference(x))
132 def endMarkedEdit(self, abort):
133 if not abort and self.mutableList is not None:
134 new_marked = set(self.servicelist.getMarked())
135 old_marked = set(self.__marked)
136 removed = old_marked - new_marked
137 added = new_marked - old_marked
141 self.mutableList.removeService(eServiceReference(x))
144 self.mutableList.addService(eServiceReference(x))
146 self.mutableList.flushChanges()
147 self.setRoot(self.bouquetRoot)
148 #self.showFavourites()
151 self.bouquet_mark_edit = False
152 self.bouquetRoot = None
153 self.mutableList = None
155 def clearMarks(self):
156 self.servicelist.clearMarks()
159 ref = self.servicelist.getCurrent()
160 if self.servicelist.isMarked(ref):
161 self.servicelist.removeMarked(ref)
163 self.servicelist.addMarked(ref)
165 def removeCurrentService(self):
166 ref = self.servicelist.getCurrent()
167 mutableList = self.getMutableList()
168 if ref.valid() and mutableList is not None:
169 if not mutableList.removeService(ref):
170 mutableList.flushChanges() #FIXME dont flush on each single removed service
171 self.setRoot(self.servicelist.getRoot())
173 def addCurrentServiceToBouquet(self, dest):
174 mutableList = self.getMutableList(dest)
175 if not mutableList is None:
176 if not mutableList.addService(self.servicelist.getCurrent()):
177 mutableList.flushChanges()
180 def toggleMoveMode(self):
182 if self.entry_marked:
183 self.toggleMoveMarked() # unmark current entry
184 self.movemode = False
185 self.mutableList.flushChanges() # FIXME add check if changes was made
186 self.mutableList = None
188 self.mutableList = self.getMutableList()
191 def handleEditCancel(self):
192 if self.movemode: #movemode active?
193 self.channelSelected() # unmark
194 self.toggleMoveMode() # disable move mode
195 elif self.bouquet_mark_edit:
196 self.endMarkedEdit(True) # abort edit mode
198 def toggleMoveMarked(self):
199 if self.entry_marked:
200 self.servicelist.setCurrentMarked(False)
201 self.entry_marked = False
203 self.servicelist.setCurrentMarked(True)
204 self.entry_marked = True
207 self.session.open(ChannelContextMenu, self)
209 class ChannelSelectionBase(Screen):
210 def __init__(self, session):
211 Screen.__init__(self, session)
213 #self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
214 self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet')
216 self["key_red"] = Button("All")
217 #self["key_green"] = Button("Provider")
218 #self["key_yellow"] = Button("Satellite")
219 self["key_green"] = Button("")
220 self["key_yellow"] = Button("")
221 self["key_blue"] = Button("Favourites")
223 self["list"] = ServiceList()
224 self.servicelist = self["list"]
226 #self["okbutton"] = Button("ok", [self.channelSelected])
228 self.numericalTextInput = NumericalTextInput()
230 self.lastService = None
232 self.lastServiceTimer = eTimer()
233 self.lastServiceTimer.timeout.get().append(self.lastService)
234 self.lastServiceTimer.start(100)
236 def getBouquetNumOffset(self, bouquet):
237 if self.bouquet_root.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
240 serviceHandler = eServiceCenter.getInstance()
241 bouquetlist = serviceHandler.list(self.bouquet_root)
242 if not bouquetlist is None:
244 bouquetIterator = bouquetlist.getNext()
245 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
247 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
249 servicelist = serviceHandler.list(bouquetIterator)
250 if not servicelist is None:
252 serviceIterator = servicelist.getNext()
253 if not serviceIterator.valid(): #check if end of list
255 if serviceIterator.flags: #playable services have no flags
260 def setRootBase(self, root):
261 inBouquetRootList = root.toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
262 if not inBouquetRootList and ((root.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
263 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
264 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
266 self.servicelist.setMode(ServiceList.MODE_NORMAL)
267 self.servicelist.setRoot(root)
270 self.servicelist.moveUp()
273 self.servicelist.moveDown()
275 def showFavourites(self):
276 self.setRoot(self.bouquet_root)
278 def keyNumberGlobal(self, number):
279 print "You pressed number " + str(number)
280 print "You would go to character " + str(self.numericalTextInput.getKey(number))
281 # TODO let the servicelist jump to the next entry strating with the chosen character
283 def enterBouquet(self, action):
284 if action[:7] == "bouquet":
285 if action.find("FROM BOUQUET") != -1:
286 self.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
288 self.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
293 return self.servicelist.getRoot()
295 def getCurrentSelection(self):
296 return self.servicelist.getCurrent()
298 def setCurrentSelection(self, service):
299 self.servicelist.setCurrent(service)
304 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
305 def __init__(self, session):
306 ChannelSelectionBase.__init__(self,session)
307 ChannelSelectionEdit.__init__(self)
309 #config for lastservice
310 config.tv = ConfigSubsection();
311 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
312 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
314 if config.tv.lastroot.value == "":
315 self.servicelist.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
317 self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
319 class ChannelActionMap(NumberActionMap):
320 def action(self, contexts, action):
321 if not self.csel.enterBouquet(action):
322 if action == "cancel":
323 self.csel.handleEditCancel()
324 NumberActionMap.action(self, contexts, action)
325 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
327 "cancel": self.cancel,
328 "ok": self.channelSelected,
330 "contextMenu": self.doContext,
331 "showFavourites": self.showFavourites,
332 "showEPGList": self.showEPGList,
333 "1": self.keyNumberGlobal,
334 "2": self.keyNumberGlobal,
335 "3": self.keyNumberGlobal,
336 "4": self.keyNumberGlobal,
337 "5": self.keyNumberGlobal,
338 "6": self.keyNumberGlobal,
339 "7": self.keyNumberGlobal,
340 "8": self.keyNumberGlobal,
341 "9": self.keyNumberGlobal,
342 "0": self.keyNumberGlobal
344 self["actions"].csel = self
346 def showEPGList(self):
347 ref=self.servicelist.getCurrent()
348 ptr=eEPGCache.getInstance()
349 if ptr.startTimeQuery(ref) != -1:
350 self.session.open(EPGSelection, ref)
352 print 'no epg for service', ref.toString()
354 def channelSelected(self):
355 ref = self.servicelist.getCurrent()
357 self.toggleMoveMarked()
358 elif (ref.flags & 7) == 7:
360 elif self.bouquet_mark_edit:
366 def setRoot(self, root):
367 if not self.movemode:
368 self.setRootBase(root)
370 #called from infoBar and channelSelected
372 self.session.nav.playService(self.servicelist.getCurrent())
375 def saveRoot(self, root):
377 config.tv.lastroot.value = root.toString()
378 config.tv.lastroot.save()
380 def saveChannel(self):
381 ref = self.session.nav.getCurrentlyPlayingServiceReference()
383 refstr = ref.toString()
386 config.tv.lastservice.value = refstr
387 config.tv.lastservice.save()
389 def lastService(self):
390 self.lastServiceTimer.stop()
391 #zap to last running tv service
392 self.setRoot(eServiceReference(config.tv.lastroot.value))
393 self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
395 class SimpleChannelSelection(ChannelSelectionBase):
396 def __init__(self, session, title):
397 ChannelSelectionBase.__init__(self, session)
399 self.onShown.append(self.onExecCallback)
401 class ChannelActionMap(ActionMap):
402 def action(self, contexts, action):
403 if not self.csel.enterBouquet(action):
404 ActionMap.action(self, contexts, action)
405 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
407 "cancel": self.cancel,
408 "ok": self.channelSelected,
409 "showFavourites": self.showFavourites,
410 "1": self.keyNumberGlobal,
411 "2": self.keyNumberGlobal,
412 "3": self.keyNumberGlobal,
413 "4": self.keyNumberGlobal,
414 "5": self.keyNumberGlobal,
415 "6": self.keyNumberGlobal,
416 "7": self.keyNumberGlobal,
417 "8": self.keyNumberGlobal,
418 "9": self.keyNumberGlobal,
419 "0": self.keyNumberGlobal
421 self["actions"].csel = self
423 def onExecCallback(self):
424 print "onExecCallback"
425 self.session.currentDialog.instance.setTitle(self.title)
427 def channelSelected(self): # just return selected service
428 ref = self.servicelist.getCurrent()
431 def setRoot(self, root):
432 self.setRootBase(root)