plugin.py split up,\nfeed overview and single feed view in different screens,\nyellow...
[enigma2-plugins.git] / simplerss / src / SimpleRSSSetup.py
1 from Screens.Screen import Screen
2 from Components.config import config, ConfigSubsection, ConfigSubList, ConfigEnableDisable, ConfigInteger, ConfigText, getConfigListEntry
3 from Components.ConfigList import ConfigListScreen
4 from Components.Button import Button
5 from Components.ActionMap import ActionMap
6
7 class SimpleRSSFeedEdit(ConfigListScreen, Screen):
8         skin = """
9                 <screen name="SimpleRSSFeedEdit" position="100,100" size="550,120" title="Simple RSS Reader Setup" >
10                         <widget name="config" position="20,10" size="510,75" scrollbarMode="showOnDemand" />
11                         <ePixmap name="red"    position="0,75"   zPosition="4" size="140,40" pixmap="key_red-fs8.png" transparent="1" alphatest="on" />
12                         <ePixmap name="green"  position="140,75" zPosition="4" size="140,40" pixmap="key_green-fs8.png" transparent="1" alphatest="on" />
13                         <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" />
14                         <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" />
15                 </screen>"""
16
17         def __init__(self, session, id):
18                 Screen.__init__(self, session)
19
20                 self.list = [ getConfigListEntry(_("Autoupdate: "), config.plugins.simpleRSS.feed[id].autoupdate), getConfigListEntry(_("Feed URI: "), config.plugins.simpleRSS.feed[id].uri) ]
21
22                 ConfigListScreen.__init__(self, self.list, session)
23
24                 self["key_red"] = Button(_("Cancel"))
25                 self["key_green"] = Button(_("OK"))
26
27                 self["setupActions"] = ActionMap(["SetupActions"],
28                 {
29                         "save": self.save,
30                         "cancel": self.keyCancel
31                 }, -1)
32
33                 self.id = id
34
35         def save(self):
36                 config.plugins.simpleRSS.feed[self.id].save()
37                 config.plugins.simpleRSS.feed.save()
38                 self.close()
39
40 class SimpleRSSSetup(ConfigListScreen, Screen):
41         skin = """
42                 <screen name="SimpleRSSSetup" position="100,100" size="550,400" title="Simple RSS Reader Setup" >
43                         <widget name="config"  position="20,10" size="510,350" scrollbarMode="showOnDemand" />
44                         <ePixmap name="red"    position="0,360"   zPosition="4" size="140,40" pixmap="key_red-fs8.png" transparent="1" alphatest="on" />
45                         <ePixmap name="green"  position="140,360" zPosition="4" size="140,40" pixmap="key_green-fs8.png" transparent="1" alphatest="on" />
46                         <ePixmap name="yellow" position="280,360" zPosition="4" size="140,40" pixmap="key_yellow-fs8.png" transparent="1" alphatest="on" />
47                         <ePixmap name="blue"   position="420,360" zPosition="4" size="140,40" pixmap="key_blue-fs8.png" transparent="1" alphatest="on" />
48                         <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" />
49                         <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" />
50                         <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" />
51                         <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" />
52                 </screen>"""
53
54         def __init__(self, session, rssPoller = None):
55                 Screen.__init__(self, session)
56
57                 self.onClose.append(self.abort)
58
59                 self.rssPoller = rssPoller
60
61                 # nun erzeugen wir eine liste von elementen fuer die menu liste.
62                 self.list = [ ]
63                 for i in range(0, config.plugins.simpleRSS.feedcount.value):
64                         self.list.append(getConfigListEntry(_("Feed: "), config.plugins.simpleRSS.feed[i].uri))
65
66                 self.list.append(getConfigListEntry(_("Show new Messages: "), config.plugins.simpleRSS.show_new))
67                 self.list.append(getConfigListEntry(_("Update Interval (min): "), config.plugins.simpleRSS.interval))
68
69                 # die liste selbst
70                 ConfigListScreen.__init__(self, self.list, session)
71
72                 self["key_red"] = Button(_("Cancel"))
73                 self["key_green"] = Button(_("OK"))
74                 self["key_yellow"] = Button(_("New"))
75                 self["key_blue"] = Button(_("Delete"))
76
77                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
78                 {
79                         "blue": self.delete,
80                         "yellow": self.new,
81                         "save": self.keySave,
82                         "cancel": self.keyCancel,
83                         "ok": self.ok
84                 }, -1)
85         
86         def delete(self):
87                 self.session.openWithCallback(self.deleteConfirm, MessageBox, "Really delete this entry?\nIt cannot be recovered!")
88
89         def deleteConfirm(self, result):
90                 if result:
91                         id = self["config"].instance.getCurrentIndex()
92                         del config.plugins.simpleRSS.feed[id]
93                         config.plugins.simpleRSS.feedcount.value -= 1
94                         self.list.pop(id)
95                         # redraw list
96                         self["config"].setList(self.list)
97
98         def ok(self):
99                 id = self["config"].instance.getCurrentIndex()
100                 self.session.openWithCallback(self.refresh, SimpleRSSFeedEdit, id)
101
102         def refresh(self):
103                 # TODO: anything to be done here?
104                 pass
105
106         def new(self):
107                 id = len(config.plugins.simpleRSS.feed)
108                 config.plugins.simpleRSS.feed.append(ConfigSubsection())
109                 config.plugins.simpleRSS.feed[id].uri = ConfigText(default="http://", fixed_size = False)
110                 config.plugins.simpleRSS.feed[id].autoupdate = ConfigEnableDisable(default=True)
111                 self.session.openWithCallback(self.conditionalNew, SimpleRSSFeedEdit, id)
112
113         def conditionalNew(self):
114                 id = len(config.plugins.simpleRSS.feed)-1
115                 # Check if new feed differs from default
116                 if config.plugins.simpleRSS.feed[id].uri.value == "http://":
117                         del config.plugins.simpleRSS.feed[id]
118                 else:
119                         self.list.insert(id, getConfigListEntry(_("Feed: "), config.plugins.simpleRSS.feed[id].uri))
120                         config.plugins.simpleRSS.feedcount.value = id+1
121
122         def keySave(self):
123                 if self.rssPoller is not None:
124                         self.rssPoller.triggerReload()
125                 ConfigListScreen.keySave(self)
126
127         def abort(self):
128                 print "[SimpleRSS] Closing Setup Dialog"
129                 # Keep feedcount sane
130                 config.plugins.simpleRSS.feedcount.value = len(config.plugins.simpleRSS.feed)
131                 config.plugins.simpleRSS.feedcount.save()