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