Webinterface: check fullpath in getMovieSubdirs
[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                 self["MovieListSubdir"] = Movie(session, None, func=Movie.DIRS)
187
188 class MediaPlayerWebScreen(WebScreen):
189         def __init__(self, session, request):
190                 WebScreen.__init__(self, session, request, allow_GET = False)
191                 from WebComponents.Sources.MP import MP
192
193                 self["FileList"] = MP(session, func=MP.LIST)
194                 self["PlayFile"] = MP(session, func=MP.PLAY)
195                 self["AddFile"] = MP(session, func = MP.ADD)
196                 self["RemoveFile"] = MP(session, func=MP.REMOVE)
197                 self["Command"] = MP(session, func=MP.COMMAND)
198                 self["WritePlaylist"] = MP(session, func=MP.WRITEPLAYLIST)
199                 self["CurrentTrack"] = MP(session, func=MP.CURRENT)
200                 self["LoadPlaylist"] = MP(session, func=MP.LOADPLAYLIST)
201
202 class AutoTimerWebScreen(WebScreen):
203         def __init__(self, session, request):
204                 WebScreen.__init__(self, session, request, allow_GET = False)
205                 from WebComponents.Sources.AT import AT
206
207                 self["AutoTimerList"] = AT(session, func=AT.LIST)
208                 self["AutoTimerWrite"] = AT(session, func=AT.WRITE)
209
210 class TimerWebScreen(WebScreen):
211         def __init__(self, session, request):
212                 WebScreen.__init__(self, session, request, allow_GET = False)
213                 from WebComponents.Sources.Timer import Timer
214
215                 self["TimerList"] = Timer(session, func=Timer.LIST)
216                 self["TimerAddEventID"] = Timer(session, func=Timer.ADDBYID)
217                 self["TimerAdd"] = Timer(session, func=Timer.ADD)
218                 self["TimerDel"] = Timer(session, func=Timer.DEL)
219                 self["TimerChange"] = Timer(session, func=Timer.CHANGE)
220                 self["TimerListWrite"] = Timer(session, func=Timer.WRITE)
221                 self["TVBrowser"] = Timer(session, func=Timer.TVBROWSER)
222                 self["RecordNow"] = Timer(session, func=Timer.RECNOW)
223                 self["TimerCleanup"] = Timer(session, func=Timer.CLEANUP)
224
225 class TimerEditWebScreen(ServiceListWebScreen, LocationsAndTagsWebScreen):
226         def __init__(self, session, request):
227                 ServiceListWebScreen.__init__(self, session, request)
228                 LocationsAndTagsWebScreen.__init__(self, session, request)
229
230                 from Components.Sources.ServiceList import ServiceList
231                 from Screens.ChannelSelection import service_types_tv
232                 fav = eServiceReference(service_types_tv + ' FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
233                 self["BouquetList"] = ServiceList(fav, command_func=self.getBouquetList, validate_commands=False)
234                 #get the first bouquet and set it
235                 favlist = self["BouquetList"].getServicesAsList(format = "S")
236                 if len(favlist) > 0:
237                         self["ServiceList"].root = eServiceReference(favlist[0])
238
239         def getBouquetList(self, ref):
240                 pass
241
242 class RemoteWebScreen(WebScreen):
243         def __init__(self, session, request):
244                 WebScreen.__init__(self, session, request, allow_GET = False)
245                 from WebComponents.Sources.RemoteControl import RemoteControl
246
247                 self["RemoteControl"] = RemoteControl(session)
248
249 class PowerWebScreen(WebScreen):
250         def __init__(self, session, request):
251                 WebScreen.__init__(self, session, request, allow_GET = False)
252                 from WebComponents.Sources.PowerState import PowerState
253
254                 self["PowerState"] = PowerState(session)
255
256 class ParentControlWebScreen(WebScreen):
257         def __init__(self, session, request):
258                 WebScreen.__init__(self, session, request, allow_GET = False)
259                 from WebComponents.Sources.ParentControl import ParentControl
260
261                 self["ParentControlList"] = ParentControl(session)
262
263 class WapWebScreen(WebScreen):
264         def __init__(self, session, request):
265                 WebScreen.__init__(self, session, request)
266                 from WebComponents.Sources.WAPfunctions import WAPfunctions
267
268                 self["WAPFillOptionListYear"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
269                 self["WAPFillOptionListDay"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
270                 self["WAPFillOptionListMonth"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
271                 self["WAPFillOptionListShour"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
272                 self["WAPFillOptionListSmin"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
273                 self["WAPFillOptionListEhour"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
274                 self["WAPFillOptionListEmin"] = WAPfunctions(session, func=WAPfunctions.LISTTIME)
275
276                 self["WAPFillOptionListRecord"] = WAPfunctions(session, func=WAPfunctions.OPTIONLIST)
277                 self["WAPFillOptionListAfterEvent"] = WAPfunctions(session, func=WAPfunctions.OPTIONLIST)
278
279                 self["WAPFillValueName"] = WAPfunctions(session, func=WAPfunctions.FILLVALUE)
280                 self["WAPFillValueDescr"] = WAPfunctions(session, func=WAPfunctions.FILLVALUE)
281                 self["WAPFillLocation"] = WAPfunctions(session, func=WAPfunctions.LOCATIONLIST)
282                 self["WAPFillTags"] = WAPfunctions(session, func=WAPfunctions.TAGLIST)
283
284                 self["WAPFillOptionListRepeated"] = WAPfunctions(session, func=WAPfunctions.REPEATED)
285                 self["WAPServiceList"] = WAPfunctions(session, func=WAPfunctions.SERVICELIST)
286
287                 self["WAPdeleteOldOnSave"] = WAPfunctions(session, func=WAPfunctions.DELETEOLD)
288
289 streamingScreens = []
290 streamingEvents = []
291
292 class StreamingWebScreen(WebScreen):
293         EVENT_START = 0
294         EVENT_END = 1
295
296         def __init__(self, session, request):
297                 WebScreen.__init__(self, session, request)
298                 from Components.Sources.StreamService import StreamService
299                 self["StreamService"] = StreamService(self.session.nav)
300                 self.screenIndex = len(streamingScreens) - 1
301                 self.clientIP = request.getAllHeaders().get('x-forwarded-for', request.getClientIP())
302                 self.onClose.append(boundFunction(self.stateChanged, self.EVENT_END))
303                 streamingScreens.append(self)
304                 self.stateChanged(StreamingWebScreen.EVENT_START)
305
306         def stateChanged(self, event):
307                 for f in streamingEvents:
308                         f(event, self)
309
310         def getRecordService(self):
311                 if self.has_key("StreamService"):
312                         return self["StreamService"].getService()
313                 return None
314
315         def getRecordServiceRef(self):
316                 if self.has_key("StreamService"):
317                         return self["StreamService"].ref
318                 return None
319
320 class M3uStreamingWebScreen(WebScreen):
321         def __init__(self, session, request):
322                 WebScreen.__init__(self, session, request)
323                 from Components.Sources.StaticText import StaticText
324                 from Components.Sources.Config import Config
325                 from Components.config import config
326                 self["ref"] = StaticText()
327
328 class M3uStreamingCurrentServiceWebScreen(WebScreen):
329         def __init__(self, session, request):
330                 WebScreen.__init__(self, session, request)
331                 from WebComponents.Sources.CurrentService import CurrentService
332                 self["CurrentService"] = CurrentService(session)
333
334 class TsM3uWebScreen(WebScreen):
335         def __init__(self, session, request):
336                 WebScreen.__init__(self, session, request)
337                 from Components.Sources.StaticText import StaticText
338                 from Components.Sources.Config import Config
339                 from Components.config import config
340                 self["file"] = StaticText()
341
342 class RestartWebScreen(WebScreen):
343         def __init__(self, session, request):
344                 WebScreen.__init__(self, session, request)
345                 import plugin
346                 plugin.restartWebserver(session)
347
348 class GetPidWebScreen(WebScreen):
349         def __init__(self, session, request):
350                  WebScreen.__init__(self, session, request)
351                  from Components.Sources.StaticText import StaticText
352                  from enigma import iServiceInformation
353                  pids = self.session.nav.getCurrentService()
354                  if pids is not None:
355                         pidinfo = pids.info()
356                         VPID = hex(pidinfo.getInfo(iServiceInformation.sVideoPID))
357                         APID = hex(pidinfo.getInfo(iServiceInformation.sAudioPID))
358                         PPID = hex(pidinfo.getInfo(iServiceInformation.sPMTPID))
359                         self["pids"] = StaticText("%s,%s,%s" % (PPID.lstrip("0x"), VPID.lstrip("0x"), APID.lstrip("0x")))
360                  else:
361                         self["pids"] = StaticText("0x,0x,0x")
362
363 class DeviceInfoWebScreen(WebScreen):
364         def __init__(self, session, request):
365                 WebScreen.__init__(self, session, request)
366                 from WebComponents.Sources.Network import Network
367                 from WebComponents.Sources.Hdd import Hdd
368                 from WebComponents.Sources.Frontend import Frontend
369                 from Components.config import config
370                 from Components.About import about
371                 from Components.Sources.StaticText import StaticText
372                 from Tools.DreamboxHardware import getFPVersion
373                 from Tools.HardwareInfo import HardwareInfo
374
375                 hw = HardwareInfo()
376
377                 self["Network"] = Network()
378                 self["Hdd"] = Hdd()
379                 self["Frontends"] = Frontend()
380                 self["EnigmaVersion"] = StaticText(about.getEnigmaVersionString())
381                 self["ImageVersion"] = StaticText(about.getVersionString())
382                 self["WebIfVersion"] = StaticText(config.plugins.Webinterface.version.value)
383                 self["FpVersion"] = StaticText(str(getFPVersion()))
384                 self["DeviceName"] = StaticText(hw.get_device_name())
385
386 class ServicePlayableWebScreen(WebScreen):
387         def __init__(self, session, request):
388                 WebScreen.__init__(self, session, request)
389                 from WebComponents.Sources.ServicePlayable import ServicePlayable
390
391                 self["ServicePlayable"] = ServicePlayable(session, type=ServicePlayable.SINGLE)
392
393 class ServiceListPlayableWebScreen(WebScreen):
394         def __init__(self, session, request):
395                 WebScreen.__init__(self, session, request)
396                 from WebComponents.Sources.ServicePlayable import ServicePlayable
397
398                 self["ServiceListPlayable"] = ServicePlayable(session, type=ServicePlayable.BOUQUET)
399
400 class SleepTimerWebScreen(WebScreen):
401         def __init__(self, session, request):
402                 WebScreen.__init__(self, session, request, allow_GET = False)
403
404                 from WebComponents.Sources.SleepTimer import SleepTimer
405                 self["SleepTimer"] = SleepTimer(session)
406
407 class TPMWebScreen(WebScreen):
408         def __init__(self, session, request):
409                 WebScreen.__init__(self, session, request)
410
411                 from WebComponents.Sources.TPMChallenge import TPMChallenge
412                 self["TPM"] = TPMChallenge()
413
414 class ExternalWebScreen(WebScreen):
415         def __init__(self, session, request):
416                 WebScreen.__init__(self, session, request)
417
418                 from WebComponents.Sources.External import External
419                 self["External"] = External()
420
421 class StringsWebScreen(WebScreen):
422         def __init__(self, session, request):
423                 WebScreen.__init__(self, session, request)
424
425                 from WebComponents.Sources.Strings import Strings
426                 self["Strings"] = Strings()
427
428 class SessionWebScreen(WebScreen):
429         def __init__(self, session, request):
430                 WebScreen.__init__(self, session, request)
431
432                 from WebComponents.Sources.WebSession import WebSession
433                 self["Session"] = WebSession(request)
434
435 class BackupWebScreen(WebScreen):
436         def __init__(self, session, request):
437                 WebScreen.__init__(self, session, request, allow_GET = False)
438
439                 from WebComponents.Sources.Backup import Backup
440                 self["Backup"] = Backup(Backup.BACKUP)
441                 self["Restore"] = Backup(Backup.RESTORE)
442                 
443 class StopServiceWebScreen(WebScreen):
444         def __init__(self, session, request):
445                 WebScreen.__init__(self, session, request)
446                 
447                 from WebComponents.Sources.StopService import StopService
448                 self["StopService"] = StopService(session)
449