-
Notifications
You must be signed in to change notification settings - Fork 0
/
growl.py
77 lines (57 loc) · 3.95 KB
/
growl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2009-2011 AG Projects. See LICENSE for details.
#
from Foundation import NSLocalizedString
import os
import Growl
from application.notification import NotificationCenter, IObserver
from application.python import Null
from application.python.types import Singleton
from zope.interface import implements
class GrowlNotifications(object):
__metaclass__ = Singleton
implements(IObserver)
notification_names = ('SMS Received', 'Chat Message Received', 'Missed Call', 'Audio Call Recorded', 'Voicemail Summary', 'New Contact Request')
def __init__(self):
dir = os.path.dirname(__file__)
appicon = Growl.Image.imageFromPath(os.path.join(dir, 'blink.icns'))
self.growl = Growl.GrowlNotifier('Blink', self.notification_names, applicationIcon=appicon )
self.growl.register()
notification_center = NotificationCenter()
notification_center.add_observer(self, name='GrowlGotSMS')
notification_center.add_observer(self, name='GrowlGotChatMessage')
notification_center.add_observer(self, name='GrowlMissedCall')
notification_center.add_observer(self, name='GrowlAudioSessionRecorded')
notification_center.add_observer(self, name='GrowlGotMWI')
notification_center.add_observer(self, name='GrowlContactRequest')
def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null)
handler(notification)
def _NH_GrowlContactRequest(self, notification):
title = NSLocalizedString("New Contact Request", "System notification title")
message = NSLocalizedString("%s has subscribed to my availability", "System notification body") % notification.data.watcher
self.growl.notify('New Contact Request', title, message)
def _NH_GrowlGotSMS(self, notification):
title = NSLocalizedString("SMS Received", "System notification title")
message = NSLocalizedString("From %s", "System notification body") % notification.data.sender + "\n\n" + notification.data.content
self.growl.notify('SMS Received', title, message)
def _NH_GrowlGotChatMessage(self, notification):
title = NSLocalizedString("Chat Message Received", "System notification title")
message = NSLocalizedString("From %s", "System notification body") % notification.data.sender + "\n\n" + notification.data.content
self.growl.notify('Chat Message Received', title, message)
def _NH_GrowlMissedCall(self, notification):
title = NSLocalizedString("Missed Call", "System notification title") + "(" + notification.data.streams + ")"
message = 'From %s\nat %s' % (notification.data.caller, notification.datetime.strftime("%Y-%m-%d %H:%M"))
self.growl.notify('Missed Call', title, message, sticky=True)
def _NH_GrowlAudioSessionRecorded(self, notification):
title = NSLocalizedString("Audio Call Recorded", "System notification title")
message = "%s\n" % notification.data.remote_party + NSLocalizedString("at ", "Time label") + notification.datetime.strftime("%Y-%m-%d %H:%M")
self.growl.notify('Audio Call Recorded', title, message, sticky=True)
def _NH_GrowlGotMWI(self, notification):
# new_messages will always be > 0 at this point
title = NSLocalizedString("New Voicemail Message", "System notification title") if notification.data.new_messages == 1 else NSLocalizedString("New Voicemail Messages", "System notification title")
if notification.data.old_messages > 0:
message = NSLocalizedString("You have %d new", "System notification body") % notification.data.new_messages + NSLocalizedString("and %d old voicemail messages", "System notification body") % notification.data.old_messages
else:
message = NSLocalizedString("You have %d new voicemail messages", "System notification body") % notification.data.new_messages
self.growl.notify('Voicemail Summary', title, message)
notifier = GrowlNotifications()