1 # for localized messages
4 from Screens.Screen import Screen
5 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
6 ConfigText, getConfigListEntry
7 from Components.ConfigList import ConfigListScreen
8 from Components.Button import Button
9 from Components.ActionMap import ActionMap
11 class RSSFeedEdit(ConfigListScreen, Screen):
12 """Edit an RSS-Feed"""
14 <screen name="RSSFeedEdit" position="100,100" size="550,120" title="Simple RSS Reader Setup" >
15 <widget name="config" position="20,10" size="510,75" scrollbarMode="showOnDemand" />
16 <ePixmap name="red" position="0,75" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
17 <ePixmap name="green" position="140,75" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
18 <widget name="key_red" position="0,75" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
19 <widget name="key_green" position="140,75" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
22 def __init__(self, session, id):
23 Screen.__init__(self, session)
25 s = config.plugins.simpleRSS.feed[id]
27 getConfigListEntry(_("Autoupdate"), s.autoupdate),
28 getConfigListEntry(_("Feed URI"), s.uri)
31 ConfigListScreen.__init__(self, list, session)
33 self["key_red"] = Button(_("Cancel"))
34 self["key_green"] = Button(_("OK"))
36 self["setupActions"] = ActionMap(["SetupActions"],
39 "cancel": self.keyCancel
44 self.onLayoutFinish.append(self.setCustomTitle)
46 def setCustomTitle(self):
47 self.setTitle(_("Simple RSS Reader Setup"))
50 config.plugins.simpleRSS.feed[self.id].save()
51 config.plugins.simpleRSS.feed.save()
54 class RSSSetup(ConfigListScreen, Screen):
55 """Setup for SimpleRSS, quick-edit for Feed-URIs and settings present."""
57 <screen name="RSSSetup" position="100,100" size="550,400" title="Simple RSS Reader Setup" >
58 <widget name="config" position="20,10" size="510,350" scrollbarMode="showOnDemand" />
59 <ePixmap name="red" position="0,360" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
60 <ePixmap name="green" position="140,360" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
61 <ePixmap name="yellow" position="280,360" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
62 <ePixmap name="blue" position="420,360" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
63 <widget name="key_red" position="0,360" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
64 <widget name="key_green" position="140,360" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
65 <widget name="key_yellow" position="280,360" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
66 <widget name="key_blue" position="420,360" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
69 def __init__(self, session, rssPoller = None):
70 Screen.__init__(self, session)
71 self.rssPoller = rssPoller
74 config.plugins.simpleRSS.autostart.addNotifier(self.elementChanged, initial_call = False)
75 config.plugins.simpleRSS.enable_google_reader.addNotifier(self.elementChanged, initial_call = False)
77 # Initialize ConfigListScreen
78 ConfigListScreen.__init__(self, self.list, session)
80 self["key_red"] = Button(_("Cancel"))
81 self["key_green"] = Button(_("OK"))
82 self["key_yellow"] = Button(_("New"))
83 self["key_blue"] = Button(_("Delete"))
85 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
90 "cancel": self.keyCancel,
94 self.onLayoutFinish.append(self.setCustomTitle)
95 self.onClose.append(self.abort)
97 def setCustomTitle(self):
98 self.setTitle(_("Simple RSS Reader Setup"))
100 def createSetup(self):
101 simpleRSS = config.plugins.simpleRSS
103 # Create List of all Feeds
105 getConfigListEntry(_("Feed"), x.uri)
106 for x in simpleRSS.feed
109 list.append(getConfigListEntry(_("Start automatically with Enigma2"), simpleRSS.autostart))
111 # Save keep_running in instance as we want to dynamically add/remove it
112 self.keep_running = getConfigListEntry(_("Keep running in background"), simpleRSS.keep_running)
113 if not simpleRSS.autostart.value:
114 list.append(self.keep_running)
116 # Append Last two config Elements
118 getConfigListEntry(_("Show new Messages as"), simpleRSS.update_notification),
119 getConfigListEntry(_("Update Interval (min)"), simpleRSS.interval),
120 getConfigListEntry(_("Fetch feed from Google Reader?"), simpleRSS.enable_google_reader),
123 if simpleRSS.enable_google_reader.value:
125 getConfigListEntry(_("Google Username"), simpleRSS.google_username),
126 getConfigListEntry(_("Google Password"), simpleRSS.google_password),
131 def elementChanged(self, instance):
133 self["config"].setList(self.list)
136 from Screens.MessageBox import MessageBox
138 self.session.openWithCallback(
141 _("Really delete this entry?\nIt cannot be recovered!")
144 def deleteConfirm(self, result):
146 id = self["config"].getCurrentIndex()
147 del config.plugins.simpleRSS.feed[id]
148 config.plugins.simpleRSS.feedcount.value -= 1
151 self["config"].setList(self.list)
154 id = self["config"].getCurrentIndex()
155 if id < len(config.plugins.simpleRSS.feed):
156 self.session.openWithCallback(self.refresh, RSSFeedEdit, id)
159 # TODO: anything to be done here?
163 l = config.plugins.simpleRSS.feed
164 s = ConfigSubsection()
165 s.uri = ConfigText(default="http://", fixed_size = False)
166 s.autoupdate = ConfigEnableDisable(default=True)
170 self.session.openWithCallback(self.conditionalNew, RSSFeedEdit, id)
172 def conditionalNew(self):
173 id = len(config.plugins.simpleRSS.feed)-1
174 uri = config.plugins.simpleRSS.feed[id].uri
176 # Check if new feed differs from default
177 if uri.value == "http://":
178 del config.plugins.simpleRSS.feed[id]
180 config.plugins.simpleRSS.feedcount.value = id+1
182 self["config"].setList(self.list)
185 # Tell Poller to recreate List if present
186 if self.rssPoller is not None:
187 self.rssPoller.triggerReload()
188 ConfigListScreen.keySave(self)
191 print "[SimpleRSS] Closing Setup Dialog"
192 simpleRSS = config.plugins.simpleRSS
195 simpleRSS.autostart.notifiers.remove(self.elementChanged)
196 simpleRSS.enable_google_reader.notifiers.remove(self.elementChanged)
198 # Keep feedcount sane
199 simpleRSS.feedcount.value = len(simpleRSS.feed)
200 simpleRSS.feedcount.save()
202 def addFeed(address, auto = False):
203 l = config.plugins.simpleRSS.feed
206 s = ConfigSubsection()
207 s.uri = ConfigText(default="http://", fixed_size = False)
208 s.autoupdate = ConfigEnableDisable(default=True)
211 s.uri.value = address
212 s.autoupdate.value = auto