Enable the User to close 'New Messages'-Popup via exit
[enigma2-plugins.git] / simplerss / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2
3 from RSSSetup import RSSSetup
4 from RSSScreens import RSSOverview
5 from RSSPoller import RSSPoller
6
7 from Components.config import config, ConfigSubsection, ConfigSubList, ConfigEnableDisable, ConfigInteger, ConfigText
8
9 # Initialize Configuration
10 config.plugins.simpleRSS = ConfigSubsection()
11 config.plugins.simpleRSS.show_new = ConfigEnableDisable(default=True)
12 config.plugins.simpleRSS.interval = ConfigInteger(default=10, limits=(5, 300))
13 config.plugins.simpleRSS.feedcount = ConfigInteger(default=0)
14 config.plugins.simpleRSS.autostart = ConfigEnableDisable(default=False)
15 config.plugins.simpleRSS.keep_running = ConfigEnableDisable(default=True)
16 config.plugins.simpleRSS.feed = ConfigSubList()
17 for i in range(0, config.plugins.simpleRSS.feedcount.value):
18         config.plugins.simpleRSS.feed.append(ConfigSubsection())
19         config.plugins.simpleRSS.feed[i].uri = ConfigText(default="http://", fixed_size = False)
20         config.plugins.simpleRSS.feed[i].autoupdate = ConfigEnableDisable(default=True)
21
22 # Global Poller-Object
23 rssPoller = None
24
25 # Main Function
26 def main(session, **kwargs):
27         # Get Global rssPoller-Object
28         global rssPoller
29
30         # Create one if we have none (no autostart)
31         if rssPoller is None:
32                 rssPoller = RSSPoller(session)
33
34         # Show Overview when we have feeds
35         if len(rssPoller.feeds):
36                 session.openWithCallback(closed, RSSOverview, rssPoller)
37         # Show Setup otherwise
38         else:
39                 session.openWithCallback(closed, RSSSetup, rssPoller)
40
41 # Plugin window has been closed
42 def closed():
43         # If SimpleRSS should not run in Background: shutdown
44         if not config.plugins.simpleRSS.autostart.value and not config.plugins.simpleRSS.keep_running.value:
45                 # Get Global rssPoller-Object
46                 global rssPoller
47                 
48                 rssPoller.shutdown()
49                 rssPoller = None
50
51 # Autostart
52 def autostart(reason, **kwargs):
53         global rssPoller
54
55         # Instanciate when autostarting active, session present and enigma2 is launching
56         if config.plugins.simpleRSS.autostart.value and kwargs.has_key("session") and reason == 0:
57                 rssPoller = RSSPoller(kwargs["session"])
58         elif reason == 1:
59                 if rssPoller is not None:
60                         rssPoller.shutdown()
61                         rssPoller = None
62
63 def Plugins(**kwargs):
64         return [ PluginDescriptor(name="RSS Reader", description="A simple to use RSS reader", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
65                 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
66                 PluginDescriptor(name="View RSS", description="Let's you view current RSS entries", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main) ]