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