epgrefresh: changes to how adapters are handled
[enigma2-plugins.git] / epgrefresh / src / RecordAdapter.py
1 from Components.SystemInfo import SystemInfo
2
3 # MessageBox
4 from Screens.MessageBox import MessageBox
5 from Tools import Notifications
6
7 # Config
8 from Components.config import config
9
10 class RecordAdapter:
11         backgroundCapable = True
12         def __init__(self, session):
13                 if SystemInfo.get("NumVideoDecoders", 1) < 2:
14                         self.backgroundRefreshAvailable = False
15                         return
16
17                 self.backgroundRefreshAvailable = True
18                 self.__service = None
19                 self.navcore = session.nav
20
21         def prepare(self):
22                 if not self.backgroundRefreshAvailable:
23                         return False
24                 if config.plugins.epgrefresh.enablemessage.value:
25                         Notifications.AddNotification(MessageBox, _("EPG refresh started in background."), type=MessageBox.TYPE_INFO, timeout=4)
26
27                 return True
28
29         def play(self, service):
30                 print "[EPGRefresh.RecordAdapter.play]"
31                 if not self.backgroundRefreshAvailable: return False
32                 self.stopStreaming()
33                 self.__service = self.navcore.recordService(service)
34                 if self.__service is not None:
35                         self.__service.prepareStreaming()
36                         self.__service.start()
37                         return True
38                 return False
39
40         def stopStreaming(self):
41                 if self.__service is not None:
42                         self.navcore.stopRecordService(self.__service)
43                         self.__service = None
44
45         def stop(self):
46                 print "[EPGRefresh.RecordAdapter.stop]"
47                 self.stopStreaming()
48