annotate src/gaim-notifications-example @ 13951:614c56622453

[gaim-migrate @ 16496] Rename gaim_buffer.c and .h to circbuffer.c and .h committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 16 Jul 2006 19:08:31 +0000
parents 13b7e59a0759
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13765
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
1 #!/usr/bin/env python
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
2
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
3 # This is a simple gaim notification server.
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
4 # It shows notifications when your buddy signs on or you get an IM message.
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
5 #
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
6 # This script requires Python 2.4 and PyGTK bindings
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
7 #
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
8 # Note that all function names are resolved dynamically, no
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
9 # gaim-specific library is needed.
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
10
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
11 import dbus
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
12 import dbus.glib
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
13 import dbus.decorators
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
14 import gobject
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
15 import os
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
16
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
17 def ensureimconversation(conversation, account, name):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
18 if conversation != 0:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
19 return conversation
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
20 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
21 # 1 = GAIM_CONV_IM
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
22 return gaim.GaimConversationNew(1, account, name)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
23
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
24 def receivedimmsg(account, name, message, conversation, flags):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
25 buddy = gaim.GaimFindBuddy(account, name)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
26 if buddy != 0:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
27 alias = gaim.GaimBuddyGetAlias(buddy)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
28 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
29 alias = name
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
30
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
31 text = "%s says %s" % (alias, message)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
32 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
33 "'So what?','Show me',Close,Abuse", text)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
34
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
35 if code == 101: # so what?
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
36 pass
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
37 else:
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
38 conversation = ensureimconversation(conversation, account, name)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
39
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
40 if code == 102: # show me
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
41 window = gaim.GaimConversationGetWindow(conversation)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
42 gaim.GaimConvWindowRaise(window)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
43
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
44 if code == 103: # close
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
45 gaim.GaimConversationDestroy(conversation)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
46
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
47 if code == 104: # abuse
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
48 im = gaim.GaimConversationGetImData(conversation)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
49 gaim.GaimConvImSend(im, "Go away you f...")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
50
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
51
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
52 def buddysignedon(buddyid):
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
53 alias = gaim.GaimBuddyGetAlias(buddyid)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
54 text = "%s is online" % alias
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
55
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
57 "'So what?','Let's talk'", text)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
58
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
59 if code == 101: # so what?
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
60 pass
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
61
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
62 if code == 102: # talk
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
63 name = gaim.GaimBuddyGetName(buddyid)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
64 account = gaim.GaimBuddyGetAccount(buddyid)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
65 gaim.GaimConversationNew(1, account, name)
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
66
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
67
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
68 bus = dbus.SessionBus()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
69 obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
70 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
71
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
72 bus.add_signal_receiver(receivedimmsg,
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
73 dbus_interface = "net.sf.gaim.GaimInterface",
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
74 signal_name = "ReceivedImMsg")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
75
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
76 bus.add_signal_receiver(buddysignedon,
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
77 dbus_interface = "net.sf.gaim.GaimInterface",
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
78 signal_name = "BuddySignedOn")
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
79
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
80 print "This is a simple gaim notification server."
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
81 print "It shows notifications when your buddy signs on or you get an IM message."
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
82
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
83 loop = gobject.MainLoop()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
84 loop.run()
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
85
13b7e59a0759 [gaim-migrate @ 16177]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
86