add downloadbutton in movielist, fix HTTP-Header Contenttype
[enigma2-plugins.git] / webinterface / src / WebChilds / Screenpage.py
1 from twisted.web2 import resource, stream, responsecode, http, http_headers
2
3 from Plugins.Extensions.WebInterface import webif
4
5 import os
6
7
8 """
9     define all files in /web to send no  XML-HTTP-Headers here
10     all files listed here will get an Content-Type: application/xhtml+xml charset: UTF-8
11 """
12 AppTextHeaderFiles = ['stream.m3u.xml','ts.m3u.xml',] 
13
14 """
15  Actualy, the TextHtmlHeaderFiles should contain the updates.html.xml, but the IE then
16  has problems with unicode-characters
17 """
18 TextHtmlHeaderFiles = ['wapremote.xml','stream.xml',] 
19
20 """
21     define all files in /web to send no  XML-HTTP-Headers here
22     all files listed here will get an Content-Type: text/html charset: UTF-8
23 """
24 NoExplicitHeaderFiles = ['getpid.xml','tvbrowser.xml',] 
25
26 class ScreenPage(resource.Resource):
27     def __init__(self, session,path):
28         self.session = session
29         self.path = path
30
31     def render(self, req):
32         #if self.session is not True:
33         #    return http.Response(responsecode.OK, stream="please wait until enigma has booted")
34
35         class myProducerStream(stream.ProducerStream):
36             def __init__(self):
37                 stream.ProducerStream.__init__(self)
38                 self.closed_callback = None
39
40             def close(self):
41                 if self.closed_callback:
42                     self.closed_callback()
43                     self.closed_callback = None
44                 stream.ProducerStream.close(self)
45
46         if os.path.isfile(self.path):
47             s=myProducerStream()
48             webif.renderPage(s, self.path, req, self.session)  # login?
49             if self.path.split("/")[-1] in AppTextHeaderFiles:
50                 return http.Response(responsecode.OK,{'Content-type': http_headers.MimeType('application', 'text', (('charset', 'UTF-8'),))},stream=s)
51             elif self.path.split("/")[-1] in TextHtmlHeaderFiles or (self.path.endswith(".html.xml") and self.path.split("/")[-1] != "updates.html.xml"):
52                 return http.Response(responsecode.OK,{'Content-type': http_headers.MimeType('text', 'html', (('charset', 'UTF-8'),))},stream=s)
53             elif self.path.split("/")[-1] in NoExplicitHeaderFiles:
54                 return http.Response(responsecode.OK,stream=s)
55             else:
56                 return http.Response(responsecode.OK,{'Content-type': http_headers.MimeType('application', 'xhtml+xml', (('charset', 'UTF-8'),))},stream=s)
57         else:
58             return http.Response(responsecode.NOT_FOUND)
59
60     def locateChild(self, request, segments):
61         path = self.path+'/'+'/'.join(segments)
62         if path[-1:] == "/":
63             path += "index.html"
64         path +=".xml"
65         return ScreenPage(self.session,path), ()