Mercurial > pidgin
annotate src/gaim-notifications-example.py @ 13253:87a7c3077c19
[gaim-migrate @ 15619]
More cleaning up of oscar. Renamed some functions to be more clear.
Got rid of some stuff that wasn't used. Inlined some small things
in conn.c that were only used once.
The goals of all this are
1. Non-blocking I/O for all connections
2. p2p stuff won't use the same struct as oscar connections, because
that's stupid
3. The oscar PRPL should be less scary
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 12 Feb 2006 21:27:04 +0000 |
| parents | ac5bc9a7b603 |
| children | d323a4e74753 |
| 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 | |
| 62 if code == 102: # let's talk | |
| 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 | |
| 80 print """This is a simple gaim notification server. | |
| 81 It shows notifications when your buddy signs on or you get an IM message.""" | |
| 82 | |
| 83 loop = gobject.MainLoop() | |
| 84 loop.run() | |
| 85 | |
| 86 |
