aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/NimManager.py
blob: 0ba7a392a05dfcc94d1f86fdeee4921043735c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from config import config       #global config instance

from config import configElement
from config import ConfigSubsection
from config import ConfigSlider
from config import configSelection

import xml.dom.minidom
from xml.dom import EMPTY_NAMESPACE
from skin import elementsWithTag
from Tools import XMLTools

class nimSlot:
	def __init__(self, slotid, nimtype, name):
		self.slotid = slotid
		self.nimType = nimtype
		self.name = name

class NimManager:
	def readSatsfromFile(self):
		self.satellites = { }
		#FIXME: path ok???
		satfile = file('/etc/tuxbox/satellites.xml', 'r')
		satdom = xml.dom.minidom.parseString(satfile.read())
		satfile.close()

		for entries in elementsWithTag(satdom.childNodes, "satellites"):
			for x in elementsWithTag(entries.childNodes, "sat"):
				#print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
				self.satellites[x.getAttribute('position')] = x.getAttribute('name')

	def getNimType(self, slotID):
		#FIXME get it from /proc
		if slotID == 0:
			return self.nimType["DVB-S"]
		else:
			return self.nimType["empty/unknown"]

	def getNimName(self, slotID):
		#FIXME get it from /proc
		return "Alps BSBE1"

	def getNimSocketCount(self):
		#FIXME get it from /proc
		return 2

	def getConfigPrefix(self, slotid):
		return "config.Nim" + ("A","B","C","D")[slotid] + "."
			
	def __init__(self):
		#use as enum
		self.nimType = {		"empty/unknown": -1,
												"DVB-S": 0,
												"DVB-C": 1,
												"DVB-T": 2}
												
		self.readSatsfromFile()										
												
		self.nimCount = self.getNimSocketCount()

		self.nimslots = [ ]
		x = 0
		while x < self.nimCount:
			tType = self.getNimType(x)
			tName = self.getNimName(x)
			tNim = nimSlot(x, tType, tName)
			self.nimslots.append(tNim)
			x += 1
		
		InitNimManager(self)	#init config stuff

	def nimList(self):
		list = [ ]
		for slot in self.nimslots:
			nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
			if slot.nimType == -1:
				nimText += "empty/unknown"
			else:
				nimText += slot.name + " ("	
				nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
			list.append((nimText, slot))
		return list

def InitNimManager(nimmgr):
	config.Nims = [ConfigSubsection()] * nimmgr.nimCount

	for slot in nimmgr.nimslots:
		x = slot.slotid
		cname = nimmgr.getConfigPrefix(x)
		
		if slot.nimType == nimmgr.nimType["DVB-S"]:
			#use custom configElement which can handle a dict (for sats)
			config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 0, ("Single", "Toneburst A/B", "DiSEqC A/B"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcA",configSelection, 0, ("Astra", "Hotbird"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcB",configSelection, 0, ("Astra", "Hotbird"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcC",configSelection, 0, ("Astra", "Hotbird"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcD",configSelection, 0, ("Astra", "Hotbird"));
		else:
			print "pls add support for this frontend type!"		

	#def nimConfig

  #def inputDevicesRepeatChanged(configElement):
  #  iDevices.setRepeat(configElement.value);

  #def inputDevicesDelayChanged(configElement):
  #  iDevices.setDelay(configElement.value);

  # this will call the "setup-val" initial
  #config.inputDevices.repeat.addNotifier(inputDevicesRepeatChanged);
  #config.inputDevices.delay.addNotifier(inputDevicesDelayChanged);

nimmanager = NimManager()