1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import ActionMap
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
10 import xml.dom.minidom
12 class BouquetSelector(FixedMenu):
13 def __init__(self, session, bouquets, parent):
17 entrys.append((x[0], self.bouquetSelected, x[1]))
18 FixedMenu.__init__(self, session, "Bouquetlist", entrys)
19 self.skinName = "Menu"
21 def bouquetSelected(self):
22 self.parent.addCurrentServiceToBouquet(self["menu"].getCurrent()[2])
25 class ChannelContextMenu(FixedMenu):
26 def __init__(self, session, csel):
31 inBouquetRootList = csel.servicelist.getRoot().toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
32 inBouquet = csel.getMutableList() is not None
34 if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
35 menu.append(("add service to bouquet", self.addServiceToBouquetSelected))
37 menu.append(("remove service", self.removeCurrentService))
39 if inBouquet: # current list is editable?
40 if not csel.bouquet_mark_edit:
42 menu.append(("enable move mode", self.toggleMoveMode))
43 if not inBouquetRootList:
44 menu.append(("enable bouquet edit", self.bouquetMarkStart))
46 menu.append(("disable move mode", self.toggleMoveMode))
47 elif not inBouquetRootList:
48 menu.append(("end bouquet edit", self.bouquetMarkEnd))
49 menu.append(("abort bouquet edit", self.bouquetMarkAbort))
51 menu.append(("back", self.close))
53 FixedMenu.__init__(self, session, "Channel Selection", menu)
54 self.skinName = "Menu"
56 def addServiceToBouquetSelected(self):
58 serviceHandler = eServiceCenter.getInstance()
59 list = serviceHandler.list(self.csel.bouquet_root)
65 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
66 info = serviceHandler.info(s)
68 bouquets.append((info.getName(s), s))
70 if cnt > 1: # show bouquet list
71 self.session.open(BouquetSelector, bouquets, self)
72 elif cnt == 1: # add to only one existing bouquet
73 self.addCurrentServiceToBouquet(bouquet[0][1])
74 else: #no bouquets in root.. so assume only one favourite list is used
75 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
77 def addCurrentServiceToBouquet(self, dest):
78 self.csel.addCurrentServiceToBouquet(dest)
81 def removeCurrentService(self):
82 self.csel.removeCurrentService()
85 def toggleMoveMode(self):
86 self.csel.toggleMoveMode()
89 def bouquetMarkStart(self):
90 self.csel.startMarkedEdit()
93 def bouquetMarkEnd(self):
94 self.csel.endMarkedEdit(abort=False)
97 def bouquetMarkAbort(self):
98 self.csel.endMarkedEdit(abort=True)
101 class ChannelSelectionEdit:
103 self.entry_marked = False
104 self.movemode = False
105 self.bouquet_mark_edit = False
106 self.mutableList = None
109 def getMutableList(self, root=eServiceReference()):
110 if not self.mutableList is None:
111 return self.mutableList
112 serviceHandler = eServiceCenter.getInstance()
114 root=self.servicelist.getRoot()
115 list = serviceHandler.list(root)
117 return list.startEdit()
120 # multiple marked entry stuff ( edit mode, later multiepg selection )
121 def startMarkedEdit(self):
122 self.mutableList = self.getMutableList()
123 # add all services from the current list to internal marked set in listboxservicecontent
124 self.bouquetRoot = self.servicelist.getRoot()
125 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
126 self.bouquet_mark_edit = True
127 self.__marked = self.servicelist.getRootServices()
128 for x in self.__marked:
129 self.servicelist.addMarked(eServiceReference(x))
131 def endMarkedEdit(self, abort):
132 if not abort and self.mutableList is not None:
133 new_marked = set(self.servicelist.getMarked())
134 old_marked = set(self.__marked)
135 removed = old_marked - new_marked
136 added = new_marked - old_marked
140 self.mutableList.removeService(eServiceReference(x))
143 self.mutableList.addService(eServiceReference(x))
145 self.mutableList.flushChanges()
146 self.setRoot(self.bouquetRoot)
147 #self.showFavourites()
150 self.bouquet_mark_edit = False
151 self.bouquetRoot = None
152 self.mutableList = None
154 def clearMarks(self):
155 self.servicelist.clearMarks()
158 ref = self.servicelist.getCurrent()
159 if self.servicelist.isMarked(ref):
160 self.servicelist.removeMarked(ref)
162 self.servicelist.addMarked(ref)
164 def removeCurrentService(self):
165 ref = self.servicelist.getCurrent()
166 mutableList = self.getMutableList()
167 if ref.valid() and mutableList is not None:
168 if not mutableList.removeService(ref):
169 mutableList.flushChanges() #FIXME dont flush on each single removed service
170 self.setRoot(self.servicelist.getRoot())
172 def addCurrentServiceToBouquet(self, dest):
173 mutableList = self.getMutableList(dest)
174 if not mutableList is None:
175 if not mutableList.addService(self.servicelist.getCurrent()):
176 mutableList.flushChanges()
179 def toggleMoveMode(self):
181 if self.entry_marked:
182 self.toggleMoveMarked() # unmark current entry
183 self.movemode = False
184 self.mutableList.flushChanges() # FIXME add check if changes was made
185 self.mutableList = None
187 self.mutableList = self.getMutableList()
190 def handleEditCancel(self):
191 if self.movemode: #movemode active?
192 self.channelSelected() # unmark
193 self.toggleMoveMode() # disable move mode
194 elif self.bouquet_mark_edit:
195 self.endMarkedEdit(True) # abort edit mode
197 def toggleMoveMarked(self):
198 if self.entry_marked:
199 self.servicelist.setCurrentMarked(False)
200 self.entry_marked = False
202 self.servicelist.setCurrentMarked(True)
203 self.entry_marked = True
206 self.session.open(ChannelContextMenu, self)
208 class ChannelSelectionBase(Screen):
209 def __init__(self, session):
210 Screen.__init__(self, session)
212 self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
213 #self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet')
215 self["key_red"] = Button("All")
216 #self["key_green"] = Button("Provider")
217 #self["key_yellow"] = Button("Satellite")
218 self["key_green"] = Button("")
219 self["key_yellow"] = Button("")
220 self["key_blue"] = Button("Favourites")
222 self["list"] = ServiceList()
223 self.servicelist = self["list"]
225 #self["okbutton"] = Button("ok", [self.channelSelected])
227 self.lastServiceTimer = eTimer()
228 self.lastServiceTimer.timeout.get().append(self.lastService)
229 self.lastServiceTimer.start(100)
231 def getBouquetNumOffset(self, bouquet):
232 if self.bouquet_root.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
235 serviceHandler = eServiceCenter.getInstance()
236 bouquetlist = serviceHandler.list(self.bouquet_root)
237 if not bouquetlist is None:
239 bouquetIterator = bouquetlist.getNext()
240 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
242 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
244 servicelist = serviceHandler.list(bouquetIterator)
245 if not servicelist is None:
247 serviceIterator = servicelist.getNext()
248 if not serviceIterator.valid(): #check if end of list
250 if serviceIterator.flags: #playable services have no flags
255 def setRootBase(self, root):
256 inBouquetRootList = root.toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
257 if not inBouquetRootList and ((root.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
258 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
259 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
261 self.servicelist.setMode(ServiceList.MODE_NORMAL)
262 self.servicelist.setRoot(root)
265 self.servicelist.moveUp()
268 self.servicelist.moveDown()
270 def showFavourites(self):
271 self.setRoot(self.bouquet_root)
273 def enterBouquet(self, action):
274 if action[:7] == "bouquet":
275 if action.find("FROM BOUQUET") != -1:
276 self.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
278 self.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
283 return self.servicelist.getRoot()
285 def getCurrentSelection(self):
286 return self.servicelist.getCurrent()
288 def setCurrentSelection(self, service):
289 self.servicelist.setCurrent(service)
294 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
295 def __init__(self, session):
296 ChannelSelectionBase.__init__(self,session)
297 ChannelSelectionEdit.__init__(self)
299 #config for lastservice
300 config.tv = ConfigSubsection();
301 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
302 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
304 if config.tv.lastroot.value == "":
305 self.servicelist.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
307 class ChannelActionMap(ActionMap):
308 def action(self, contexts, action):
309 if not self.csel.enterBouquet(action):
310 if action == "cancel":
311 self.csel.handleEditCancel()
312 ActionMap.action(self, contexts, action)
313 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
315 "cancel": self.cancel,
316 "ok": self.channelSelected,
318 "contextMenu": self.doContext,
319 "showFavourites": self.showFavourites,
320 "showEPGList": self.showEPGList
322 self["actions"].csel = self
324 def showEPGList(self):
325 ref=self.servicelist.getCurrent()
326 ptr=eEPGCache.getInstance()
327 if ptr.startTimeQuery(ref) != -1:
328 self.session.open(EPGSelection, ref)
330 print 'no epg for service', ref.toString()
332 def channelSelected(self):
333 ref = self.servicelist.getCurrent()
335 self.toggleMoveMarked()
336 elif (ref.flags & 7) == 7:
338 elif self.bouquet_mark_edit:
344 def setRoot(self, root):
345 if not self.movemode:
346 self.setRootBase(root)
348 #called from infoBar and channelSelected
350 self.session.nav.playService(self.servicelist.getCurrent())
353 def saveRoot(self, root):
355 config.tv.lastroot.value = root.toString()
356 config.tv.lastroot.save()
358 def saveChannel(self):
359 ref = self.session.nav.getCurrentlyPlayingServiceReference()
361 refstr = ref.toString()
364 config.tv.lastservice.value = refstr
365 config.tv.lastservice.save()
367 def lastService(self):
368 self.lastServiceTimer.stop()
369 #zap to last running tv service
370 self.setRoot(eServiceReference(config.tv.lastroot.value))
371 self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
373 class SimpleChannelSelection(ChannelSelectionBase):
374 def __init__(self, session, title):
375 ChannelSelectionBase.__init__(self, session)
377 self.onShown.append(self.onExecCallback)
379 class ChannelActionMap(ActionMap):
380 def action(self, contexts, action):
381 if not self.csel.enterBouquet(action):
382 ActionMap.action(self, contexts, action)
383 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
385 "cancel": self.cancel,
386 "ok": self.channelSelected,
387 "showFavourites": self.showFavourites,
389 self["actions"].csel = self
391 def onExecCallback(self):
392 print "onExecCallback"
393 self.session.currentDialog.instance.setTitle(self.title)
395 def channelSelected(self): # just return selected service
396 ref = self.servicelist.getCurrent()
399 def setRoot(self, root):
400 self.setRootBase(root)