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