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_blue"] = Button("Favourites")
220 self["list"] = ServiceList()
221 self.servicelist = self["list"]
223 #self["okbutton"] = Button("ok", [self.channelSelected])
225 self.lastServiceTimer = eTimer()
226 self.lastServiceTimer.timeout.get().append(self.lastService)
227 self.lastServiceTimer.start(100)
229 def getBouquetNumOffset(self, bouquet):
230 if self.bouquet_root.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
233 serviceHandler = eServiceCenter.getInstance()
234 bouquetlist = serviceHandler.list(self.bouquet_root)
235 if not bouquetlist is None:
237 bouquetIterator = bouquetlist.getNext()
238 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
240 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
242 servicelist = serviceHandler.list(bouquetIterator)
243 if not servicelist is None:
245 serviceIterator = servicelist.getNext()
246 if not serviceIterator.valid(): #check if end of list
248 if serviceIterator.flags: #playable services have no flags
253 def setRootBase(self, root):
254 inBouquetRootList = root.toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
255 if not inBouquetRootList and ((root.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
256 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
257 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
259 self.servicelist.setMode(ServiceList.MODE_NORMAL)
260 self.servicelist.setRoot(root)
263 self.servicelist.moveUp()
266 self.servicelist.moveDown()
268 def showFavourites(self):
269 self.setRoot(self.bouquet_root)
271 def enterBouquet(self, action):
272 if action[:7] == "bouquet":
273 if action.find("FROM BOUQUET") != -1:
274 self.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
276 self.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
281 return self.servicelist.getRoot()
283 def getCurrentSelection(self):
284 return self.servicelist.getCurrent()
286 def setCurrentSelection(self, service):
287 self.servicelist.setCurrent(service)
292 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
293 def __init__(self, session):
294 ChannelSelectionBase.__init__(self,session)
295 ChannelSelectionEdit.__init__(self)
297 #config for lastservice
298 config.tv = ConfigSubsection();
299 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
300 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
302 if config.tv.lastroot.value == "":
303 self.servicelist.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
305 class ChannelActionMap(ActionMap):
306 def action(self, contexts, action):
307 if not self.csel.enterBouquet(action):
308 if action == "cancel":
309 self.csel.handleEditCancel()
310 ActionMap.action(self, contexts, action)
311 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
313 "cancel": self.cancel,
314 "ok": self.channelSelected,
316 "contextMenu": self.doContext,
317 "showFavourites": self.showFavourites,
318 "showEPGList": self.showEPGList
320 self["actions"].csel = self
322 def showEPGList(self):
323 ref=self.servicelist.getCurrent()
324 ptr=eEPGCache.getInstance()
325 if ptr.startTimeQuery(ref) != -1:
326 self.session.open(EPGSelection, ref)
328 print 'no epg for service', ref.toString()
330 def channelSelected(self):
331 ref = self.servicelist.getCurrent()
333 self.toggleMoveMarked()
334 elif (ref.flags & 7) == 7:
336 elif self.bouquet_mark_edit:
342 def setRoot(self, root):
343 if not self.movemode:
344 self.setRootBase(root)
346 #called from infoBar and channelSelected
348 self.session.nav.playService(self.servicelist.getCurrent())
351 def saveRoot(self, root):
353 config.tv.lastroot.value = root.toString()
354 config.tv.lastroot.save()
356 def saveChannel(self):
357 ref = self.session.nav.getCurrentlyPlayingServiceReference()
359 refstr = ref.toString()
362 config.tv.lastservice.value = refstr
363 config.tv.lastservice.save()
365 def lastService(self):
366 self.lastServiceTimer.stop()
367 #zap to last running tv service
368 self.setRoot(eServiceReference(config.tv.lastroot.value))
369 self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
371 class SimpleChannelSelection(ChannelSelectionBase):
372 def __init__(self, session, title):
373 ChannelSelectionBase.__init__(self, session)
375 self.onShown.append(self.onExecCallback)
377 class ChannelActionMap(ActionMap):
378 def action(self, contexts, action):
379 if not self.csel.enterBouquet(action):
380 ActionMap.action(self, contexts, action)
381 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
383 "cancel": self.cancel,
384 "ok": self.channelSelected,
385 "showFavourites": self.showFavourites,
387 self["actions"].csel = self
389 def onExecCallback(self):
390 print "onExecCallback"
391 self.session.currentDialog.instance.setTitle(self.title)
393 def channelSelected(self): # just return selected service
394 ref = self.servicelist.getCurrent()
397 def setRoot(self, root):
398 self.setRootBase(root)