from __future__ import absolute_import
from Components.Element import cached
from enigma import eServiceCenter
from Components.Sources.Source import Source
#Dr.Best --> eit with Non-TS-Files
from merlin.emerlin import eMerlin, eMerlinMetaData

class ServiceEvent(Source, object):
	def __init__(self):
		Source.__init__(self)
		self.service = None 

	@cached
	def getCurrentService(self):
		return self.service

	@cached
	def getCurrentEvent(self):
		return self.service and ((self.info and self.info.getEvent(self.service)) or eMerlin.getInstance().getEvent(self.service))

	@cached
	def getInfo(self):
		return self.service and eServiceCenter.getInstance().info(self.service)
	
	@cached
	def getMerlinMetaData(self):
		return self.service and eMerlinMetaData(self.service.getPath())

	event = property(getCurrentEvent)
	info = property(getInfo)
	merlinMetaData = property(getMerlinMetaData)

	def newService(self, ref):
		if not self.service or not ref or self.service != ref:
			self.service = ref
			if not ref:
				self.changed((self.CHANGED_CLEAR,))
			else:
				self.changed((self.CHANGED_ALL,))
