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, 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)
72 self.onClose.append(self.abort)
74 self.rssPoller = rssPoller
76 simpleRSS = config.plugins.simpleRSS
78 # Create List of all Feeds
80 getConfigListEntry(_("Feed"), x.uri)
81 for x in simpleRSS.feed
84 # Attach notifier to autostart and append ConfigListEntry to List
85 simpleRSS.autostart.addNotifier(self.autostartChanged, initial_call = False)
86 self.list.append(getConfigListEntry(_("Start automatically with Enigma2"), simpleRSS.autostart))
88 # Save keep_running in instance as we want to dynamically add/remove it
89 self.keep_running = getConfigListEntry(_("Keep running in background"), simpleRSS.keep_running)
90 if not simpleRSS.autostart.value:
91 self.list.append(self.keep_running)
93 # Append Last two config Elements
94 self.list.append(getConfigListEntry(_("Show new Messages as"), simpleRSS.update_notification))
95 self.list.append(getConfigListEntry(_("Update Interval (min)"), simpleRSS.interval))
97 # Initialize ConfigListScreen
98 ConfigListScreen.__init__(self, self.list, session)
100 self["key_red"] = Button(_("Cancel"))
101 self["key_green"] = Button(_("OK"))
102 self["key_yellow"] = Button(_("New"))
103 self["key_blue"] = Button(_("Delete"))
105 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
109 "save": self.keySave,
110 "cancel": self.keyCancel,
114 self.onLayoutFinish.append(self.setCustomTitle)
116 def setCustomTitle(self):
117 self.setTitle(_("Simple RSS Reader Setup"))
119 def autostartChanged(self, instance):
120 # Remove keep_running from list if autostart is active
122 self.list.remove(self.keep_running)
123 # Otherwise add it at third position from behind
125 self.list.insert(-2, self.keep_running)
127 # Assign new List to ConfigList
128 self["config"].setList(self.list)
131 from Screens.MessageBox import MessageBox
133 self.session.openWithCallback(
136 _("Really delete this entry?\nIt cannot be recovered!")
139 def deleteConfirm(self, result):
141 id = self["config"].instance.getCurrentIndex()
142 del config.plugins.simpleRSS.feed[id]
143 config.plugins.simpleRSS.feedcount.value -= 1
146 self["config"].setList(self.list)
149 id = self["config"].instance.getCurrentIndex()
150 self.session.openWithCallback(self.refresh, RSSFeedEdit, id)
153 # TODO: anything to be done here?
157 l = config.plugins.simpleRSS.feed
158 s = ConfigSubsection()
159 s.uri = ConfigText(default="http://", fixed_size = False)
160 s.autoupdate = ConfigEnableDisable(default=True)
164 self.session.openWithCallback(self.conditionalNew, RSSFeedEdit, id)
166 def conditionalNew(self):
167 id = len(config.plugins.simpleRSS.feed)-1
168 uri = config.plugins.simpleRSS.feed[id].uri
170 # Check if new feed differs from default
171 if uri.value == "http://":
172 del config.plugins.simpleRSS.feed[id]
174 self.list.insert(id, getConfigListEntry(_("Feed"), uri))
175 config.plugins.simpleRSS.feedcount.value = id+1
178 # Tell Poller to recreate List if present
179 if self.rssPoller is not None:
180 self.rssPoller.triggerReload()
181 ConfigListScreen.keySave(self)
184 print "[SimpleRSS] Closing Setup Dialog"
185 simpleRSS = config.plugins.simpleRSS
188 simpleRSS.autostart.notifiers.remove(self.autostartChanged)
190 # Keep feedcount sane
191 simpleRSS.feedcount.value = len(simpleRSS.feed)
192 simpleRSS.feedcount.save()
194 def addFeed(address, auto = False):
195 l = config.plugins.simpleRSS.feed
198 s = ConfigSubsection()
199 s.uri = ConfigText(default="http://", fixed_size = False)
200 s.autoupdate = ConfigEnableDisable(default=True)
203 s.uri.value = address
204 s.autoupdate.value = auto