add webbouqueteditor (dmm plugin contest winner plugin)
[enigma2-plugins.git] / webbouqueteditor / src / WebComponents / Sources / ServiceList.py
1 from Components.Sources.Source import Source
2 from enigma import eServiceCenter, eServiceReference
3 from Components.ParentalControl import parentalControl, IMG_WHITESERVICE, IMG_WHITEBOUQUET, IMG_BLACKSERVICE, IMG_BLACKBOUQUET
4 from Components.config import config
5
6 class ServiceList(Source):
7         def __init__(self, root, command_func = None, validate_commands = True):
8                 Source.__init__(self)
9                 self.root = root
10                 self.command_func = command_func
11                 self.validate_commands = validate_commands
12
13         def getServicesAsList(self, format = "RN"):
14                 services = self.getServiceList()
15                 mylist = services and services.getContent(format, True)
16                 list = []
17                 for item in mylist:
18                         if item[0].flags & eServiceReference.isGroup:
19                                 isGroup = "1"
20                         else:
21                                 isGroup = "0"
22                         if item[0].flags & eServiceReference.isMarker:
23                                 isMarker = "1"
24                         else:
25                                 isMarker = "0"
26                         isProtected = "0"
27                         if config.ParentalControl.configured.value:
28                                 protection = parentalControl.getProtectionType(item[0].toCompareString())
29                                 if protection[0]:
30                                         if protection[1] == IMG_BLACKSERVICE:
31                                                 #(locked -S-)
32                                                 isProtected = "1"
33                                         elif protection[1] == IMG_BLACKBOUQUET:
34                                                 #(locked -B-)
35                                                 isProtected = "2"
36                                         elif protection[1] == "":
37                                                 # (locked)
38                                                 isProtected = "3"
39                                 else:
40                                         if protection[1] == IMG_WHITESERVICE:
41                                                 #(unlocked -S-)
42                                                 isProtected = "4"
43                                         elif protection[1] == IMG_WHITEBOUQUET:
44                                                 #(unlocked -B-)
45                                                 isProtected = "5"
46                                         
47                         list.append((item[0].toString(),item[1],isGroup,isMarker,isProtected))
48                 return list
49
50         def getServiceList(self):
51                 serviceHandler = eServiceCenter.getInstance()
52                 return serviceHandler.list(self.root)
53                 
54         def getRoot(self):
55                 return self.__root
56
57         def setRoot(self, root):
58                 assert isinstance(root, eServiceReference)
59                 self.__root = root
60                 self.changed()
61                 
62         root = property(getRoot, setRoot)
63
64         def validateReference(self, ref):
65                 return ref in self.getServicesAsList("S")
66
67         def handleCommand(self, cmd):
68                 print "ServiceList handle command"
69                 if self.validate_commands and not self.validateReference(cmd):
70                         print "Service reference did not validate!"
71                         return
72                 ref = eServiceReference(cmd)
73                 if self.command_func:
74                         self.command_func(ref)
75
76         list = property(getServicesAsList)
77         lut = {"Reference": 0, "Name": 1, "isGroup": 2, "isMarker": 3, "isProtected": 4}