add "preview" type update_notification to notifications too instead of just displaying it
[enigma2-plugins.git] / simplerss / src / plugin.py
1 from Components.config import config, ConfigSubsection, ConfigSubList, \
2         ConfigEnableDisable, ConfigNumber, ConfigText, ConfigSelection
3
4 # Initialize Configuration
5 config.plugins.simpleRSS = ConfigSubsection()
6 config.plugins.simpleRSS.update_notification = ConfigSelection(
7         choices = [
8                 ("notification", _("Notification")),
9                 ("preview", _("Preview")),
10                 ("none", _("none"))
11         ],
12         default = "preview"
13 )
14 config.plugins.simpleRSS.interval = ConfigNumber(default=15)
15 config.plugins.simpleRSS.feedcount = ConfigNumber(default=0)
16 config.plugins.simpleRSS.autostart = ConfigEnableDisable(default=False)
17 config.plugins.simpleRSS.keep_running = ConfigEnableDisable(default=True)
18 config.plugins.simpleRSS.feed = ConfigSubList()
19 for i in range(0, config.plugins.simpleRSS.feedcount.value):
20         config.plugins.simpleRSS.feed.append(ConfigSubsection())
21         config.plugins.simpleRSS.feed[i].uri = ConfigText(default="http://", fixed_size = False)
22         config.plugins.simpleRSS.feed[i].autoupdate = ConfigEnableDisable(default=True)
23
24 # Global Poller-Object
25 rssPoller = None
26
27 # Main Function
28 def main(session, **kwargs):
29         # Get Global rssPoller-Object
30         global rssPoller
31
32         # Create one if we have none (no autostart)
33         if rssPoller is None:
34                 from RSSPoller import RSSPoller
35                 rssPoller = RSSPoller(session)
36
37         # Show Overview when we have feeds
38         if len(rssPoller.feeds):
39                 from RSSScreens import RSSOverview
40                 session.openWithCallback(closed, RSSOverview, rssPoller)
41         # Show Setup otherwise
42         else:
43                 from RSSSetup import RSSSetup
44                 session.openWithCallback(closed, RSSSetup, rssPoller)
45
46 # Plugin window has been closed
47 def closed():
48         # If SimpleRSS should not run in Background: shutdown
49         if not config.plugins.simpleRSS.autostart.value and \
50                 not config.plugins.simpleRSS.keep_running.value:
51
52                 # Get Global rssPoller-Object
53                 global rssPoller
54                 
55                 rssPoller.shutdown()
56                 rssPoller = None
57
58 # Autostart
59 def autostart(reason, **kwargs):
60         global rssPoller
61
62         # Instanciate when autostart active, session present and enigma2 is launching
63         if config.plugins.simpleRSS.autostart.value and \
64                 kwargs.has_key("session") and reason == 0:
65
66                 from RSSPoller import RSSPoller
67                 rssPoller = RSSPoller(kwargs["session"])
68         elif reason == 1:
69                 if rssPoller is not None:
70                         rssPoller.shutdown()
71                         rssPoller = None
72
73 # Filescan 
74 def filescan_open(item, session, **kwargs):
75         from RSSSetup import addFeed
76
77         # Add earch feed
78         for each in item:
79                 addFeed(each)
80
81         from Screens.MessageBox import MessageBox
82
83         # Display Message
84         session.open(
85                 MessageBox,
86                 _("%d Feed(s) were added to configuration.") % (len(item)),
87                 type = MessageBox.TYPE_INFO,
88                 timeout = 5
89         )
90
91 # Filescanner
92 def filescan(**kwargs):
93         from Components.Scanner import Scanner, ScanPath
94
95         # Overwrite checkFile to detect remote files
96         class RemoteScanner(Scanner):
97                 def checkFile(self, file):
98                         return file.path.startswith(("http://", "https://"))
99
100         return [
101                 RemoteScanner(
102                         mimetypes = ["application/rss+xml", "application/atom+xml"],
103                         paths_to_scan = 
104                                 [
105                                         ScanPath(path = "", with_subdirs = False),
106                                 ],
107                         name = "RSS-Reader",
108                         description = "Subscribe Newsfeed...",
109                         openfnc = filescan_open,
110                 )
111         ]
112
113 def Plugins(**kwargs):
114         from Plugins.Plugin import PluginDescriptor
115         return [ PluginDescriptor(name="RSS Reader", description="A simple to use RSS reader", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
116                 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
117                 PluginDescriptor(name="View RSS", description="Let's you view current RSS entries", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main),
118                 PluginDescriptor(where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)]