show servicename and clock in radio player
[enigma2.git] / lib / python / Screens / ChannelSelection.py
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
10 from Components.NimManager import nimmanager
11 from Components.ServiceName import ServiceName
12 from Components.Clock import Clock
13 from Components.EventInfo import EventInfo
14
15 import xml.dom.minidom
16
17 class BouquetSelector(FixedMenu):
18         def __init__(self, session, bouquets, selectedFunc):
19                 self.selectedFunc=selectedFunc
20                 entrys = [ ]
21                 for x in bouquets:
22                         entrys.append((x[0], self.bouquetSelected, x[1]))
23                 FixedMenu.__init__(self, session, "Bouquetlist", entrys)
24                 self.skinName = "Menu"
25
26         def bouquetSelected(self):
27                 self.selectedFunc(self["menu"].getCurrent()[2])
28
29 class ChannelContextMenu(FixedMenu):
30         def __init__(self, session, csel):
31                 self.csel = csel
32
33                 menu = [ ]
34
35                 inBouquetRootList = csel.servicelist.getRoot().getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
36                 inBouquet = csel.getMutableList() is not None
37                 haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
38
39                 if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
40                         if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
41                                 if haveBouquets:
42                                         menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
43                                 else:
44                                         menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
45                         if inBouquet:
46                                 menu.append((_("remove service"), self.removeCurrentService))
47
48                 if inBouquet: # current list is editable?
49                         if not csel.bouquet_mark_edit:
50                                 if not csel.movemode:
51                                         menu.append((_("enable move mode"), self.toggleMoveMode))
52                                         if not inBouquetRootList:
53                                                 if haveBouquets:
54                                                         menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
55                                                 else:
56                                                         menu.append((_("enable favourite edit"), self.bouquetMarkStart))
57                                 else:
58                                         menu.append((_("disable move mode"), self.toggleMoveMode))
59                         elif not inBouquetRootList:
60                                 if haveBouquets:
61                                         menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
62                                         menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
63                                 else:
64                                         menu.append((_("end favourites edit"), self.bouquetMarkEnd))
65                                         menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
66
67                 menu.append((_("back"), self.close))
68
69                 FixedMenu.__init__(self, session, _("Channel Selection"), menu)
70                 self.skinName = "Menu"
71
72         def addServiceToBouquetSelected(self):
73                 bouquets = self.csel.getBouquetList()
74                 if bouquets is None:
75                         cnt = 0
76                 else:
77                         cnt = len(bouquets)
78                 if cnt > 1: # show bouquet list
79                         self.session.open(BouquetSelector, bouquets, self.addCurrentServiceToBouquet)
80                 elif cnt == 1: # add to only one existing bouquet
81                         self.addCurrentServiceToBouquet(bouquets[0][1])
82                 else: #no bouquets in root.. so assume only one favourite list is used
83                         self.addCurrentServiceToBouquet(self.csel.bouquet_root)
84
85         def addCurrentServiceToBouquet(self, dest):
86                 self.csel.addCurrentServiceToBouquet(dest)
87                 self.close()
88
89         def removeCurrentService(self):
90                 self.csel.removeCurrentService()
91                 self.close()
92
93         def toggleMoveMode(self):
94                 self.csel.toggleMoveMode()
95                 self.close()
96
97         def bouquetMarkStart(self):
98                 self.csel.startMarkedEdit()
99                 self.close()
100
101         def bouquetMarkEnd(self):
102                 self.csel.endMarkedEdit(abort=False)
103                 self.close()
104
105         def bouquetMarkAbort(self):
106                 self.csel.endMarkedEdit(abort=True)
107                 self.close()
108
109 class ChannelSelectionEdit:
110         def __init__(self):
111                 self.entry_marked = False
112                 self.movemode = False
113                 self.bouquet_mark_edit = False
114                 self.mutableList = None
115                 self.__marked = [ ]
116                 self.saved_title = None
117                 self.saved_root = None
118
119         def getMutableList(self, root=eServiceReference()):
120                 if not self.mutableList is None:
121                         return self.mutableList
122                 serviceHandler = eServiceCenter.getInstance()
123                 if not root.valid():
124                         root=self.servicelist.getRoot()
125                 list = serviceHandler.list(root)
126                 if list is not None:
127                         return list.startEdit()
128                 return None
129
130 #  multiple marked entry stuff ( edit mode, later multiepg selection )
131         def startMarkedEdit(self):
132                 self.mutableList = self.getMutableList()
133                 # add all services from the current list to internal marked set in listboxservicecontent
134                 self.bouquetRoot = self.servicelist.getRoot()
135                 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
136                 self.saved_title = self.instance.getTitle()
137                 new_title = self.saved_title
138                 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
139                         new_title += ' ' + _("[bouquet edit]")
140                 else:
141                         new_title += ' ' + _("[favourite edit]")
142                 self.instance.setTitle(new_title)
143                 self.bouquet_mark_edit = True
144                 self.__marked = self.servicelist.getRootServices()
145                 for x in self.__marked:
146                         self.servicelist.addMarked(eServiceReference(x))
147                 self.saved_root = self.getRoot()
148                 self.showAllServices()
149
150         def endMarkedEdit(self, abort):
151                 if not abort and self.mutableList is not None:
152                         new_marked = set(self.servicelist.getMarked())
153                         old_marked = set(self.__marked)
154                         removed = old_marked - new_marked
155                         added = new_marked - old_marked
156                         changed = False
157                         for x in removed:
158                                 changed = True
159                                 self.mutableList.removeService(eServiceReference(x))
160                         for x in added:
161                                 changed = True
162                                 self.mutableList.addService(eServiceReference(x))
163                         if changed:
164                                 self.mutableList.flushChanges()
165                 self.__marked = []
166                 self.clearMarks()
167                 self.bouquet_mark_edit = False
168                 self.bouquetRoot = None
169                 self.mutableList = None
170                 self.instance.setTitle(self.saved_title)
171                 self.saved_title = None
172                 self.setRoot(self.saved_root)
173
174         def clearMarks(self):
175                 self.servicelist.clearMarks()
176
177         def doMark(self):
178                 ref = self.servicelist.getCurrent()
179                 if self.servicelist.isMarked(ref):
180                         self.servicelist.removeMarked(ref)
181                 else:
182                         self.servicelist.addMarked(ref)
183
184         def removeCurrentService(self):
185                 ref = self.servicelist.getCurrent()
186                 mutableList = self.getMutableList()
187                 if ref.valid() and mutableList is not None:
188                         if not mutableList.removeService(ref):
189                                 currentIndex = self.servicelist.getCurrentIndex()
190                                 self.servicelist.moveDown()
191                                 if self.servicelist.getCurrentIndex() == currentIndex:
192                                         currentIndex -= 1
193                                 mutableList.flushChanges() #FIXME dont flush on each single removed service
194                                 self.setRoot(self.servicelist.getRoot())
195                                 self.servicelist.moveToIndex(currentIndex)
196
197         def addCurrentServiceToBouquet(self, dest):
198                 mutableList = self.getMutableList(dest)
199                 if not mutableList is None:
200                         if not mutableList.addService(self.servicelist.getCurrent()):
201                                 mutableList.flushChanges()
202                 self.close()
203
204         def toggleMoveMode(self):
205                 if self.movemode:
206                         if self.entry_marked:
207                                 self.toggleMoveMarked() # unmark current entry
208                         self.movemode = False
209                         self.mutableList.flushChanges() # FIXME add check if changes was made
210                         self.mutableList = None
211                         self.instance.setTitle(self.saved_title)
212                         self.saved_title = None
213                 else:
214                         self.mutableList = self.getMutableList()
215                         self.movemode = True
216                         self.saved_title = self.instance.getTitle()
217                         new_title = self.saved_title
218                         new_title += ' ' + _("[move mode]");
219                         self.instance.setTitle(new_title);
220
221         def handleEditCancel(self):
222                 if self.movemode: #movemode active?
223                         self.channelSelected() # unmark
224                         self.toggleMoveMode() # disable move mode
225                 elif self.bouquet_mark_edit:
226                         self.endMarkedEdit(True) # abort edit mode
227
228         def toggleMoveMarked(self):
229                 if self.entry_marked:
230                         self.servicelist.setCurrentMarked(False)
231                         self.entry_marked = False
232                 else:
233                         self.servicelist.setCurrentMarked(True)
234                         self.entry_marked = True
235
236         def doContext(self):
237                 self.session.open(ChannelContextMenu, self)
238
239 USE_MULTIBOUQUETS = False
240
241 MODE_TV = 0
242 MODE_RADIO = 1
243
244 class ChannelSelectionBase(Screen):
245         def __init__(self, session):
246                 Screen.__init__(self, session)
247
248                 # this makes it much simple to implement a selectable radio or tv mode :)
249                 self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17)'
250                 self.service_types_radio = '1:7:1:0:0:0:0:0:0:0:(type == 2)'
251
252                 self["key_red"] = Button(_("All"))
253                 self["key_green"] = Button(_("Satellites"))
254                 self["key_yellow"] = Button(_("Provider"))
255                 self["key_blue"] = Button(_("Favourites"))
256
257                 self["list"] = ServiceList()
258                 self.servicelist = self["list"]
259
260                 self.numericalTextInput = NumericalTextInput()
261
262         def appendDVBTypes(self, ref):
263                 path = ref.getPath()
264                 pos = path.find(' FROM BOUQUET')
265                 if pos != -1:
266                         return eServiceReference(self.service_types + path[pos:])
267                 return ref
268
269         def getBouquetNumOffset(self, bouquet):
270                 bouquet = self.appendDVBTypes(bouquet)
271                 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
272                         return 0
273                 offsetCount = 0
274                 serviceHandler = eServiceCenter.getInstance()
275                 bouquetlist = serviceHandler.list(self.bouquet_root)
276                 if not bouquetlist is None:
277                         while True:
278                                 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
279                                 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
280                                         break
281                                 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
282                                         continue
283                                 servicelist = serviceHandler.list(bouquetIterator)
284                                 if not servicelist is None:
285                                         while True:
286                                                 serviceIterator = servicelist.getNext()
287                                                 if not serviceIterator.valid(): #check if end of list
288                                                         break
289                                                 if serviceIterator.flags: #playable services have no flags
290                                                         continue
291                                                 offsetCount += 1
292                 return offsetCount
293
294         def setTvMode(self):
295                 self.service_types = self.service_types_tv
296                 if USE_MULTIBOUQUETS:
297                         self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
298                 else:
299                         self.bouquet_root = eServiceReference('%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types))
300                 title = self.instance.getTitle()
301                 pos = title.find(" (")
302                 if pos != -1:
303                         title = title[:pos]
304                 title += " (TV)"
305                 self.instance.setTitle(title)
306                 self.mode = MODE_TV
307
308         def setRadioMode(self):
309                 self.service_types = self.service_types_radio
310                 if USE_MULTIBOUQUETS:
311                         self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet')
312                 else:
313                         self.bouquet_root = eServiceReference('%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types))
314                 title = self.instance.getTitle()
315                 pos = title.find(" (")
316                 if pos != -1:
317                         title = title[:pos]
318                 title += " (Radio)"
319                 self.instance.setTitle(title)
320                 self.mode = MODE_RADIO
321
322         def setRootBase(self, root, justSet=False):
323                 path = root.getPath()
324                 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
325                 pos = path.find(' FROM BOUQUET')
326                 isBouquet = pos != -1
327                 if not inBouquetRootList and isBouquet:
328                         self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
329                         self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
330                         refstr = self.service_types + path[pos:]
331                         root = eServiceReference(refstr)
332                 else:
333                         self.servicelist.setMode(ServiceList.MODE_NORMAL)
334                 self.servicelist.setRoot(root, justSet)
335
336         def moveUp(self):
337                 self.servicelist.moveUp()
338
339         def moveDown(self):
340                 self.servicelist.moveDown()
341
342         def showAllServices(self):
343                 ref = eServiceReference('%s ORDER BY name'%(self.service_types))
344                 self.setRoot(ref)
345
346         def showSatellites(self):
347                 ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
348                 self.setRoot(ref, True)
349                 serviceHandler = eServiceCenter.getInstance()
350                 servicelist = serviceHandler.list(ref)
351                 if not servicelist is None:
352                         while True:
353                                 service = servicelist.getNext()
354                                 if not service.valid(): #check if end of list
355                                         break
356                                 orbpos = service.getData(4) >> 16
357                                 if service.getPath().find("FROM PROVIDER") != -1:
358                                         service_name = _("Providers")
359                                 else:
360                                         service_name = _("Services")
361                                 try:
362                                         service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
363                                         service.setName(service_name) # why we need this cast?
364                                 except:
365                                         if orbpos > 1800: # west
366                                                 service.setName("%s (%3.1f" + _("W") + ")" %(str, (0 - (orbpos - 3600)) / 10.0))
367                                         else:
368                                                 service.setName("%s (%3.1f" + _("E") + ")" % (str, orbpos / 10.0))
369                                 self.servicelist.addService(service)
370                 self.servicelist.finishFill()
371
372         def showProviders(self):
373                 ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
374                 self.setRoot(ref)
375
376         def showFavourites(self):
377                 self.setRoot(self.bouquet_root)
378
379         def keyNumberGlobal(self, number):
380                 char = self.numericalTextInput.getKey(number)
381                 print "You pressed number " + str(number)
382                 print "You would go to character " + str(char)
383                 self.servicelist.moveToChar(char)
384
385         def enterBouquet(self, action):
386                 if action[:7] == "bouquet":
387                         if action.find("FROM BOUQUET") != -1:
388                                 self.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
389                         else:
390                                 self.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
391                         return True
392                 return False
393
394         def getRoot(self):
395                 return self.servicelist.getRoot()
396
397         def getCurrentSelection(self):
398                 return self.servicelist.getCurrent()
399
400         def setCurrentSelection(self, service):
401                 self.servicelist.setCurrent(service)
402
403         def cancel(self):
404                 self.close(None)
405
406         def getBouquetList(self):
407                 serviceCount=0
408                 bouquets = [ ]
409                 serviceHandler = eServiceCenter.getInstance()
410                 list = serviceHandler.list(self.bouquet_root)
411                 if not list is None:
412                         while True:
413                                 s = list.getNext()
414                                 if not s.valid():
415                                         break
416                                 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
417                                         info = serviceHandler.info(s)
418                                         if not info is None:
419                                                 bouquets.append((info.getName(s), s))
420                                 else:
421                                         serviceCount += 1
422                         if len(bouquets) == 0 and serviceCount > 0:
423                                 info = serviceHandler.info(self.bouquet_root)
424                                 if not info is None:
425                                         bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
426                         return bouquets
427                 return None
428
429 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
430         def __init__(self, session):
431                 ChannelSelectionBase.__init__(self,session)
432                 ChannelSelectionEdit.__init__(self)
433
434                 #config for lastservice
435                 config.tv = ConfigSubsection();
436                 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
437                 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
438
439                 class ChannelActionMap(NumberActionMap):
440                         def action(self, contexts, action):
441                                 if not self.csel.enterBouquet(action):
442                                         if action == "cancel":
443                                                 self.csel.handleEditCancel()
444                                         NumberActionMap.action(self, contexts, action)
445                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
446                         {
447                                 "cancel": self.cancel,
448                                 "ok": self.channelSelected,
449                                 "mark": self.doMark,
450                                 "contextMenu": self.doContext,
451                                 "showFavourites": self.showFavourites,
452                                 "showAllServices": self.showAllServices,
453                                 "showProviders": self.showProviders,
454                                 "showSatellites": self.showSatellites,
455                                 "showEPGList": self.showEPGList,
456                                 "1": self.keyNumberGlobal,
457                                 "2": self.keyNumberGlobal,
458                                 "3": self.keyNumberGlobal,
459                                 "4": self.keyNumberGlobal,
460                                 "5": self.keyNumberGlobal,
461                                 "6": self.keyNumberGlobal,
462                                 "7": self.keyNumberGlobal,
463                                 "8": self.keyNumberGlobal,
464                                 "9": self.keyNumberGlobal,
465                                 "0": self.keyNumberGlobal
466                         })
467                 self["actions"].csel = self
468                 self.onShown.append(self.onShow)
469
470                 self.lastChannelRootTimer = eTimer()
471                 self.lastChannelRootTimer.timeout.get().append(self.onCreate)
472                 self.lastChannelRootTimer.start(100,True)
473
474         def onCreate(self):
475                 self.setTvMode()
476                 lastroot=eServiceReference(config.tv.lastroot.value)
477                 if lastroot.valid():
478                         self.setRoot(lastroot)
479                 else:
480                         self.showFavourites()
481                         self.saveRoot(self.getRoot())
482
483                 lastservice=eServiceReference(config.tv.lastservice.value)
484                 if lastservice.valid():
485                         self.servicelist.setCurrent(lastservice)
486                         self.session.nav.playService(lastservice)
487
488         def onShow(self):
489                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
490                 if ref is not None and ref.valid() and ref.getPath() == "":
491                         self.servicelist.setPlayableIgnoreService(ref)
492                 else:
493                         self.servicelist.setPlayableIgnoreService(eServiceReference())
494
495         def showEPGList(self):
496                 ref=self.getCurrentSelection()
497                 ptr=eEPGCache.getInstance()
498                 if ptr.startTimeQuery(ref) != -1:
499                         self.session.open(EPGSelection, ref)
500                 else:
501                         print 'no epg for service', ref.toString()
502
503         def channelSelected(self):
504                 ref = self.getCurrentSelection()
505                 if self.movemode:
506                         self.toggleMoveMarked()
507                 elif (ref.flags & 7) == 7:
508                         self.setRoot(ref)
509                 elif self.bouquet_mark_edit:
510                         self.doMark()
511                 else:
512                         self.zap()
513                         self.close(ref)
514
515         def setRoot(self, root, justSet=False):
516                 if not self.movemode:
517                         self.setRootBase(root, justSet)
518
519         #called from infoBar and channelSelected
520         def zap(self):
521                 self.session.nav.playService(self.getCurrentSelection())
522                 self.saveRoot(self.getRoot())
523                 self.saveChannel()
524
525         def saveRoot(self, root):
526                 if root is not None:
527                         config.tv.lastroot.value = root.toString()
528                         config.tv.lastroot.save()
529
530         def saveChannel(self):
531                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
532                 if ref is not None:
533                         refstr = ref.toString()
534                 else:
535                         refstr = ""
536                 config.tv.lastservice.value = refstr
537                 config.tv.lastservice.save()
538
539         def cancel(self):
540                 self.close(None)
541                 lastroot=eServiceReference(config.tv.lastroot.value)
542                 lastservice=eServiceReference(config.tv.lastservice.value)
543                 if lastroot.valid() and self.getRoot() != lastroot:
544                         self.setRoot(lastroot)
545                 if lastservice.valid() and self.getCurrentSelection() != lastservice:
546                         self.servicelist.setCurrent(lastservice)
547
548 class ServiceInfoWindow(Screen):
549         def __init__(self, session):
550                 Screen.__init__(self, session)
551                 self["Service_Name"] = ServiceName(self.session.nav)
552                 self["Clock"] = Clock()
553                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
554                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
555                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
556                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
557                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
558                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
559
560 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit):
561         def __init__(self, session):
562                 ChannelSelectionBase.__init__(self, session)
563                 ChannelSelectionEdit.__init__(self)
564
565                 config.radio = ConfigSubsection();
566                 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
567                 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
568                 self.onLayoutFinish.append(self.onCreate)
569
570                 self.info = session.instantiateDialog(ServiceInfoWindow)
571
572                 class ChannelActionMap(NumberActionMap):
573                         def action(self, contexts, action):
574                                 if not self.csel.enterBouquet(action):
575                                         NumberActionMap.action(self, contexts, action)
576                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions", "TvRadioActions"],
577                         {
578                                 "keyTV": self.closeRadio,
579                                 "keyRadio": self.closeRadio,
580                                 "contextMenu": self.doContext,
581                                 "cancel": self.closeRadio,
582                                 "ok": self.channelSelected,
583                                 "showFavourites": self.showFavourites,
584                                 "showAllServices": self.showAllServices,
585                                 "showProviders": self.showProviders,
586                                 "showSatellites": self.showSatellites,
587                                 "1": self.keyNumberGlobal,
588                                 "2": self.keyNumberGlobal,
589                                 "3": self.keyNumberGlobal,
590                                 "4": self.keyNumberGlobal,
591                                 "5": self.keyNumberGlobal,
592                                 "6": self.keyNumberGlobal,
593                                 "7": self.keyNumberGlobal,
594                                 "8": self.keyNumberGlobal,
595                                 "9": self.keyNumberGlobal,
596                                 "0": self.keyNumberGlobal
597                         })
598                 self["actions"].csel = self
599
600         def onCreate(self):
601                 self.setRadioMode()
602                 lastroot=eServiceReference(config.radio.lastroot.value)
603                 if lastroot.valid():
604                         self.setRoot(lastroot)
605                 else:
606                         self.showFavourites()
607                         self.saveRoot(self.getRoot())
608                 lastservice=eServiceReference(config.radio.lastservice.value)
609                 if lastservice.valid():
610                         self.servicelist.setCurrent(lastservice)
611                         self.session.nav.playService(lastservice)
612                         self.servicelist.setPlayableIgnoreService(lastservice)
613                 self.info.instance.show()
614
615         def channelSelected(self): # just return selected service
616                 ref = self.getCurrentSelection()
617                 if self.movemode:
618                         self.toggleMoveMarked()
619                 elif (ref.flags & 7) == 7:
620                         self.setRoot(ref)
621                 elif self.bouquet_mark_edit:
622                         self.doMark()
623                 else:
624                         self.session.nav.playService(ref)
625                         self.servicelist.setPlayableIgnoreService(ref)
626                         config.radio.lastservice.value = ref.toString()
627                         config.radio.lastservice.save()
628                         config.radio.lastroot.value = self.getRoot().toString()
629                         config.radio.lastroot.save()
630                 
631         def setRoot(self, root, justSet=False):
632                 self.setRootBase(root, justSet)
633
634         def closeRadio(self):
635                 self.info.instance.hide()
636                 #set previous tv service
637                 lastservice=eServiceReference(config.tv.lastservice.value)
638                 self.session.nav.playService(lastservice)
639                 self.close(None)
640
641 class SimpleChannelSelection(ChannelSelectionBase):
642         def __init__(self, session, title):
643                 ChannelSelectionBase.__init__(self, session)
644                 self.title = title
645                 self.onShown.append(self.onExecCallback)
646
647                 class ChannelActionMap(NumberActionMap):
648                         def action(self, contexts, action):
649                                 if not self.csel.enterBouquet(action):
650                                         NumberActionMap.action(self, contexts, action)
651                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions", "TvRadioActions"],
652                         {
653                                 "cancel": self.cancel,
654                                 "ok": self.channelSelected,
655                                 "showFavourites": self.showFavourites,
656                                 "showAllServices": self.showAllServices,
657                                 "showProviders": self.showProviders,
658                                 "showSatellites": self.showSatellites,
659                                 "keyRadio": self.setModeRadio,
660                                 "keyTV": self.setModeTv,
661                                 "1": self.keyNumberGlobal,
662                                 "2": self.keyNumberGlobal,
663                                 "3": self.keyNumberGlobal,
664                                 "4": self.keyNumberGlobal,
665                                 "5": self.keyNumberGlobal,
666                                 "6": self.keyNumberGlobal,
667                                 "7": self.keyNumberGlobal,
668                                 "8": self.keyNumberGlobal,
669                                 "9": self.keyNumberGlobal,
670                                 "0": self.keyNumberGlobal
671                         })
672                 self["actions"].csel = self
673
674         def onExecCallback(self):
675                 self.session.currentDialog.instance.setTitle(self.title)
676                 self.setModeTv()
677
678         def channelSelected(self): # just return selected service
679                 ref = self.getCurrentSelection()
680                 if (ref.flags & 7) == 7:
681                         self.setRoot(ref)
682                 else:
683                         ref = self.getCurrentSelection()
684                         self.close(ref)
685
686         def setRoot(self, root, justSet=False):
687                 self.setRootBase(root, justSet)
688
689         def setModeTv(self):
690                 self.setTvMode()
691                 self.showFavourites()
692
693         def setModeRadio(self):
694                 self.setRadioMode()
695                 self.showFavourites()