Merge branch 'master' of fraxinas@git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Components / Sources / ServiceList.py
1 from Source import Source
2 from enigma import eServiceCenter, eServiceReference
3
4 class ServiceList(Source):
5         def __init__(self, root, command_func = None, validate_commands = True):
6                 Source.__init__(self)
7                 self.root = root
8                 self.command_func = command_func
9                 self.validate_commands = validate_commands
10
11         def getServicesAsList(self, format = "SN"):
12                 services = self.getServiceList()
13                 return services and services.getContent(format, True)
14
15         def getServiceList(self):
16                 serviceHandler = eServiceCenter.getInstance()
17                 return serviceHandler.list(self.root)
18
19         def validateReference(self, ref):
20                 return ref in self.getServicesAsList("S")
21
22         list = property(getServicesAsList)
23         lut = {"Reference": 0, "Name": 1}
24
25         def getRoot(self):
26                 return self.__root
27
28         def setRoot(self, root):
29                 assert isinstance(root, eServiceReference)
30                 self.__root = root
31                 self.changed()
32                 
33         root = property(getRoot, setRoot)
34
35         def handleCommand(self, cmd):
36                 print "ServiceList handle command"
37                 
38                 if self.validate_commands and not self.validateReference(cmd):
39                         print "Service reference did not validate!"
40                         return
41
42                 ref = eServiceReference(cmd)
43                 if self.command_func:
44                         self.command_func(ref)