Mercurial > pidgin
annotate src/gaim-notifications-example.py @ 13588:bbf2e601be82
[gaim-migrate @ 15973]
this should make configure _NOT_ fail on systems where dbus isn't installed. It's a bit messy buy should work fine..
committer: Tailor Script <tailor@pidgin.im>
| author | Gary Kramlich <grim@reaperworld.com> |
|---|---|
| date | Thu, 06 Apr 2006 22:28:22 +0000 |
| parents | d323a4e74753 |
| children |
| rev | line source |
|---|---|
| 11331 | 1 #!/usr/bin/env python |
| 2 | |
| 3 # This is a simple gaim notification server. | |
| 4 # It shows notifications when your buddy signs on or you get an IM message. | |
| 5 # | |
| 6 # This script requires Python 2.4 and PyGTK bindings | |
| 7 # | |
| 8 # Note that all function names are resolved dynamically, no | |
| 9 # gaim-specific library is needed. | |
| 10 | |
| 11 import dbus | |
| 12 import dbus.glib | |
| 13 import dbus.decorators | |
| 14 import gobject | |
| 15 import os | |
| 16 | |
| 17 def ensureimconversation(conversation, account, name): | |
| 18 if conversation != 0: | |
| 19 return conversation | |
| 20 else: | |
| 21 # 1 = GAIM_CONV_IM | |
| 22 return gaim.GaimConversationNew(1, account, name) | |
| 23 | |
| 24 def receivedimmsg(account, name, message, conversation, flags): | |
| 25 buddy = gaim.GaimFindBuddy(account, name) | |
| 26 if buddy != 0: | |
| 27 alias = gaim.GaimBuddyGetAlias(buddy) | |
| 28 else: | |
| 29 alias = name | |
| 30 | |
| 31 text = "%s says %s" % (alias, message) | |
| 32 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | |
| 33 "'So what?','Show me',Close,Abuse", text) | |
| 34 | |
| 35 if code == 101: # so what? | |
| 36 pass | |
| 37 else: | |
| 38 conversation = ensureimconversation(conversation, account, name) | |
| 39 | |
| 40 if code == 102: # show me | |
| 41 window = gaim.GaimConversationGetWindow(conversation) | |
| 42 gaim.GaimConvWindowRaise(window) | |
| 43 | |
| 44 if code == 103: # close | |
| 45 gaim.GaimConversationDestroy(conversation) | |
| 46 | |
| 47 if code == 104: # abuse | |
| 48 im = gaim.GaimConversationGetImData(conversation) | |
| 49 gaim.GaimConvImSend(im, "Go away you f...") | |
| 50 | |
| 51 | |
| 52 def buddysignedon(buddyid): | |
| 53 alias = gaim.GaimBuddyGetAlias(buddyid) | |
| 54 text = "%s is online" % alias | |
| 55 | |
| 56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | |
| 57 "'So what?','Let's talk'", text) | |
| 58 | |
| 59 if code == 101: # so what? | |
| 60 pass | |
| 61 | |
|
13265
d323a4e74753
[gaim-migrate @ 15631]
Richard Laager <rlaager@wiktel.com>
parents:
13220
diff
changeset
|
62 if code == 102: # talk |
| 11331 | 63 name = gaim.GaimBuddyGetName(buddyid) |
| 64 account = gaim.GaimBuddyGetAccount(buddyid) | |
| 65 gaim.GaimConversationNew(1, account, name) | |
| 66 | |
| 67 | |
| 68 bus = dbus.SessionBus() | |
|
13220
ac5bc9a7b603
[gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents:
11331
diff
changeset
|
69 obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject") |
|
ac5bc9a7b603
[gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents:
11331
diff
changeset
|
70 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface") |
| 11331 | 71 |
| 72 bus.add_signal_receiver(receivedimmsg, | |
|
13220
ac5bc9a7b603
[gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents:
11331
diff
changeset
|
73 dbus_interface = "net.sf.gaim.GaimInterface", |
| 11331 | 74 signal_name = "ReceivedImMsg") |
| 75 | |
| 76 bus.add_signal_receiver(buddysignedon, | |
|
13220
ac5bc9a7b603
[gaim-migrate @ 15584]
Richard Laager <rlaager@wiktel.com>
parents:
11331
diff
changeset
|
77 dbus_interface = "net.sf.gaim.GaimInterface", |
| 11331 | 78 signal_name = "BuddySignedOn") |
| 79 | |
|
13265
d323a4e74753
[gaim-migrate @ 15631]
Richard Laager <rlaager@wiktel.com>
parents:
13220
diff
changeset
|
80 print "This is a simple gaim notification server." |
|
d323a4e74753
[gaim-migrate @ 15631]
Richard Laager <rlaager@wiktel.com>
parents:
13220
diff
changeset
|
81 print "It shows notifications when your buddy signs on or you get an IM message." |
| 11331 | 82 |
| 83 loop = gobject.MainLoop() | |
| 84 loop.run() | |
| 85 | |
| 86 |
