PushService: Ignore zap timer
[enigma2-plugins.git] / pushservice / src / Controller / RecordSummary.py
1 #######################################################################
2 #
3 #    Push Service for Enigma-2
4 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=167779
6 #
7 #    This program is free software; you can redistribute it and/or
8 #    modify it under the terms of the GNU General Public License
9 #    as published by the Free Software Foundation; either version 2
10 #    of the License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #######################################################################
18
19 # Config
20 from Components.config import ConfigYesNo, NoSave
21
22 # Plugin internal
23 from Plugins.Extensions.PushService.__init__ import _
24 from Plugins.Extensions.PushService.ControllerBase import ControllerBase
25
26 # Plugin specific
27 import NavigationInstance
28 from time import localtime, strftime
29
30
31 # Constants
32 SUBJECT = _("Record Summary")
33 BODY    = _("Finished record list:\n%s")
34 TAG     = _("FinishedTimerPushed")
35
36
37 class RecordSummary(ControllerBase):
38         
39         ForceSingleInstance = True
40         
41         def __init__(self):
42                 # Is called on instance creation
43                 ControllerBase.__init__(self)
44                 self.timers = []
45                 
46                 # Default configuration
47                 self.setOption( 'remove_timer', NoSave(ConfigYesNo( default = False )), _("Remove finished timer(s)") )
48
49         def run(self, callback, errback):
50                 # At the end a plugin has to call one of the functions: callback or errback
51                 # Callback should return with at least one of the parameter: Header, Body, Attachment
52                 # If empty or none is returned, nothing will be sent
53                 self.timers = []
54                 text = ""
55                 for timer in NavigationInstance.instance.RecordTimer.processed_timers:
56                         if not timer.disabled and not timer.justplay and TAG not in timer.tags:
57                                 text += str(timer.name) + "\t" \
58                                                         + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \
59                                                         + strftime(_("%H:%M"), localtime(timer.end)) + "\t" \
60                                                         + str(timer.service_ref and timer.service_ref.getServiceName() or "") \
61                                                         + "\n"
62                                 self.timers.append( timer )
63                 if self.timers and text:
64                         callback( SUBJECT, BODY % text )
65                 else:
66                         callback()
67
68         # Callback functions
69         def callback(self):
70                 # Called after all services succeded
71                 if self.getValue('remove_timer'):
72                         # Remove finished timers
73                         for timer in self.timers[:]:
74                                 if timer in NavigationInstance.instance.RecordTimer.processed_timers:
75                                         NavigationInstance.instance.RecordTimer.processed_timers.remove(timer)
76                                 self.timers.remove(timer)
77                 else:
78                         # Set tag to avoid resending it
79                         for timer in self.timers[:]:
80                                 timer.tags.append(TAG)
81                                 NavigationInstance.instance.RecordTimer.saveTimer()
82                                 self.timers.remove(timer)
83
84         def errback(self):
85                 # Called after all services has returned, but at least one has failed
86                 self.timers = []