sync
[enigma2.git] / lib / python / Components / NimManager.py
1 from config import config       #global config instance
2
3 from config import configElement
4 from config import ConfigSubsection
5 from config import ConfigSlider
6 from config import configSelection
7 from config import configSatlist
8
9 import xml.dom.minidom
10 from xml.dom import EMPTY_NAMESPACE
11 from skin import elementsWithTag
12 from Tools import XMLTools
13
14 class nimSlot:
15         def __init__(self, slotid, nimtype, name):
16                 self.slotid = slotid
17                 self.nimType = nimtype
18                 self.name = name
19
20 class NimManager:
21         def readSatsfromFile(self):
22                 self.satellites = { }
23                 #FIXME: path ok???
24                 satfile = file('/etc/tuxbox/satellites.xml', 'r')
25                 satdom = xml.dom.minidom.parseString(satfile.read())
26                 satfile.close()
27
28                 for entries in elementsWithTag(satdom.childNodes, "satellites"):
29                         for x in elementsWithTag(entries.childNodes, "sat"):
30                                 #print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
31                                 tpos = x.getAttribute('position')
32                                 tname = x.getAttribute('name')
33                                 #tname.encode('utf8')
34                                 self.satellites[tpos] = tname
35                                 self.satList.append( (tname, tpos) )
36
37         def getNimType(self, slotID):
38                 #FIXME get it from /proc
39                 if slotID == 0:
40                         return self.nimType["DVB-S"]
41                 else:
42                         return self.nimType["empty/unknown"]
43
44         def getNimName(self, slotID):
45                 #FIXME get it from /proc
46                 return "Alps BSBE1"
47
48         def getNimSocketCount(self):
49                 #FIXME get it from /proc
50                 return 2
51
52         def getConfigPrefix(self, slotid):
53                 return "config.Nim" + ("A","B","C","D")[slotid] + "."
54                         
55         def __init__(self):
56                 #use as enum
57                 self.nimType = {                "empty/unknown": -1,
58                                                                                                 "DVB-S": 0,
59                                                                                                 "DVB-C": 1,
60                                                                                                 "DVB-T": 2}
61                 self.satList = [ ]                                                                              
62                                                                                                 
63                 self.readSatsfromFile()                                                                         
64                                                                                                 
65                 self.nimCount = self.getNimSocketCount()
66
67                 self.nimslots = [ ]
68                 x = 0
69                 while x < self.nimCount:
70                         tType = self.getNimType(x)
71                         tName = self.getNimName(x)
72                         tNim = nimSlot(x, tType, tName)
73                         self.nimslots.append(tNim)
74                         x += 1
75                 
76                 InitNimManager(self)    #init config stuff
77
78         def nimList(self):
79                 list = [ ]
80                 for slot in self.nimslots:
81                         nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
82                         if slot.nimType == -1:
83                                 nimText += "empty/unknown"
84                         else:
85                                 nimText += slot.name + " ("     
86                                 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
87                         list.append((nimText, slot))
88                 return list
89
90 def InitNimManager(nimmgr):
91         config.Nims = [ConfigSubsection()] * nimmgr.nimCount
92
93         for slot in nimmgr.nimslots:
94                 x = slot.slotid
95                 cname = nimmgr.getConfigPrefix(x)
96                 
97                 if slot.nimType == nimmgr.nimType["DVB-S"]:
98                         #use custom configElement which can handle a dict (for sats)
99                         config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
100                         config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 0, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D"));
101                         config.Nims[x].diseqcA = configElement(cname + "diseqcA",configSatlist, 0, nimmgr.satList);
102                         config.Nims[x].diseqcB = configElement(cname + "diseqcB",configSatlist, 0, nimmgr.satList);
103                         config.Nims[x].diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
104                         config.Nims[x].diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
105                 else:
106                         print "pls add support for this frontend type!"         
107
108         #def nimConfig
109
110   #def inputDevicesRepeatChanged(configElement):
111   #  iDevices.setRepeat(configElement.value);
112
113   #def inputDevicesDelayChanged(configElement):
114   #  iDevices.setDelay(configElement.value);
115
116   # this will call the "setup-val" initial
117   #config.inputDevices.repeat.addNotifier(inputDevicesRepeatChanged);
118   #config.inputDevices.delay.addNotifier(inputDevicesDelayChanged);
119
120 nimmanager = NimManager()