~ubuntu-branches/ubuntu/saucy/radiotray/saucy

« back to all changes in this revision

Viewing changes to data/plugins/NotificationPlugin.py

  • Committer: Package Import Robot
  • Author(s): Elías Alejandro Año Mendoza
  • Date: 2011-12-28 17:06:38 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20111228170638-cym2rxl7boqq8dxr
Tags: 0.7.1-1
* New upstream release
* debian/copyright
  + Added new copyright owners

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##########################################################################
 
2
# Copyright 2009 Carlos Ribeiro
 
3
#
 
4
# This file is part of Radio Tray
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
#
 
19
##########################################################################
 
20
 
 
21
from Plugin import Plugin
 
22
import gtk
 
23
import gobject
 
24
import pynotify
 
25
from lib.common import APP_ICON, APPNAME
 
26
from events.EventManager import EventManager
 
27
 
 
28
class NotificationPlugin(Plugin):
 
29
 
 
30
    def __init__(self):
 
31
        super(NotificationPlugin, self).__init__()
 
32
 
 
33
    def getName(self):
 
34
        return self.name
 
35
 
 
36
    def initialize(self, name, notification, eventSubscriber, provider, cfgProvider, mediator, tooltip):
 
37
    
 
38
        self.name = name
 
39
        self.notification = notification
 
40
        self.eventSubscriber = eventSubscriber
 
41
        self.provider = provider
 
42
        self.cfgProvider = cfgProvider
 
43
        self.mediator = mediator
 
44
        self.tooltip = tooltip
 
45
        
 
46
 
 
47
    def activate(self):
 
48
        self.notif = None
 
49
        self.lastMessage = None
 
50
        self.eventSubscriber.bind(EventManager.NOTIFICATION, self.on_notification)
 
51
 
 
52
 
 
53
    def on_notification(self, data):
 
54
        self.notify(data['title'], data['message'])
 
55
 
 
56
 
 
57
    def notify(self, title, message):
 
58
 
 
59
        if self.lastMessage != message:
 
60
 
 
61
            self.lastMessage = message
 
62
            
 
63
            if self.notif == None:
 
64
        
 
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)
 
71
                    self.notif.show()
 
72
                else:
 
73
                    self.log.error('Error: there was a problem initializing the pynotify module')
 
74
            
 
75
            else:
 
76
                self.notif.update(title, message)
 
77
                self.notif.show()