Mercurial > pidgin
comparison libpurple/purple-notifications-example @ 16143:598b1b15b199
Trac Ticket #149 from JensenDied
This patch does a rename of our DBus stuff.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 18:09:14 +0000 |
parents | c6e563dfaa7a |
children | 61c2d36a38a3 |
comparison
equal
deleted
inserted
replaced
16142:74b2d576f458 | 16143:598b1b15b199 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # This is a simple gaim notification server. | 3 # This is a simple purple notification server. |
4 # It shows notifications when your buddy signs on or you get an IM message. | 4 # It shows notifications when your buddy signs on or you get an IM message. |
5 # | 5 # |
6 # This script requires Python 2.4 and PyGTK bindings | 6 # This script requires Python 2.4 and PyGTK bindings |
7 # | 7 # |
8 # Note that all function names are resolved dynamically, no | 8 # Note that all function names are resolved dynamically, no |
9 # gaim-specific library is needed. | 9 # purple-specific library is needed. |
10 | 10 |
11 import dbus | 11 import dbus |
12 import dbus.glib | 12 import dbus.glib |
13 import dbus.decorators | 13 import dbus.decorators |
14 import gobject | 14 import gobject |
17 def ensureimconversation(conversation, account, name): | 17 def ensureimconversation(conversation, account, name): |
18 if conversation != 0: | 18 if conversation != 0: |
19 return conversation | 19 return conversation |
20 else: | 20 else: |
21 # 1 = GAIM_CONV_IM | 21 # 1 = GAIM_CONV_IM |
22 return gaim.GaimConversationNew(1, account, name) | 22 return purple.PurpleConversationNew(1, account, name) |
23 | 23 |
24 def receivedimmsg(account, name, message, conversation, flags): | 24 def receivedimmsg(account, name, message, conversation, flags): |
25 buddy = gaim.GaimFindBuddy(account, name) | 25 buddy = purple.PurpleFindBuddy(account, name) |
26 if buddy != 0: | 26 if buddy != 0: |
27 alias = gaim.GaimBuddyGetAlias(buddy) | 27 alias = purple.PurpleBuddyGetAlias(buddy) |
28 else: | 28 else: |
29 alias = name | 29 alias = name |
30 | 30 |
31 text = "%s says %s" % (alias, message) | 31 text = "%s says %s" % (alias, message) |
32 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | 32 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", |
36 pass | 36 pass |
37 else: | 37 else: |
38 conversation = ensureimconversation(conversation, account, name) | 38 conversation = ensureimconversation(conversation, account, name) |
39 | 39 |
40 if code == 102: # show me | 40 if code == 102: # show me |
41 window = gaim.GaimConversationGetWindow(conversation) | 41 window = purple.PurpleConversationGetWindow(conversation) |
42 gaim.GaimConvWindowRaise(window) | 42 purple.PurpleConvWindowRaise(window) |
43 | 43 |
44 if code == 103: # close | 44 if code == 103: # close |
45 gaim.GaimConversationDestroy(conversation) | 45 purple.PurpleConversationDestroy(conversation) |
46 | 46 |
47 if code == 104: # abuse | 47 if code == 104: # abuse |
48 im = gaim.GaimConversationGetImData(conversation) | 48 im = purple.PurpleConversationGetImData(conversation) |
49 gaim.GaimConvImSend(im, "Go away you f...") | 49 purple.PurpleConvImSend(im, "Go away you f...") |
50 | 50 |
51 | 51 |
52 def buddysignedon(buddyid): | 52 def buddysignedon(buddyid): |
53 alias = gaim.GaimBuddyGetAlias(buddyid) | 53 alias = purple.PurpleBuddyGetAlias(buddyid) |
54 text = "%s is online" % alias | 54 text = "%s is online" % alias |
55 | 55 |
56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | 56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", |
57 "'So what?','Let's talk'", text) | 57 "'So what?','Let's talk'", text) |
58 | 58 |
59 if code == 101: # so what? | 59 if code == 101: # so what? |
60 pass | 60 pass |
61 | 61 |
62 if code == 102: # talk | 62 if code == 102: # talk |
63 name = gaim.GaimBuddyGetName(buddyid) | 63 name = purple.PurpleBuddyGetName(buddyid) |
64 account = gaim.GaimBuddyGetAccount(buddyid) | 64 account = purple.PurpleBuddyGetAccount(buddyid) |
65 gaim.GaimConversationNew(1, account, name) | 65 purple.PurpleConversationNew(1, account, name) |
66 | 66 |
67 | 67 |
68 bus = dbus.SessionBus() | 68 bus = dbus.SessionBus() |
69 obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject") | 69 obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") |
70 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface") | 70 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") |
71 | 71 |
72 bus.add_signal_receiver(receivedimmsg, | 72 bus.add_signal_receiver(receivedimmsg, |
73 dbus_interface = "net.sf.gaim.GaimInterface", | 73 dbus_interface = "im.pidgin.purple.PurpleInterface", |
74 signal_name = "ReceivedImMsg") | 74 signal_name = "ReceivedImMsg") |
75 | 75 |
76 bus.add_signal_receiver(buddysignedon, | 76 bus.add_signal_receiver(buddysignedon, |
77 dbus_interface = "net.sf.gaim.GaimInterface", | 77 dbus_interface = "im.pidgin.purple.PurpleInterface", |
78 signal_name = "BuddySignedOn") | 78 signal_name = "BuddySignedOn") |
79 | 79 |
80 print "This is a simple gaim notification server." | 80 print "This is a simple purple notification server." |
81 print "It shows notifications when your buddy signs on or you get an IM message." | 81 print "It shows notifications when your buddy signs on or you get an IM message." |
82 | 82 |
83 loop = gobject.MainLoop() | 83 loop = gobject.MainLoop() |
84 loop.run() | 84 loop.run() |
85 | 85 |