annotate src/dbus-client-example.py @ 11193:e865bdbbf91d

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