from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.Pixmap import Pixmap
from Components.Sources.List import List
from Components.Sources.StaticText import StaticText
from enigma import eMediaDatabase

try:
	from Plugins.SystemPlugins.MediaDatabaseManager.MediaDatabaseManager import MediaDatabaseManager
	print "[PowerMetrixFHD] 012 -OK-- MediaDatabaseManager"
except:
	print "[PowerMetrixFHD] 012 -NOK- MediaDatabaseManager"

#######################################################################################################################################################

def MediaDatabaseManager__init__(self, session):
	Screen.__init__(self, session)
	self["list"] = List([], enableWrapAround=True)
	self["key_red"] = StaticText(_("Remove"))
	self["key_green"] = StaticText(_("Add"))
	self["key_yellow"] = StaticText("")
	self["key_blue"] = StaticText(_("Rescan"))
	self["status"] = StaticText(_("waiting for statistics..."))

	# Background for Buttons
	self["red"] = Pixmap()
	self["green"] = Pixmap()
	self["yellow"] = Pixmap()
	self["blue"] = Pixmap()

	self._db = eMediaDatabase.getInstance()
	self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
	{
		"ok" : self._ok,
		"cancel" : self.close,
		"red" : self._red,
		"green" : self._green,
		"yellow" : self._yellow,
		"blue" : self._blue
	}, -2)

	self._db_scanStatistics_conn = self._db.scanStatistics.connect(self._onScanStatistics)
	self._db_scanFinished_conn = self._db.scanFinished.connect(self._onScanFinished)
	self._db_insertFinished_conn = self._db.insertFinished.connect(self._onInsertFinished)
	self.onLayoutFinish.append(self._onLayoutFinish)
	self.onClose.append(self._onClose)

#######################################################################################################################################################

def doMediaDatabaseManagerChange():
	try:
		MediaDatabaseManager.__init__ = MediaDatabaseManager__init__
		print "[PowerMetrixFHD] 012 -OK-- MediaDatabaseManager"
	except:
		print "[PowerMetrixFHD] 012 -NOK- MediaDatabaseManager"
