comparison src/gaim-notifications-example @ 13765:13b7e59a0759

[gaim-migrate @ 16177] SF Bug #1485718 "At Solaris ARC review, the architect committee noticed that gaim installs two files to /usr/bin with the *.py extension. These include: gaim-notifications-example.py gaim-remote.py ARC also noticed that there are no other applications in /usr/bin with this extension, and questioned whether it makes sense to add applications to the default user PATH like this. Does it make more sense to remove the .py from the filenames if you are planning to install them into PATH? They recommend changing the name for consistancy. Also, not sure it is a good idea to install example programs to /usr/bin. Perhaps gaim-notifications-example should be installed to a /usr/demo directory, or elsewhere?" I've renamed gaim-remote.py to gaim-remote and moved gaim-notifications-example to /usr/share/gaim/doc/examples. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 11 May 2006 17:02:46 +0000
parents
children
comparison
equal deleted inserted replaced
13764:8d972f41b4de 13765:13b7e59a0759
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: # talk
63 name = gaim.GaimBuddyGetName(buddyid)
64 account = gaim.GaimBuddyGetAccount(buddyid)
65 gaim.GaimConversationNew(1, account, name)
66
67
68 bus = dbus.SessionBus()
69 obj = bus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
70 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
71
72 bus.add_signal_receiver(receivedimmsg,
73 dbus_interface = "net.sf.gaim.GaimInterface",
74 signal_name = "ReceivedImMsg")
75
76 bus.add_signal_receiver(buddysignedon,
77 dbus_interface = "net.sf.gaim.GaimInterface",
78 signal_name = "BuddySignedOn")
79
80 print "This is a simple gaim notification server."
81 print "It shows notifications when your buddy signs on or you get an IM message."
82
83 loop = gobject.MainLoop()
84 loop.run()
85
86