# -*- coding: utf-8 -*-
from Plugins.Plugin import PluginDescriptor
from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild
from Plugins.Extensions.WebInterface.WebChilds.Screenpage import ScreenPage
from twisted.web import static
from twisted.python import util
from enigma import eEnv
from plugins.__init__ import importExternalModules

if hasattr(static.File, 'render_GET'):
	class File(static.File):
		def render_POST(self, request):
			return self.render_GET(request)
else:
	File = static.File

def autostart(reason, **kwargs):
	if reason == 0 and "session" in kwargs:
		session = kwargs["session"]
		root = File(eEnv.resolve("${libdir}/enigma2/python/Plugins/Bp/gemininetcastwebif/web-data"))
		root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True) )
		root.putChild("mobile", ScreenPage(session, util.sibpath(__file__, "mobile"), True) )
		root.putChild('tmp', File('/tmp'))
		addExternalChild( ("netcast", root, "<img src=\"/netcast/img/icon.png\"> </img>DreamNetcast", 1, True, "_self") )
		
		importExternalModules()

def Plugins(**kwargs):
	return [PluginDescriptor(name="DreamNetcast",
			where = PluginDescriptor.WHERE_SESSIONSTART,
			fnc = autostart)]
