Merge branch 'master' of ssh://drmichael@scm.schwerkraft.elitedvb.net/scmrepos/git...
[enigma2-plugins.git] / webinterface / src / WebScreens.py
1 from enigma import eServiceReference
2 from Screens.Screen import Screen
3 from Tools.BoundFunction import boundFunction
4 from WebComponents.Sources.RequestData import RequestData
5
6
7 class WebScreen(Screen):
8         def __init__(self, session, request, allow_GET = True):
9                 Screen.__init__(self, session)
10                 self.stand_alone = True
11                 self.request = request
12                 self.instance = None
13                 self.allow_GET = allow_GET
14
15                 self["localip"] = RequestData(request, what=RequestData.HOST)
16                 self["localport"] = RequestData(request, what=RequestData.PORT)
17                 self["protocol"] = RequestData(request, what=RequestData.PROTOCOL)
18
19 class DummyWebScreen(WebScreen):
20         #use it, if you dont need any source, just to can do a static file with an xml-file
21         def __init__(self, session, request):
22                 WebScreen.__init__(self, session, request)
23
24 class UpdateWebScreen(WebScreen):
25         def __init__(self, session, request):
26                 WebScreen.__init__(self, session, request)
27                 from Components.Sources.Clock import Clock
28                 self["CurrentTime"] = Clock()
29                 from WebComponents.Sources.Volume import Volume
30                 self["Volume"] = Volume(session)
31
32
33 class MessageWebScreen(WebScreen):
34         def __init__(self, session, request):
35                 WebScreen.__init__(self, session, request, allow_GET = False)
36                 from WebComponents.Sources.Message import Message
37
38                 self["Message"] = Message(session, func=Message.PRINT)
39                 self["GetAnswer"] = Message(session, func=Message.ANSWER)
40
41 class ServiceListReloadWebScreen(WebScreen):
42         def __init__(self, session, request):
43                 WebScreen.__init__(self, session, request, allow_GET = False)
44                 from WebComponents.Sources.ServiceListReload import ServiceListReload
45
46                 self["ServiceListReload"] = ServiceListReload(session)
47
48 class AudioWebScreen(WebScreen):
49         def __init__(self, session, request):
50                 WebScreen.__init__(self, session, request, allow_GET = False)
51                 from WebComponents.Sources.AudioTracks import AudioTracks
52
53                 self["AudioTracks"] = AudioTracks(session, func=AudioTracks.GET)
54                 self["SelectAudioTrack"] = AudioTracks(session, func=AudioTracks.SET)
55                 self["Downmix"] = AudioTracks(session, func=AudioTracks.DOWNMIX)
56
57 class AboutWebScreen(WebScreen):
58         def __init__(self, session, request):
59                 WebScreen.__init__(self, session, request)
60                 from WebComponents.Sources.About import About
61                 from WebComponents.Sources.Frontend import Frontend
62                 from WebComponents.Sources.Hdd import Hdd
63                 from WebComponents.Sources.Network import Network
64                 from Components.config import config
65                 from Components.About import about
66                 from Components.Sources.StaticText import StaticText
67                 from Tools.DreamboxHardware import getFPVersion
68                 from Tools.HardwareInfo import HardwareInfo
69
70                 hw = HardwareInfo()
71
72                 self["About"] = About(session)
73
74                 self["Network"] = Network()
75                 self["Hdd"] = Hdd()
76                 self["Frontends"] = Frontend()
77                 self["EnigmaVersion"] = StaticText(about.getEnigmaVersionString())
78                 self["ImageVersion"] = StaticText(about.getVersionString())
79                 self["WebIfVersion"] = StaticText(config.plugins.Webinterface.version.value)
80                 self["FpVersion"] = StaticText(str(getFPVersion()))
81                 self["DeviceName"] = StaticText(hw.get_device_name())
82
83 class VolumeWebScreen(WebScreen):
84         def __init__(self, session, request):
85                 WebScreen.__init__(self, session, request, allow_GET = False)
86                 from WebComponents.Sources.Volume import Volume
87                 self["Volume"] = Volume(session)
88
89 class SettingsWebScreen(WebScreen):
90         def __init__(self, session, request):
91                 WebScreen.__init__(self, session, request)
92                 from WebComponents.Sources.Settings import Settings
93
94                 self["Settings"] = Settings(session)
95
96 class SubServiceWebScreen(WebScreen):
97         def __init__(self, session, request):
98                 WebScreen.__init__(self, session, request)
99                 from WebComponents.Sources.SubServices import SubServices
100
101                 self["SubServices"] = SubServices(session)
102
103 class StreamSubServiceWebScreen(WebScreen):
104         def __init__(self, session, request):
105                 WebScreen.__init__(self, session, request)
106                 from WebComponents.Sources.SubServices import SubServices
107
108                 self["StreamSubServices"] = SubServices(session, streamingScreens)
109
110 class ServiceListWebScreen(WebScreen):
111         def __init__(self, session, request):
112                 WebScreen.__init__(self, session, request)
113
114                 from Components.Sources.ServiceList import ServiceList
115                 from Screens.ChannelSelection import service_types_tv
116
117                 fav = eServiceReference(service_types_tv + ' FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
118                 self["ServiceList"] = ServiceList(fav, command_func=self.getServiceList, validate_commands=False)
119
120         def getServiceList(self, sRef):
121                 self["ServiceList"].root = sRef
122
123 class ServiceListRecursiveWebScreen(WebScreen):
124         def __init__(self, session, request):
125                 WebScreen.__init__(self, session, request)
126
127                 from WebComponents.Sources.ServiceListRecursive import ServiceListRecursive
128                 self["ServiceListRecursive"] = ServiceListRecursive(session, func=ServiceListRecursive.FETCH)
129
130 class SwitchServiceWebScreen(WebScreen):
131         def __init__(self, session, request):
132                 WebScreen.__init__(self, session, request, allow_GET = False)
133
134                 from WebComponents.Sources.SwitchService import SwitchService
135                 self["SwitchService"] = SwitchService(session)
136
137 class ReadPluginListWebScreen(WebScreen):
138         def __init__(self, session, request):
139                 WebScreen.__init__(self, session, request)
140                 from WebComponents.Sources.ReadPluginList import ReadPluginList
141                 self["ReadPluginList"] = ReadPluginList(session)
142
143 class LocationsAndTagsWebScreen(WebScreen):
144         def __init__(self, session, request):
145                 WebScreen.__init__(self, session, request)
146                 from WebComponents.Sources.LocationsAndTags import LocationsAndTags
147
148                 self["CurrentLocation"] = LocationsAndTags(session, LocationsAndTags.CURRLOCATION)
149                 self["Locations"] = LocationsAndTags(session, LocationsAndTags.LOCATIONS)
150                 self["AddLocation"] = LocationsAndTags(session, LocationsAndTags.ADDLOCATION)
151                 self["RemoveLocation"] = LocationsAndTags(session, LocationsAndTags.REMOVELOCATION)
152                 self["Tags"] = LocationsAndTags(session, LocationsAndTags.TAGS)
153
154 class EpgWebScreen(WebScreen):
155         def __init__(self, session, request):
156                 WebScreen.__init__(self, session, request)
157                 from WebComponents.Sources.EPG import EPG
158
159                 self["EpgSearch"] = EPG(session, func=EPG.SEARCH)
160                 self["EpgSearchSimilar"] = EPG(session, func=EPG.SEARCHSIMILAR)
161                 self["EpgService"] = EPG(session, func=EPG.SERVICE)
162                 self["EpgBouquetNow"] = EPG(session, func=EPG.BOUQUETNOW)
163                 self["EpgBouquetNext"] = EPG(session, func=EPG.BOUQUETNEXT)
164                 self["EpgBouquetNowNext"] = EPG(session, func=EPG.BOUQUETNOWNEXT)
165                 self["EpgServiceNow"] = EPG(session, func=EPG.SERVICENOW)
166                 self["EpgServiceNext"] = EPG(session, func=EPG.SERVICENEXT)
167                 self["EpgBouquet"] = EPG(session, func=EPG.BOUQUET)
168                 self["EpgMulti"] = EPG(session, func=EPG.MULTI)
169
170                 self["EpgServiceWap"] = EPG(session, func=EPG.SERVICE, endtm=True)
171
172         def getServiceList(self, sRef):
173                 self["ServiceList"].root = sRef
174
175 class MovieWebScreen(WebScreen):
176         def __init__(self, session, request):
177                 WebScreen.__init__(self, session, request)
178                 from Components.MovieList import MovieList
179                 from Tools.Directories import resolveFilename, SCOPE_HDD
180                 from WebComponents.Sources.Movie import Movie
181
182                 movielist = MovieList(None)
183                 self["MovieList"] = Movie(session, movielist, func=Movie.LIST)
184                 self["MovieFileDel"] = Movie(session, movielist, func=Movie.DEL)
185                 self["MovieFileMove"] = Movie(session, movielist, func=Movie.MOVE)
186
187 class MediaPlayerWebScreen(WebScreen):
188         def __init__(self, session, request):
189                 WebScreen.__init__(self, session, request, allow_GET = False)
190                 from WebComponents.Sources.MP import MP
191
192                 self["FileList"] = MP(session, func=MP.LIST)
193                 self["PlayFile"] = MP(session, func=MP.PLAY)
194                 self["AddFile"] = MP(session, func = MP.ADD)
195                 self["RemoveFile"] = MP(session, func=MP.REMOVE)
196                 self["Command"] = MP(session, func=MP.COMMAND)
197                 self["WritePlaylist"] = MP(session, func=MP.WRITEPLAYLIST)
198                 self["CurrentTrack"] = MP(session, func=MP.CURRENT)
199                 self["LoadPlaylist"] = MP(session, func=MP.LOADPLAYLIST)
200
201 class AutoTimerWebScreen(WebScreen):
202         def __init__(self, session, request):
203                 WebScreen.__init__(self, session, request, allow_GET = False)
204                 from WebComponents.Sources.AT import AT
205
206                 self["AutoTimerList"] = AT(session, func=AT.LIST)
207                 self["AutoTimerWrite"] = AT(session, func=AT.WRITE)
208
209 class TimerWebScreen(WebScreen):
210         def __init__(self, session, request):
211                 WebScreen.__init__(self, session, request, allow_GET = False)
212                 from WebComponents.Sources.Timer import Timer
213
214                 self["TimerList"] = Timer(session, func=Timer.LIST)
215                 self["TimerAddEventID"] = Timer(session, func=Timer.ADDBYID)
216                 self["TimerAdd"] = Timer(session, func=Timer.ADD)
217                 self["TimerDel"] = Timer(session, func=Timer.DEL)
218                 self["TimerChange"] = Timer(session, func=Timer.CHANGE)
219                 self["TimerListWrite"] = Timer(session, func=Timer.WRITE)
220                 self["TVBrowser"] = Timer(session, func=Timer.TVBROWSER)
221                 self["RecordNow"] = Timer(session, func=Timer.RECNOW)
222                 self["TimerCleanup"] = Timer(session, func=Timer.CLEANUP)
223
224 class TimerEditWebScreen(ServiceListWebScreen, LocationsAndTagsWebScreen):
225         def __init__(self, session, request):
226                 ServiceListWebScreen.__init__(self, session, request)
227                 LocationsAndTagsWebScreen.__init__(self, session, request)
228
229                 from Components.Sources.ServiceList import ServiceList
230                 from Screens.ChannelSelection import service_types_tv
231                 fav = eServiceReference(service_types_tv + ' FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
232                 self["BouquetList"] = ServiceList(fav, command_func=self.getBouquetList, validate_commands=False)
233                 #get the first bouquet and set it
234                 favlist = self["BouquetList"].getServicesAsList(format = "S")
235                 if len(favlist) > 0:
236                         self["ServiceList"].root = eServiceReference(favlist[0])
237
238         def getBouquetList(self, ref):
239                 pass
240
241 class RemoteWebScreen(WebScreen):
242         def __init__(self, session, request):
243                 WebScreen.__init__(self, session, request, allow_GET = False)
244                 from WebComponents.Sources.RemoteControl import RemoteControl
245
246                 self["RemoteControl"] = RemoteControl(session)
247
248 class PowerWebScreen(WebScreen):
249         def __init__(self, session, request):
250                 WebScreen.__init__(self, session, request, allow_GET = False)
251                 from WebComponents.Sources.PowerState import PowerState
252
253                 self["PowerState"] = PowerState(session)
254
255 class ParentControlWebScreen(WebScreen):
256         def __init__(self, session, request):
257                 WebScreen.__init__(self, session, request, allow_GET = False)
258                 from WebComponents.Sources.ParentControl import ParentControl
259
260                 self["ParentControlList"] = ParentControl(session)
261
262 class WapWebScreen(WebScreen):
263         def __init__(self, session, request):
264                 WebScreen.__init__(self, session, request)
265                 from WebComponents.Sources.WAPfunctions import WAPfunctions
266
267                 self["WAPFillOptionListYear"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
268                 self["WAPFillOptionListDay"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
269                 self["WAPFillOptionListMonth"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
270                 self["WAPFillOptionListShour"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
271                 self["WAPFillOptionListSmin"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
272                 self["WAPFillOptionListEhour"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
273                 self["WAPFillOptionListEmin"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
274
275                 self["WAPFillOptionListRecord"] = WAPfunctions(session, func=WAPfunctions.OPTIONLIST)
276                 self["WAPFillOptionListAfterEvent"] = WAPfunctions(session, func=WAPfunctions.OPTIONLIST)
277
278                 self["WAPFillValueName"] = WAPfunctions(session, func=WAPfunctions.FILLVALUE)
279                 self["WAPFillValueDescr"] = WAPfunctions(session, func=WAPfunctions.FILLVALUE)
280                 self["WAPFillLocation"] = WAPfunctions(session, func=WAPfunctions.LOCATIONLIST)
281                 self["WAPFillTags"] = WAPfunctions(session, func=WAPfunctions.TAGLIST)
282
283                 self["WAPFillOptionListRepeated"] = WAPfunctions(session, func=WAPfunctions.REPEATED)
284                 self["WAPServiceList"] = WAPfunctions(session, func=WAPfunctions.SERVICELIST)
285
286                 self["WAPdeleteOldOnSave"] = WAPfunctions(session, func=WAPfunctions.DELETEOLD)
287
288 streamingScreens = []
289 streamingEvents = []
290
291 class StreamingWebScreen(WebScreen):
292         EVENT_START = 0
293         EVENT_END = 1
294
295         def __init__(self, session, request):
296                 WebScreen.__init__(self, session, request)
297                 from Components.Sources.StreamService import StreamService
298                 self["StreamService"] = StreamService(self.session.nav)
299                 self.screenIndex = len(streamingScreens) - 1
300                 self.clientIP = request.getAllHeaders().get('x-forwarded-for', request.getClientIP())
301                 self.onClose.append(boundFunction(self.stateChanged, self.EVENT_END))
302                 streamingScreens.append(self)
303                 self.stateChanged(StreamingWebScreen.EVENT_START)
304
305         def stateChanged(self, event):
306                 for f in streamingEvents:
307                         f(event, self)
308
309         def getRecordService(self):
310                 if self.has_key("StreamService"):
311                         return self["StreamService"].getService()
312                 return None
313
314         def getRecordServiceRef(self):
315                 if self.has_key("StreamService"):
316                         return self["StreamService"].ref
317                 return None
318
319 class M3uStreamingWebScreen(WebScreen):
320         def __init__(self, session, request):
321                 WebScreen.__init__(self, session, request)
322                 from Components.Sources.StaticText import StaticText
323                 from Components.Sources.Config import Config
324                 from Components.config import config
325                 self["ref"] = StaticText()
326
327 class M3uStreamingCurrentServiceWebScreen(WebScreen):
328         def __init__(self, session, request):
329                 WebScreen.__init__(self, session, request)
330                 from WebComponents.Sources.CurrentService import CurrentService
331                 self["CurrentService"] = CurrentService(session)
332
333 class TsM3uWebScreen(WebScreen):
334         def __init__(self, session, request):
335                 WebScreen.__init__(self, session, request)
336                 from Components.Sources.StaticText import StaticText
337                 from Components.Sources.Config import Config
338                 from Components.config import config
339                 self["file"] = StaticText()
340
341 class RestartWebScreen(WebScreen):
342         def __init__(self, session, request):
343                 WebScreen.__init__(self, session, request)
344                 import plugin
345                 plugin.restartWebserver(session)
346
347 class GetPidWebScreen(WebScreen):
348         def __init__(self, session, request):
349                  WebScreen.__init__(self, session, request)
350                  from Components.Sources.StaticText import StaticText
351                  from enigma import iServiceInformation
352                  pids = self.session.nav.getCurrentService()
353                  if pids is not None:
354                         pidinfo = pids.info()
355                         VPID = hex(pidinfo.getInfo(iServiceInformation.sVideoPID))
356                         APID = hex(pidinfo.getInfo(iServiceInformation.sAudioPID))
357                         PPID = hex(pidinfo.getInfo(iServiceInformation.sPMTPID))
358                         self["pids"] = StaticText("%s,%s,%s" % (PPID.lstrip("0x"), VPID.lstrip("0x"), APID.lstrip("0x")))
359                  else:
360                         self["pids"] = StaticText("0x,0x,0x")
361
362 class DeviceInfoWebScreen(WebScreen):
363         def __init__(self, session, request):
364                 WebScreen.__init__(self, session, request)
365                 from WebComponents.Sources.Network import Network
366                 from WebComponents.Sources.Hdd import Hdd
367                 from WebComponents.Sources.Frontend import Frontend
368                 from Components.config import config
369                 from Components.About import about
370                 from Components.Sources.StaticText import StaticText
371                 from Tools.DreamboxHardware import getFPVersion
372                 from Tools.HardwareInfo import HardwareInfo
373
374                 hw = HardwareInfo()
375
376                 self["Network"] = Network()
377                 self["Hdd"] = Hdd()
378                 self["Frontends"] = Frontend()
379                 self["EnigmaVersion"] = StaticText(about.getEnigmaVersionString())
380                 self["ImageVersion"] = StaticText(about.getVersionString())
381                 self["WebIfVersion"] = StaticText(config.plugins.Webinterface.version.value)
382                 self["FpVersion"] = StaticText(str(getFPVersion()))
383                 self["DeviceName"] = StaticText(hw.get_device_name())
384
385 class ServicePlayableWebScreen(WebScreen):
386         def __init__(self, session, request):
387                 WebScreen.__init__(self, session, request)
388                 from WebComponents.Sources.ServicePlayable import ServicePlayable
389
390                 self["ServicePlayable"] = ServicePlayable(session, type=ServicePlayable.SINGLE)
391
392 class ServiceListPlayableWebScreen(WebScreen):
393         def __init__(self, session, request):
394                 WebScreen.__init__(self, session, request)
395                 from WebComponents.Sources.ServicePlayable import ServicePlayable
396
397                 self["ServiceListPlayable"] = ServicePlayable(session, type=ServicePlayable.BOUQUET)
398
399 class SleepTimerWebScreen(WebScreen):
400         def __init__(self, session, request):
401                 WebScreen.__init__(self, session, request, allow_GET = False)
402
403                 from WebComponents.Sources.SleepTimer import SleepTimer
404                 self["SleepTimer"] = SleepTimer(session)
405
406 class TPMWebScreen(WebScreen):
407         def __init__(self, session, request):
408                 WebScreen.__init__(self, session, request)
409
410                 from WebComponents.Sources.TPMChallenge import TPMChallenge
411                 self["TPM"] = TPMChallenge()
412
413 class ExternalWebScreen(WebScreen):
414         def __init__(self, session, request):
415                 WebScreen.__init__(self, session, request)
416
417                 from WebComponents.Sources.External import External
418                 self["External"] = External()
419
420 class StringsWebScreen(WebScreen):
421         def __init__(self, session, request):
422                 WebScreen.__init__(self, session, request)
423
424                 from WebComponents.Sources.Strings import Strings
425                 self["Strings"] = Strings()
426
427 class SessionWebScreen(WebScreen):
428         def __init__(self, session, request):
429                 WebScreen.__init__(self, session, request)
430
431                 from WebComponents.Sources.WebSession import WebSession
432                 self["Session"] = WebSession(request)
433
434 class BackupWebScreen(WebScreen):
435         def __init__(self, session, request):
436                 WebScreen.__init__(self, session, request, allow_GET = False)
437
438                 from WebComponents.Sources.Backup import Backup
439                 self["Backup"] = Backup(Backup.BACKUP)
440                 self["Restore"] = Backup(Backup.RESTORE)