PushService: Initial release
[enigma2-plugins.git] / pushservice / src / Plugins / RecordSummary.py
1 # Config
2 from Components.config import ConfigYesNo, NoSave
3
4 # Plugin internal
5 from Plugins.Extensions.PushService.__init__ import _
6 from Plugins.Extensions.PushService.PluginBase import PluginBase
7
8 # Plugin specific
9 import NavigationInstance
10 from time import localtime, strftime
11
12
13 SUBJECT = _("Record Summary")
14 BODY    = _("Finished record list:\n%s")
15 TAG     = _("FinishedTimerPushed")
16
17
18 class RecordSummary(PluginBase):
19         
20         ForceSingleInstance = True
21         
22         def __init__(self):
23                 # Is called on instance creation
24                 PluginBase.__init__(self)
25                 self.timers = []
26                 
27                 # Default configuration
28                 self.setOption( 'remove_timer', NoSave(ConfigYesNo( default = False )), _("Remove finished timer(s) only after ") )
29
30         def run(self):
31                 # Return Header, Body, Attachment
32                 # If empty or none is returned, nothing will be sent
33                 # Search finished timers
34                 self.timers = []
35                 text = ""
36                 for timer in NavigationInstance.instance.RecordTimer.processed_timers:
37                         if not timer.disabled and TAG not in timer.tags:
38                                 text += str(timer.name) + "\t" \
39                                                         + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \
40                                                         + strftime(_("%H:%M"), localtime(timer.end)) + "\t" \
41                                                         + str(timer.service_ref and timer.service_ref.getServiceName() or "") \
42                                                         + "\n"
43                                 self.timers.append( timer )
44                 if self.timers and text:
45                         return SUBJECT, BODY % text
46                 else:
47                         return None
48
49         # Callback functions
50         def success(self):
51                 # Called after successful sending the message
52                 if self.getValue('remove_timer'):
53                         # Remove finished timers
54                         for timer in self.timers[:]:
55                                 if timer in NavigationInstance.instance.RecordTimer.processed_timers:
56                                         NavigationInstance.instance.RecordTimer.processed_timers.remove(timer)
57                                 self.timers.remove(timer)
58                 else:
59                         # Set tag to avoid resending it
60                         for timer in self.timers[:]:
61                                 timer.tags.append(TAG)
62                                 NavigationInstance.instance.RecordTimer.saveTimer()
63                                 self.timers.remove(timer)
64
65         def error(self):
66                 # Called after message sent has failed
67                 self.timers = []