1
##########################################################################
2
# Copyright 2009 Carlos Ribeiro
4
# This file is part of Radio Tray
6
# Radio Tray is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 1 of the License, or
9
# (at your option) any later version.
11
# Radio Tray is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
19
##########################################################################
21
from Plugin import Plugin
25
from lib.common import APP_ICON, APPNAME
26
from events.EventManager import EventManager
28
class NotificationPlugin(Plugin):
31
super(NotificationPlugin, self).__init__()
36
def initialize(self, name, notification, eventSubscriber, provider, cfgProvider, mediator, tooltip):
39
self.notification = notification
40
self.eventSubscriber = eventSubscriber
41
self.provider = provider
42
self.cfgProvider = cfgProvider
43
self.mediator = mediator
44
self.tooltip = tooltip
49
self.lastMessage = None
50
self.eventSubscriber.bind(EventManager.NOTIFICATION, self.on_notification)
53
def on_notification(self, data):
54
self.notify(data['title'], data['message'])
57
def notify(self, title, message):
59
if self.lastMessage != message:
61
self.lastMessage = message
63
if self.notif == None:
65
if pynotify.init(APPNAME):
66
self.notif = pynotify.Notification(title, message)
67
self.notif.set_urgency(pynotify.URGENCY_LOW)
68
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(APP_ICON, 48, 48)
69
self.notif.set_icon_from_pixbuf(pixbuf)
70
self.notif.set_timeout(pynotify.EXPIRES_DEFAULT)
73
self.log.error('Error: there was a problem initializing the pynotify module')
76
self.notif.update(title, message)