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