* Changed Subservice Handling a lot
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / SubServices.py
1 from Components.Sources.Source import Source
2 from ServiceReference import ServiceReference
3 from time import sleep
4
5 class SubServices(Source):
6     
7     def __init__(self, session):
8         Source.__init__(self)        
9         self.session = session
10         
11 #        self.session.nav.event.append(self.checkSubservicesAvail) # we like to get service events
12 #
13 #    def checkSubservicesAvail(self, ev):
14 #        if ev == iPlayableService.evUpdatedEventInfo:
15 #            service = self.session.nav.getCurrentService()
16 #            subservices = service and service.subServices()
17 #            if subservices or subservices.getNumberOfSubservices() == 0:
18 #                self["SubserviceQuickzapAction"].setEnabled(False)
19         
20     def command(self):
21         print "SubServices was called"
22         list = []
23         
24         #sleep(5) # FIXMEEEEE very ugly code !! 
25         
26         list0 = []
27         currentService = self.session.nav.getCurrentlyPlayingServiceReference()
28         if currentService is not None:
29             list0.append(currentService.toString())
30             list0.append( ServiceReference(currentService).getServiceName() )
31             list.append(list0)
32         else:
33             list0.append("N/A")
34             list0.append("N/A")
35             list.append(list0)
36
37         service = self.session.nav.getCurrentService()
38         subservices = service and service.subServices()
39         if subservices or subservices.getNumberOfSubservices() != 0:
40             n = subservices and subservices.getNumberOfSubservices()
41             for x in range(n):
42                 list1 = []
43                 sub = subservices.getSubservice(x)
44                 list1.append(sub.toString())
45                 list1.append(sub.getName())
46                 list.append(list1)
47         
48         print "SubServices is returning list ",list
49         return list
50         
51     list = property(command)
52     lut = {"ServiceReference": 0
53            ,"Name": 1
54            }
55