# -*- coding: utf-8 -*-
#
#  mFeInfo - Converter
#
#  Coded by weazle (c) 2013 / OE2.2 changes by dre
#  Support: www.dreambox-tools.info
#  E-Mail: weazle@dreambox-tools.info
#
# This Converter is open source but it is NOT free software.
#
# This Converter may only be distributed to and executed on hardware which
# is licensed by Dream Multimedia GmbH.
# In other words:
# It's NOT allowed to distribute any parts of this Converter or its source code in ANY way
# to hardware which is NOT licensed by Dream Multimedia GmbH.
# It's NOT allowed to execute this Converter and its source code or even parts of it in ANY way
# on hardware which is NOT licensed by Dream Multimedia GmbH.
#
# If you want to use or modify the code or parts of it,
# you have to keep MY license and inform me about the modifications by mail.
#	

from Components.Converter.Converter import Converter
from Components.Element import cached

from enigma import iServiceInformation

class mFeInfo(Converter, object):
	def __init__(self, type):
		Converter.__init__(self, type)

	@cached
	def getData(self):
		system_info = None
		tuner_info = None		
		service = self.source.service
		if service:
			frontend_info = service.frontendInfo()
			if frontend_info:
				frontend_data = frontend_info.getAll(True)
				tuner_info = frontend_data.get('tuner_type')
				if tuner_info is not None:	
					if tuner_info == 0:
						info = service and service.info()
						if info is not None:
							self.transponder_info = info.getInfoObject(iServiceInformation.sTransponderData)
							if self.transponder_info is not None:
								tpInfo = self.transponder_info.get("system", None)
								if tpInfo == 1:
									return 3
								else:
									return 0					
					else:
						return tuner_info
		return -1


	@cached
	def getText(self):
		tval = self.getData()
		if tval is not None:
			if tval == 0:
				return 'DVB-S'
			elif tval == 1:
				return 'DVB-C'
			elif tval == 2:
				return 'DVB-T'
			elif tval == 3:
				return 'DVB-S2'
		return ""

	text = property(getText)

	@cached
	def getValue(self):
		val = self.getData()
		if val is not None:
			return val
		return -1	

	value = property(getValue)
