Introduction of localization including german messages
[vuplus_dvbapp-plugin] / autotimer / src / plugin.py
1 # for localized messages
2 from . import _
3
4 # GUI (Screens)
5 from Screens.MessageBox import MessageBox
6
7 # Config
8 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
9         ConfigNumber, ConfigSelection
10
11 # Initialize Configuration
12 config.plugins.autotimer = ConfigSubsection()
13 config.plugins.autotimer.autopoll = ConfigEnableDisable(default = False)
14 config.plugins.autotimer.interval = ConfigNumber(default = 3)
15 config.plugins.autotimer.refresh = ConfigSelection(choices = [
16                 ("none", _("None")),
17                 ("auto", _("Only AutoTimers created during this Session")),
18                 ("all", _("All non-repeating Timers"))
19         ], default = "none"
20 )
21 config.plugins.autotimer.try_guessing = ConfigEnableDisable(default = True)
22
23 autotimer = None
24 autopoller = None
25
26 # Autostart
27 def autostart(reason, **kwargs):
28         global autotimer
29         global autopoller
30
31         # Startup
32         if config.plugins.autotimer.autopoll.value and reason == 0:
33                 # Initialize AutoTimer
34                 from AutoTimer import AutoTimer
35                 autotimer = AutoTimer()
36
37                 # Start Poller
38                 from AutoPoller import AutoPoller
39                 autopoller = AutoPoller()
40                 autopoller.start()
41         # Shutdown
42         elif reason == 1:
43                 # Stop Poller
44                 if autopoller is not None:
45                         # We might shutdown when configuring, timer won't be running then
46                         try:
47                                 autopoller.stop()
48                         except ValueError, ve:
49                                 pass
50
51                         autopoller = None
52
53                 if autotimer is not None:
54                         # Save xml
55                         autotimer.writeXml()
56
57                         # Remove AutoTimer
58                         autotimer = None
59
60 # Mainfunction
61 def main(session, **kwargs):
62         global autotimer
63         global autopoller
64
65         if autotimer is None:
66                 from AutoTimer import AutoTimer
67                 autotimer = AutoTimer()
68
69         from xml.parsers.expat import ExpatError
70
71         try:
72                 autotimer.readXml()
73         except ExpatError, ee:
74                 session.open(
75                         MessageBox,
76                         "Your config file is not well-formed.\nError parsing in line: %s" % (ee.lineno),
77                         type = MessageBox.TYPE_ERROR,
78                         timeout = 10
79                 )
80                 return
81
82         # Do not run in background while editing, this might screw things up
83         if autopoller is not None:
84                 autopoller.stop()
85
86         from AutoTimerOverview import AutoTimerOverview
87         session.openWithCallback(
88                 editCallback,
89                 AutoTimerOverview,
90                 autotimer
91         )
92
93 def editCallback(session):
94         global autotimer
95         global autopoller
96
97         # XXX: canceling of GUI (Overview) won't affect config values which might have been changed - is this intended?
98
99         # Don't parse EPG if editing was canceled
100         if session is not None:
101                 # Poll EPGCache
102                 ret = autotimer.parseEPG()
103                 session.open(
104                         MessageBox,
105                         "Found a total of %d matching Events.\n%d Timer were added and %d modified.." % (ret[0], ret[1], ret[2]),
106                         type = MessageBox.TYPE_INFO,
107                         timeout = 10
108                 )
109
110         # Start autopoller again if wanted
111         if config.plugins.autotimer.autopoll.value:
112                 if autopoller is None:
113                         from AutoPoller import AutoPoller
114                         autopoller = AutoPoller()
115                 autopoller.start(initial = False)
116         # Remove instance if not running in background
117         else:
118                 autopoller = None
119
120                 # Save xml (as long as we did not cancel)
121                 session and autotimer.writeXml()
122                 autotimer = None
123
124 # Movielist
125 def movielist(session, service, **kwargs):
126         from AutoTimerEditor import addAutotimerFromService
127         addAutotimerFromService(session, service)
128
129 def Plugins(**kwargs):
130         from Plugins.Plugin import PluginDescriptor
131
132         return [
133                 PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart),
134                 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_PLUGINMENU, icon = "plugin.png", fnc = main),
135                 PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main),
136                 PluginDescriptor(name="AutoTimer", description= _("Add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist)
137         ]