PushService: Initial release
[enigma2-plugins.git] / pushservice / src / Plugins / DeactivatedTimers.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 SUBJECT = _("Found deactivated timer(s)")
13 BODY    = _("Deactivated timer list:\n%s")
14 TAG     = _("DeactivatedTimerPushed")
15
16
17 class DeactivatedTimers(PluginBase):
18         
19         ForceSingleInstance = True
20         
21         def __init__(self):
22                 # Is called on instance creation
23                 PluginBase.__init__(self)
24                 self.timers = []
25                 
26                 # Default configuration
27                 self.setOption( 'remove_timer', NoSave(ConfigYesNo( default = False )), _("Remove deactivated timer(s)") )
28
29         def run(self):
30                 # Return Header, Body, Attachment
31                 # If empty or none is returned, nothing will be sent
32                 # Search deactivated timers
33                 self.timers = []
34                 text = ""
35                 for timer in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers:
36                         if timer.disabled and TAG not in timer.tags:
37                                 text += str(timer.name) + "    " \
38                                                         + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \
39                                                         + strftime(_("%H:%M"), localtime(timer.end)) + "    " \
40                                                         + str(timer.service_ref and timer.service_ref.getServiceName() or "") \
41                                                         + "\n"
42                                 self.timers.append( timer )
43                 if self.timers and text:
44                         return SUBJECT, BODY % text
45                 else:
46                         return None
47
48         # Callback functions
49         def success(self):
50                 # Called after successful sending the message
51                 if self.getValue('remove_timer'):
52                         # Remove deactivated timers
53                         for timer in self.timers[:]:
54                                 if timer in NavigationInstance.instance.RecordTimer.processed_timers:
55                                         NavigationInstance.instance.RecordTimer.processed_timers.remove(timer)
56                                 elif timer in NavigationInstance.instance.RecordTimer.timer_list:
57                                         NavigationInstance.instance.RecordTimer.timer_list.remove(timer)
58                                 self.timers.remove(timer)
59                 else:
60                         # Set tag to avoid resending it
61                         for timer in self.timers[:]:
62                                 timer.tags.append(TAG)
63                                 NavigationInstance.instance.RecordTimer.saveTimer()
64                                 self.timers.remove(timer)
65
66         def error(self):
67                 # Called after message sent has failed
68                 self.timers = []