service: add sort of servicelist including all required layers
[enigma2.git] / lib / python / Components / config.py
index 7bd8175a612ab35a0b837c4583fe76f4632367be..7f8f50727c166bbf50ab99a0c8e1585a5f3b6c43 100644 (file)
@@ -77,6 +77,38 @@ class configSelection:
        def __call__(self, selected):                   #needed by configlist
                self.checkValues()
                return ("text", self.parent.vals[self.parent.value])
+
+class configSatlist:
+       def __init__(self, parent):
+               self.parent = parent
+
+       def checkValues(self):
+               if self.parent.value < 0:
+                       self.parent.value = 0   
+
+               if(self.parent.value >= (len(self.parent.vals) - 1)):
+                       self.parent.value = len(self.parent.vals) - 1
+                       
+       def cancel(self):
+               self.parent.reload()
+
+       def save(self):
+               self.parent.save()
+
+       def handleKey(self, key):
+               if key == config.key["prevElement"]:
+                       self.parent.value = self.parent.value - 1
+               if key == config.key["nextElement"]:
+                       self.parent.value = self.parent.value + 1
+               
+               self.checkValues()                      
+
+               self.parent.change()    
+
+       def __call__(self, selected):                   #needed by configlist
+               self.checkValues()
+               #fixme
+               return ("text", str(self.parent.vals[self.parent.value][0]))
                
 class configSequence:
        def __init__(self, parent):
@@ -214,6 +246,20 @@ class ConfigSubsection:
                pass
 
 class configElement:
+
+       def getIndexbyEntry(self, data):
+               cnt = 0;
+               tcnt = -1; #for defaultval
+               for x in self.vals:
+                       if int(x[1]) == int(data):
+                                       return cnt
+                       if int(x[1]) == int(self.defaultValue):
+                                       tcnt = cnt
+                       cnt += 1
+               if tcnt != -1:
+                       return tcnt                     
+               return 0        #prevent bigger then array
+
        def datafromFile(self, control, data):
                if control == ConfigSlider:
                        return int(data);
@@ -225,6 +271,8 @@ class configElement:
                        for x in part:
                                list.append(int(x))
                        return list
+               elif control == configSatlist:
+                       return self.getIndexbyEntry(data)
                else: 
                        return ""       
 
@@ -242,6 +290,8 @@ class configElement:
 #                                      value += self.vals[0]
 #                              value += str(i)
                        return value
+               elif control == configSatlist:
+                       return str(self.vals[self.value][1]);
                else: 
                        return ""       
 
@@ -253,10 +303,18 @@ class configElement:
 
                if value == "":
                        print "value not found - using default"
-                       self.value = self.defaultValue
+
+                       if self.controlType == configSatlist:
+                               self.value = self.getIndexbyEntry(self.defaultValue)
+                       else:   
+                               self.value = self.defaultValue
+
                        self.save()             #add missing value to dict
                else:
                        self.value = value
+                       
+               #is this right? activate settings after load/cancel and use default     
+               self.change()
 
        def __init__(self, configPath, control, defaultValue, vals):
                self.configPath = configPath