1 from Plugins.Plugin import PluginDescriptor
3 from Tools import Notifications
5 from Screens.Setup import SetupSummary
6 from Screens.Screen import Screen
7 from Components.ActionMap import ActionMap
8 from Components.config import config, getConfigListEntry, ConfigSubsection, \
9 ConfigText, ConfigPassword, ConfigYesNo, ConfigSelection, ConfigSet, \
10 ConfigSubList, ConfigNumber, NoSave
11 from Components.ConfigList import ConfigListScreen
12 from Components.Sources.StaticText import StaticText
14 from GrowleeConnection import gotNotification, emergencyDisable, growleeConnection
16 from . import NOTIFICATIONID
18 growlee = ConfigSubsection()
19 config.plugins.growlee = growlee
20 growlee.hostcount = ConfigNumber(default=0)
21 growlee.hosts = ConfigSubList()
24 s = ConfigSubsection()
25 s.name = ConfigText(default=name, fixed_size=False)
26 s.enable_incoming = ConfigYesNo(default=False)
27 s.enable_outgoing = ConfigYesNo(default=False)
28 s.address = ConfigText(fixed_size=False)
29 s.password = ConfigPassword()
30 s.protocol = ConfigSelection(default="growl", choices=[("growl", "Growl"), ("snarl", "Snarl"), ("prowl", "Prowl"), ("syslog", "Syslog UDP")])
31 s.level = ConfigSelection(default="-1", choices=[("-1", _("Low (Yes/No)")), ("0", _("Normal (Information)")), ("1", _("High (Warning)")), ("2", _("Highest (Emergency)"))])
32 s.blacklist = ConfigSet(choices=[])
33 config.plugins.growlee.hosts.append(s)
37 while i < growlee.hostcount.value:
41 # XXX: change to new config format
42 # NOTE: after some time, remove this and hardcode default length to 1
43 # since internally we assume to have at least 1 host configured
44 if growlee.hostcount.value == 0:
45 growlee.enable_outgoing = ConfigYesNo(default=False)
46 growlee.enable_incoming = ConfigYesNo(default=False)
47 growlee.address = ConfigText(fixed_size=False)
48 growlee.password = ConfigPassword()
49 password = growlee.password.value
50 growlee.prowl_api_key = ConfigText()
51 growlee.protocol = ConfigSelection(default="growl", choices=[("growl", "Growl"), ("snarl", "Snarl"), ("prowl", "Prowl")])
52 growlee.level = ConfigSelection(default="-1", choices=[("-1", _("Low (Yes/No)")), ("0", _("Normal (Information)")), ("1", _("High (Warning)")), ("2", _("Highest (Emergency)"))])
53 growlee.blacklist = ConfigSet(choices=[])
54 if growlee.protocol.value == "prowl":
55 password = growlee.prowl_api_key.value
57 s = addHost(_("Converted connection"))
58 s.enable_incoming.value = growlee.enable_incoming.value
59 s.enable_outgoing.value = growlee.enable_outgoing.value
60 s.address.value = growlee.address.value
61 s.password.value = password
62 s.protocol.value = growlee.protocol.value
63 s.level.value = growlee.level.value
64 s.blacklist.value = growlee.blacklist.value
66 growlee.enable_incoming.value = False
67 growlee.enable_outgoing.value = False
68 growlee.address.value = ""
69 growlee.password.value = ""
70 growlee.prowl_api_key.value = ""
71 growlee.protocol.value = "growl"
72 growlee.level.value = "-1"
73 growlee.blacklist.value = []
75 growlee.hostcount.value += 1
81 class GrowleeConfiguration(Screen, ConfigListScreen):
83 <screen name="RSSSetup" position="center,center" size="560,400" title="Simple RSS Reader Setup" >
84 <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
85 <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
86 <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
87 <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
88 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
89 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
90 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
91 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
92 <widget name="config" position="5,45" size="550,350" scrollbarMode="showOnDemand" />
95 def __init__(self, session):
96 Screen.__init__(self, session)
99 self["key_red"] = StaticText(_("Cancel"))
100 self["key_green"] = StaticText(_("OK"))
101 self["key_yellow"] = StaticText(_("New"))
102 self["key_blue"] = StaticText(_("Delete"))
105 self.setup_title = "Growlee Configuration"
106 self.onChangedEntry = []
109 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
113 "cancel": self.keyCancel,
114 "save": self.keySave,
117 self.hostElement = NoSave(ConfigSelection(choices=[(x, x.name.value) for x in config.plugins.growlee.hosts]))
118 self.hostElement.addNotifier(self.setupList, initial_call=False)
119 ConfigListScreen.__init__(
123 on_change=self.changed
125 self.cur = self.hostElement.value
132 from Screens.MessageBox import MessageBox
134 self.session.openWithCallback(
137 _("Really delete this entry?\nIt cannot be recovered!")
140 def deleteConfirm(self, result):
141 if result and config.plugins.growlee.hostcount.value > 0:
142 config.plugins.growlee.hostcount.value -= 1
143 config.plugins.growlee.hosts.remove(self.cur)
144 self.hostElement.setChoices([(x, x.name.value) for x in config.plugins.growlee.hosts])
145 self.cur = self.hostElement.value
148 self.cur = addHost(_("New connection"))
149 config.plugins.growlee.hostcount.value += 1
150 self.hostElement.setChoices([(x, x.name.value) for x in config.plugins.growlee.hosts])
151 self.hostElement.setValue(self.cur)
154 for x in self.onChangedEntry:
157 def setupList(self, *args):
159 if self.setupList in last.protocol.notifiers:
160 last.protocol.notifiers.remove(self.setupList)
161 cur = self.hostElement.value
163 cur.protocol.notifiers.append(self.setupList)
166 getConfigListEntry(_("Host"), self.hostElement),
167 getConfigListEntry(_("Name"), cur.name),
168 getConfigListEntry(_("Type"), cur.protocol),
169 getConfigListEntry(_("Minimum Priority"), cur.level),
170 getConfigListEntry(_("Send Notifications?"), cur.enable_outgoing),
173 proto = cur.protocol.value
175 l.append(getConfigListEntry(_("API Key"), cur.password))
178 getConfigListEntry(_("Receive Notifications?"), cur.enable_incoming),
179 getConfigListEntry(_("Address"), cur.address),
183 getConfigListEntry(_("Password"), cur.password)
186 self["config"].list = l
188 def getCurrentEntry(self):
189 cur = self["config"].getCurrent()
190 return cur and cur[0]
192 def getCurrentValue(self):
193 cur = self["config"].getCurrent()
194 return cur and str(cur[1].getText())
196 def createSummary(self):
199 def cancelConfirm(self):
200 ConfigListScreen.cancelConfirm(self)
201 config.plugins.growlee.cancel()
204 config.plugins.growlee.save()
205 if self["config"].isChanged():
206 def doConnect(*args, **kwargs):
207 growleeConnection.listen()
209 d = growleeConnection.stop()
211 d.addCallback(doConnect).addErrback(emergencyDisable)
219 if self.setupList in self.cur.protocol.notifiers:
220 self.cur.protocol.notifiers.remove(self.setupList)
223 def configuration(session, **kwargs):
224 session.open(GrowleeConfiguration)
226 def autostart(**kwargs):
227 # NOTE: we need to be the first one to be notified since other listeners
228 # may remove the notifications from the list for good
229 Notifications.notificationAdded.insert(0, gotNotification)
231 growleeConnection.listen()
233 def Plugins(**kwargs):
236 where=PluginDescriptor.WHERE_SESSIONSTART,
241 description=_("Configure Growlee"),
242 where=PluginDescriptor.WHERE_PLUGINMENU,