enigma2: 4.3.1r10
[enigma2.git] / usr / lib / enigma2 / python / Plugins / SystemPlugins / DBusInterfaceProxy / plugin.py
1 from enigma import eDBusInterface, eDBusInterfaceProxy, eServiceReference
2 from Components.VolumeControl import VolumeControl
3 from Plugins.Plugin import PluginDescriptor
4 from Screens.MoviePlayer import MoviePlayer
5 from Tools.Log import Log
6
7 from time import time
8
9 class DBusInterfaceProxy(eDBusInterfaceProxy):
10         proxyInstance = None
11
12         def __init__(self, session):
13                 assert not DBusInterfaceProxy.instance
14                 eDBusInterfaceProxy.__init__(self)
15                 DBusInterfaceProxy.proxyInstance = self
16                 self._session = session
17                 self._player = None
18
19         def play(self, val, isUri):
20                 Log.w("%s %s" %(val, isUri))
21                 if isUri:
22                         val = val.split("#")
23                         uri = val[0]
24                         if len(val) > 1:
25                                 name = val[1]
26                         else:
27                                 name = uri.split("/")[-1]
28                         if uri.startswith("file://") or uri.startswith("/"): #Local File
29                                 if uri.lower().endswith(".ts"):
30                                         serviceType = eServiceReference.idDVB
31                                 elif uri.lower().endswith(".m2ts"):
32                                         serviceType = eServiceReference.idM2TS
33                                 else:
34                                         serviceType = eServiceReference.idGST
35                                 uri = uri.replace("file://", "")
36                                 ref = eServiceReference(serviceType, 0, uri)
37                         else:
38                                 ref = eServiceReference(eServiceReference.idURI, 0, uri)
39                                 ref.setName(name)
40                 else:
41                         ref = eServiceReference(val)
42                 if not ref.valid():
43                         return False
44                 if not self._player:
45                         self._player = self._session.openWithCallback(self._onPlayerClosed, MoviePlayer, ref)
46                 else:
47                         self._player.playService(ref)
48                 return True
49
50         def stop(self):
51                 if self._player:
52                         self._player.handleLeave(ask=False)
53                         return True
54                 return False
55
56         def isTimerPending(self):
57                 next_rec_time = self._session.nav.RecordTimer.getNextRecordingTime()
58                 return next_rec_time > 0 and (next_rec_time - time()) < 360
59
60         def setVolume(self, to):
61                 if to < 0 or to > 100 or not VolumeControl.instance:
62                         return False
63                 VolumeControl.instance.setDiscreteVolume(to)
64                 return True
65
66         def _onPlayerClosed(self):
67                 Log.i("Playback stopped!")
68                 self._player = None
69
70 def registerProxy(session, *args, **kwargs):
71         eDBusInterface.setProxy(DBusInterfaceProxy(session))
72
73 def Plugins(**kwargs):
74         return PluginDescriptor(name=_("DBus Interface Python Proxy"), description=_("Supplies DBus with some additional functionality"), where = PluginDescriptor.WHERE_SESSIONSTART, needsRestart = False, fnc=registerProxy)