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 ChannelSelection(Screen):
102 def lastService(self):
103 self.lastServiceTimer.stop()
104 #zap to last running tv service
105 self.setRoot(eServiceReference(config.tv.lastroot.value))
106 self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
108 def __init__(self, session):
109 Screen.__init__(self, session)
111 #config for lastservice
112 config.tv = ConfigSubsection();
113 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
114 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
116 self.entry_marked = False
117 self.movemode = False
118 self.bouquet_mark_edit = False
119 #self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
120 self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet')
121 self.mutableList = None
125 self["key_red"] = Button("All")
126 self["key_green"] = Button("Provider")
127 self["key_yellow"] = Button("Satellite")
128 self["key_blue"] = Button("Favourites")
130 self["list"] = ServiceList()
131 self.servicelist = self["list"]
133 if config.tv.lastroot.value == "":
134 self.servicelist.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
135 #self["okbutton"] = Button("ok", [self.channelSelected])
137 self.lastServiceTimer = eTimer()
138 self.lastServiceTimer.timeout.get().append(self.lastService)
139 self.lastServiceTimer.start(100)
141 class ChannelActionMap(ActionMap):
142 def action(self, contexts, action):
143 if action[:7] == "bouquet":
145 if action.find("FROM BOUQUET") != -1:
146 l.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
148 l.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
150 if action == "cancel":
152 if l.movemode: #movemode active?
153 l.channelSelected() # unmark
154 l.toggleMoveMode() # disable move mode
155 elif l.bouquet_mark_edit:
156 l.endMarkedEdit(True) # abort edit mode
157 ActionMap.action(self, contexts, action)
159 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
161 "cancel": self.close,
162 "ok": self.channelSelected,
164 "contextMenu": self.doContext,
165 "showFavourites": self.showFavourites,
166 "showEPGList": self.showEPGList
168 self["actions"].csel = self
170 def showEPGList(self):
171 ref=self.servicelist.getCurrent()
172 ptr=eEPGCache.getInstance()
173 if ptr.startTimeQuery(ref) != -1:
174 self.session.open(EPGSelection, ref)
176 print 'no epg for service', ref.toString()
178 def getMutableList(self, root=eServiceReference()):
179 if not self.mutableList is None:
180 return self.mutableList
181 serviceHandler = eServiceCenter.getInstance()
183 root=self.servicelist.getRoot()
184 list = serviceHandler.list(root)
186 return list.startEdit()
189 # multiple marked entry stuff ( edit mode, later multiepg selection )
190 def startMarkedEdit(self):
191 self.mutableList = self.getMutableList()
192 # add all services from the current list to internal marked set in listboxservicecontent
193 self.bouquetRoot = self.servicelist.getRoot()
194 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
195 self.bouquet_mark_edit = True
196 self.__marked = self.servicelist.getRootServices()
197 for x in self.__marked:
198 self.servicelist.addMarked(eServiceReference(x))
200 def endMarkedEdit(self, abort):
201 if not abort and self.mutableList is not None:
202 new_marked = set(self.servicelist.getMarked())
203 old_marked = set(self.__marked)
204 removed = old_marked - new_marked
205 added = new_marked - old_marked
209 self.mutableList.removeService(eServiceReference(x))
212 self.mutableList.addService(eServiceReference(x))
214 self.mutableList.flushChanges()
215 self.setRoot(self.bouquetRoot)
216 #self.showFavourites()
219 self.bouquet_mark_edit = False
220 self.bouquetRoot = None
221 self.mutableList = None
223 def clearMarks(self):
224 self.servicelist.clearMarks()
227 ref = self.servicelist.getCurrent()
228 if self.servicelist.isMarked(ref):
229 self.servicelist.removeMarked(ref)
231 self.servicelist.addMarked(ref)
233 def removeCurrentService(self):
234 ref = self.servicelist.getCurrent()
235 mutableList = self.getMutableList()
236 if ref.valid() and mutableList is not None:
237 if not mutableList.removeService(ref):
238 mutableList.flushChanges() #FIXME dont flush on each single removed service
239 self.setRoot(self.servicelist.getRoot())
241 def addCurrentServiceToBouquet(self, dest):
242 mutableList = self.getMutableList(dest)
243 if not mutableList is None:
244 if not mutableList.addService(self.servicelist.getCurrent()):
245 mutableList.flushChanges()
248 def searchNumberHelper(self, serviceHandler, num, bouquet):
249 servicelist = serviceHandler.list(bouquet)
250 if not servicelist is None:
252 serviceIterator = servicelist.getNext()
253 if not serviceIterator.valid(): #check end of list
255 if serviceIterator.flags: #assume normal dvb service have no flags set
258 if not num: #found service with searched number ?
259 return serviceIterator, 0
262 def zapToNumber(self, number):
263 bouquet = self.bouquet_root
265 serviceHandler = eServiceCenter.getInstance()
266 if bouquet.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
267 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
269 bouquetlist = serviceHandler.list(bouquet)
270 if not bouquetlist is None:
272 bouquet = bouquetlist.getNext()
273 if not bouquet.valid(): #check end of list
275 if ((bouquet.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
277 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
278 if not service is None:
279 self.session.nav.playService(service) #play service
280 if self.servicelist.getRoot() != bouquet: #already in correct bouquet?
281 self.setRoot(bouquet)
282 self.servicelist.setCurrent(service) #select the service in servicelist
284 def getBouquetNumOffset(self, bouquet):
285 if self.bouquet_root.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
288 serviceHandler = eServiceCenter.getInstance()
289 bouquetlist = serviceHandler.list(self.bouquet_root)
290 if not bouquetlist is None:
292 bouquetIterator = bouquetlist.getNext()
293 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
295 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
297 servicelist = serviceHandler.list(bouquetIterator)
298 if not servicelist is None:
300 serviceIterator = servicelist.getNext()
301 if not serviceIterator.valid(): #check if end of list
303 if serviceIterator.flags: #playable services have no flags
308 def setRoot(self, root):
309 if not self.movemode: # dont change root when movemode is enabled
310 inBouquetRootList = root.toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
311 if not inBouquetRootList and ((root.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
312 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
313 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
315 self.servicelist.setMode(ServiceList.MODE_NORMAL)
316 self.servicelist.setRoot(root)
318 def channelSelected(self):
319 ref = self.servicelist.getCurrent()
321 if self.entry_marked:
322 self.servicelist.setCurrentMarked(False)
323 self.entry_marked = False
325 self.servicelist.setCurrentMarked(True)
326 self.entry_marked = True
327 elif (ref.flags & 7) == 7:
329 elif self.bouquet_mark_edit:
332 self.session.nav.playService(ref)
338 self.session.nav.playService(self.servicelist.getCurrent())
342 self.servicelist.moveUp()
345 self.servicelist.moveDown()
348 self.session.open(ChannelContextMenu, self)
350 def toggleMoveMode(self):
352 if self.entry_marked:
353 self.channelSelected() # unmark current entry
354 self.movemode = False
355 self.mutableList.flushChanges() # FIXME add check if changes was made
356 self.mutableList = None
358 self.mutableList = self.getMutableList()
361 def showFavourites(self):
362 self.setRoot(self.bouquet_root)
364 def saveRoot(self, root):
366 config.tv.lastroot.value = root.toString()
367 config.tv.lastroot.save()
369 def saveChannel(self):
370 ref = self.session.nav.getCurrentlyPlayingServiceReference()
372 refstr = ref.toString()
375 config.tv.lastservice.value = refstr
376 config.tv.lastservice.save()