1 from Screens.Screen import Screen
2 from Components.config import config, ConfigSubsection, ConfigEnableDisable, \
3 ConfigText, getConfigListEntry
4 from Components.ConfigList import ConfigListScreen
5 from Components.Button import Button
6 from Components.ActionMap import ActionMap
8 class RSSFeedEdit(ConfigListScreen, Screen):
11 <screen name="RSSFeedEdit" position="100,100" size="550,120" title="Simple RSS Reader Setup" >
12 <widget name="config" position="20,10" size="510,75" scrollbarMode="showOnDemand" />
13 <ePixmap name="red" position="0,75" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
14 <ePixmap name="green" position="140,75" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
15 <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" />
16 <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" />
19 def __init__(self, session, id):
20 Screen.__init__(self, session)
23 getConfigListEntry(_("Autoupdate"), config.plugins.simpleRSS.feed[id].autoupdate),
24 getConfigListEntry(_("Feed URI"), config.plugins.simpleRSS.feed[id].uri)
27 ConfigListScreen.__init__(self, self.list, session)
29 self["key_red"] = Button(_("Cancel"))
30 self["key_green"] = Button(_("OK"))
32 self["setupActions"] = ActionMap(["SetupActions"],
35 "cancel": self.keyCancel
41 config.plugins.simpleRSS.feed[self.id].save()
42 config.plugins.simpleRSS.feed.save()
45 class RSSSetup(ConfigListScreen, Screen):
46 """Setup for SimpleRSS, quick-edit for Feed-URIs and settings present."""
48 <screen name="RSSSetup" position="100,100" size="550,400" title="Simple RSS Reader Setup" >
49 <widget name="config" position="20,10" size="510,350" scrollbarMode="showOnDemand" />
50 <ePixmap name="red" position="0,360" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
51 <ePixmap name="green" position="140,360" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
52 <ePixmap name="yellow" position="280,360" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
53 <ePixmap name="blue" position="420,360" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
54 <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" />
55 <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" />
56 <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" />
57 <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" />
60 def __init__(self, session, rssPoller = None):
61 Screen.__init__(self, session)
63 self.onClose.append(self.abort)
65 self.rssPoller = rssPoller
67 # Create List of all Feeds
69 getConfigListEntry(_("Feed"), config.plugins.simpleRSS.feed[i].uri)
70 for i in range(0, config.plugins.simpleRSS.feedcount.value)
73 # Attach notifier to autostart and append ConfigListEntry to List
74 config.plugins.simpleRSS.autostart.addNotifier(self.autostartChanged, initial_call = False)
75 self.list.append(getConfigListEntry(_("Start automatically with Enigma2"), config.plugins.simpleRSS.autostart))
77 # Save keep_running in instance as we want to dynamically add/remove it
78 self.keep_running = getConfigListEntry(_("Keep running in background"), config.plugins.simpleRSS.keep_running)
79 if not config.plugins.simpleRSS.autostart.value:
80 self.list.append(self.keep_running)
82 # Append Last two config Elements
83 self.list.append(getConfigListEntry(_("Show new Messages as"), config.plugins.simpleRSS.update_notification))
84 self.list.append(getConfigListEntry(_("Update Interval (min)"), config.plugins.simpleRSS.interval))
86 # Initialize ConfigListScreen
87 ConfigListScreen.__init__(self, self.list, session)
89 self["key_red"] = Button(_("Cancel"))
90 self["key_green"] = Button(_("OK"))
91 self["key_yellow"] = Button(_("New"))
92 self["key_blue"] = Button(_("Delete"))
94 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
99 "cancel": self.keyCancel,
103 def autostartChanged(self, instance):
104 # Remove keep_running from list if autostart is active
106 self.list.remove(self.keep_running)
107 # Otherwise add it at third position from behind
109 self.list.insert(-2, self.keep_running)
111 # Assign new List to ConfigList
112 self["config"].setList(self.list)
115 from Screens.MessageBox import MessageBox
117 self.session.openWithCallback(
120 _("Really delete this entry?\nIt cannot be recovered!")
123 def deleteConfirm(self, result):
125 id = self["config"].instance.getCurrentIndex()
126 del config.plugins.simpleRSS.feed[id]
127 config.plugins.simpleRSS.feedcount.value -= 1
130 self["config"].setList(self.list)
133 id = self["config"].instance.getCurrentIndex()
134 self.session.openWithCallback(self.refresh, RSSFeedEdit, id)
137 # TODO: anything to be done here?
141 id = len(config.plugins.simpleRSS.feed)
142 config.plugins.simpleRSS.feed.append(ConfigSubsection())
143 config.plugins.simpleRSS.feed[id].uri = ConfigText(default="http://", fixed_size = False)
144 config.plugins.simpleRSS.feed[id].autoupdate = ConfigEnableDisable(default=True)
145 self.session.openWithCallback(self.conditionalNew, RSSFeedEdit, id)
147 def conditionalNew(self):
148 id = len(config.plugins.simpleRSS.feed)-1
149 # Check if new feed differs from default
150 if config.plugins.simpleRSS.feed[id].uri.value == "http://":
151 del config.plugins.simpleRSS.feed[id]
153 self.list.insert(id, getConfigListEntry(_("Feed"), config.plugins.simpleRSS.feed[id].uri))
154 config.plugins.simpleRSS.feedcount.value = id+1
157 # Tell Poller to recreate List if present
158 if self.rssPoller is not None:
159 self.rssPoller.triggerReload()
160 ConfigListScreen.keySave(self)
163 print "[SimpleRSS] Closing Setup Dialog"
166 config.plugins.simpleRSS.autostart.notifiers.remove(self.autostartChanged)
168 # Keep feedcount sane
169 config.plugins.simpleRSS.feedcount.value = len(config.plugins.simpleRSS.feed)
170 config.plugins.simpleRSS.feedcount.save()
172 def addFeed(address, auto = False):
174 id = len(config.plugins.simpleRSS.feed)
177 config.plugins.simpleRSS.feed.append(ConfigSubsection())
178 config.plugins.simpleRSS.feed[id].uri = ConfigText(default="http://", fixed_size = False)
179 config.plugins.simpleRSS.feed[id].autoupdate = ConfigEnableDisable(default=True)
182 config.plugins.simpleRSS.feed[id].uri.value = address
183 config.plugins.simpleRSS.feed[id].autoupdate.value = auto
186 config.plugins.simpleRSS.feed.save()