Merge branch 'obi/master'
[enigma2.git] / lib / python / Components / ParentalControlList.py
1 from MenuList import MenuList
2 from Components.ParentalControl import IMG_WHITESERVICE, IMG_WHITEBOUQUET, IMG_BLACKSERVICE, IMG_BLACKBOUQUET
3 from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
4
5 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
6 from Tools.LoadPixmap import LoadPixmap
7
8 #Now there is a list of pictures instead of one...
9 entryPicture = {}
10
11 entryPicture[IMG_BLACKSERVICE] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock.png"))
12 entryPicture[IMG_BLACKBOUQUET] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lockBouquet.png"))
13 entryPicture[IMG_WHITESERVICE] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/unlock.png"))
14 entryPicture[IMG_WHITEBOUQUET] = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/unlockBouquet.png"))
15
16 def ParentalControlEntryComponent(service, name, protectionType):
17         locked = protectionType[0]
18         sImage = protectionType[1]
19         res = [
20                 (service, name, locked),
21                 (eListboxPythonMultiContent.TYPE_TEXT, 80, 5, 300, 50, 0, RT_HALIGN_LEFT, name)
22         ]
23         #Changed logic: The image is defined by sImage, not by locked anymore
24         if sImage != "":
25                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 0, 32, 32, entryPicture[sImage]))
26         return res
27
28 class ParentalControlList(MenuList):
29         def __init__(self, list, enableWrapAround = False):
30                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
31                 self.l.setFont(0, gFont("Regular", 20))
32                 self.l.setItemHeight(32)
33
34         def toggleSelectedLock(self):
35                 from Components.ParentalControl import parentalControl
36                 print "self.l.getCurrentSelection():", self.l.getCurrentSelection()
37                 print "self.l.getCurrentSelectionIndex():", self.l.getCurrentSelectionIndex()
38                 curSel = self.l.getCurrentSelection()
39                 if curSel[0][2]:
40                         parentalControl.unProtectService(self.l.getCurrentSelection()[0][0])
41                 else:
42                         parentalControl.protectService(self.l.getCurrentSelection()[0][0])
43                 #Instead of just negating the locked- flag, now I call the getProtectionType every time...
44                 self.list[self.l.getCurrentSelectionIndex()] = ParentalControlEntryComponent(curSel[0][0], curSel[0][1], parentalControl.getProtectionType(curSel[0][0]))
45                 self.l.setList(self.list)