annotate src/gaim-notifications-example.py @ 13373:1ca4a579eb57

[gaim-migrate @ 15746] Parts of sf patch #1438833, from Sadrul Habib Chowdhury "This patch enables removing message-text from a status. Currently when you have some status with a message, and you remove the message from the statusbox-entry, the new status with no message is not used (reported in a number of bugs, like #1431289, #1431801)." committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 02 Mar 2006 04:51:09 +0000
parents d323a4e74753
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11331
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
1 #!/usr/bin/env python
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
2
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
3 # This is a simple gaim notification server.
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
4 # It shows notifications when your buddy signs on or you get an IM message.
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
5 #
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
6 # This script requires Python 2.4 and PyGTK bindings
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
7 #
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
8 # Note that all function names are resolved dynamically, no
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
9 # gaim-specific library is needed.
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
10
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
11 import dbus
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
12 import dbus.glib
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
13 import dbus.decorators
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
14 import gobject
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
15 import os
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
16
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
17 def ensureimconversation(conversation, account, name):
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
18 if conversation != 0:
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
19 return conversation
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
20 else:
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
21 # 1 = GAIM_CONV_IM
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
22 return gaim.GaimConversationNew(1, account, name)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
23
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
24 def receivedimmsg(account, name, message, conversation, flags):
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
25 buddy = gaim.GaimFindBuddy(account, name)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
26 if buddy != 0:
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
27 alias = gaim.GaimBuddyGetAlias(buddy)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
28 else:
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
29 alias = name
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
30
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
31 text = "%s says %s" % (alias, message)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
32 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
33 "'So what?','Show me',Close,Abuse", text)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
34
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
35 if code == 101: # so what?
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
36 pass
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 else:
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
38 conversation = ensureimconversation(conversation, account, name)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
39
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
40 if code == 102: # show me
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
41 window = gaim.GaimConversationGetWindow(conversation)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
42 gaim.GaimConvWindowRaise(window)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
43
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
44 if code == 103: # close
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
45 gaim.GaimConversationDestroy(conversation)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
46
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
47 if code == 104: # abuse
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
48 im = gaim.GaimConversationGetImData(conversation)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
49 gaim.GaimConvImSend(im, "Go away you f...")
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
50
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
51
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
52 def buddysignedon(buddyid):
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
53 alias = gaim.GaimBuddyGetAlias(buddyid)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
54 text = "%s is online" % alias
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
55
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
56 code = os.spawnlp(os.P_WAIT, "xmessage", "xmessage", "-buttons",
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
57 "'So what?','Let's talk'", text)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
58
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
59 if code == 101: # so what?
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
60 pass
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
61
13265
d323a4e74753 [gaim-migrate @ 15631]
Richard Laager <rlaager@wiktel.com>
parents: 13220
diff changeset
62 if code == 102: # talk
11331
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
63 name = gaim.GaimBuddyGetName(buddyid)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
64 account = gaim.GaimBuddyGetAccount(buddyid)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
65 gaim.GaimConversationNew(1, account, name)
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
66
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
67
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
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
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
71
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
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
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
74 signal_name = "ReceivedImMsg")
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
75
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
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
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
78 signal_name = "BuddySignedOn")
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
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
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
82
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
83 loop = gobject.MainLoop()
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
84 loop.run()
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
85
64fadbf3810f [gaim-migrate @ 13544]
Piotr Zielinski <zielaj>
parents:
diff changeset
86