Mercurial > pidgin
comparison src/dbus-client-example.py @ 11146:1c5398ccbeb0
[gaim-migrate @ 13217]
Gaim-DBUS signal export works with DBUS >= 0.35
Various gaim API functions available through DBUS
committer: Tailor Script <tailor@pidgin.im>
| author | Piotr Zielinski <zielaj> |
|---|---|
| date | Fri, 22 Jul 2005 19:47:29 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 11145:dbc518c453f2 | 11146:1c5398ccbeb0 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # this is an example of a client that communicates with gaim using DBUS | |
| 4 # | |
| 5 # requires Python 2.4 and PyGTK bindings | |
| 6 # | |
| 7 # note that all function names are resolved dynamically, no | |
| 8 # gaim-specific library is needed | |
| 9 | |
| 10 import dbus | |
| 11 import dbus.glib | |
| 12 import dbus.decorators | |
| 13 import gobject | |
| 14 import os | |
| 15 | |
| 16 def receivedimmsg(account, name, message, conversation, flags): | |
| 17 buddy = gaim.GaimFindBuddy(account, name) | |
| 18 if buddy != 0: | |
| 19 alias = gaim.GaimBuddyGetAlias(buddy) | |
| 20 else: | |
| 21 alias = name | |
| 22 | |
| 23 text = "%s says %s" % (alias, message) | |
| 24 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | |
| 25 "'So what?','Show me',Close,Abuse", text) | |
| 26 | |
| 27 if code == 101: # so what? | |
| 28 pass | |
| 29 if code == 102: # show me | |
| 30 window = gaim.GaimConversationGetWindow(conversation) | |
| 31 gaim.GaimConvWindowRaise(window) | |
| 32 if code == 103: # close | |
| 33 gaim.GaimConversationDestroy(conversation) | |
| 34 if code == 104: # abuse | |
| 35 im = gaim.GaimConversationGetImData(conversation) | |
| 36 gaim.GaimConvImSend(im, "Go away you f...") | |
| 37 | |
| 38 | |
| 39 def buddysignedon(buddyid): | |
| 40 alias = gaim.GaimBuddyGetAlias(buddyid) | |
| 41 text = "%s is online" % alias | |
| 42 | |
| 43 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons", | |
| 44 "'So what?','Let's talk'", text) | |
| 45 | |
| 46 if code == 101: # so what? | |
| 47 pass | |
| 48 if code == 102: # let's talk | |
| 49 name = gaim.GaimBuddyGetName(buddyid) | |
| 50 account = gaim.GaimBuddyGetAccount(buddyid) | |
| 51 gaim.GaimConversationNew(1, account, name) | |
| 52 | |
| 53 | |
| 54 def talkto(buddyname, accountname, protocolname): | |
| 55 account = gaim.GaimAccountsFindConnected(accountname, protocolname) | |
| 56 if account != 0: | |
| 57 gaim.GaimConversationNew(1, account, buddyname) | |
| 58 | |
| 59 | |
| 60 bus = dbus.SessionBus() | |
| 61 obj = bus.get_object("org.gaim.GaimService", "/org/gaim/GaimObject") | |
| 62 gaim = dbus.Interface(obj, "org.gaim.GaimInterface") | |
| 63 | |
| 64 bus.add_signal_receiver(receivedimmsg, | |
| 65 dbus_interface = "org.gaim.GaimInterface", | |
| 66 signal_name = "ReceivedImMsg") | |
| 67 bus.add_signal_receiver(buddysignedon, | |
| 68 dbus_interface = "org.gaim.GaimInterface", | |
| 69 signal_name = "BuddySignedOn") | |
| 70 | |
| 71 | |
| 72 # Tell the remote object to emit the signal | |
| 73 | |
| 74 talkto("testone@localhost", "", "prpl-jabber") | |
| 75 | |
| 76 loop = gobject.MainLoop() | |
| 77 loop.run() | |
| 78 | |
| 79 |
