comparison libpurple/purple-remote @ 16143:598b1b15b199

Trac Ticket #149 from JensenDied This patch does a rename of our DBus stuff.
author Richard Laager <rlaager@wiktel.com>
date Sun, 15 Apr 2007 18:09:14 +0000
parents c6e563dfaa7a
children c36124736326
comparison
equal deleted inserted replaced
16142:74b2d576f458 16143:598b1b15b199
7 7
8 import xml.dom.minidom 8 import xml.dom.minidom
9 9
10 xml.dom.minidom.Element.all = xml.dom.minidom.Element.getElementsByTagName 10 xml.dom.minidom.Element.all = xml.dom.minidom.Element.getElementsByTagName
11 11
12 obj = dbus.SessionBus().get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject") 12 obj = dbus.SessionBus().get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
13 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface") 13 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
14 14
15 class CheckedObject: 15 class CheckedObject:
16 def __init__(self, obj): 16 def __init__(self, obj):
17 self.obj = obj 17 self.obj = obj
18 18
29 if result == 0: 29 if result == 0:
30 raise "Error: " + self.attr + " " + str(args) + " returned " + str(result) 30 raise "Error: " + self.attr + " " + str(args) + " returned " + str(result)
31 return result 31 return result
32 32
33 def show_help(): 33 def show_help():
34 print """This program uses DBus to communicate with gaim. 34 print """This program uses DBus to communicate with purple.
35 35
36 Usage: 36 Usage:
37 37
38 %s "command1" "command2" ... 38 %s "command1" "command2" ...
39 39
42 [protocol:]commandname?param1=value1&param2=value2&... 42 [protocol:]commandname?param1=value1&param2=value2&...
43 FunctionName?param1=value1&param2=value2&... 43 FunctionName?param1=value1&param2=value2&...
44 FunctionName(value1,value2,...) 44 FunctionName(value1,value2,...)
45 45
46 The second and third form are provided for completeness but their use 46 The second and third form are provided for completeness but their use
47 is not recommended; use gaim-send or gaim-send-async instead. The 47 is not recommended; use purple-send or purple-send-async instead. The
48 second form uses introspection to find out the parameter names and 48 second form uses introspection to find out the parameter names and
49 their types, therefore it is rather slow. 49 their types, therefore it is rather slow.
50 50
51 Examples of commands: 51 Examples of commands:
52 52
56 jabber:addbuddy?screenname=my friend 56 jabber:addbuddy?screenname=my friend
57 57
58 setstatus?status=away&message=don't disturb 58 setstatus?status=away&message=don't disturb
59 quit 59 quit
60 60
61 GaimAccountsFindConnected?name=&protocol=prpl-jabber 61 PurpleAccountsFindConnected?name=&protocol=prpl-jabber
62 GaimAccountFindConnected(,prpl-jabber) 62 PurpleAccountFindConnected(,prpl-jabber)
63 """ % sys.argv[0] 63 """ % sys.argv[0]
64 64
65 cgaim = CheckedObject(gaim) 65 cpurple = CheckedObject(purple)
66 66
67 urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?" 67 urlregexp = r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"
68 68
69 def extendlist(list, length, fill): 69 def extendlist(list, length, fill):
70 if len(list) < length: 70 if len(list) < length:
79 return value 79 return value
80 80
81 def findaccount(accountname, protocolname): 81 def findaccount(accountname, protocolname):
82 try: 82 try:
83 # prefer connected accounts 83 # prefer connected accounts
84 account = cgaim.GaimAccountsFindConnected(accountname, protocolname) 84 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
85 return account 85 return account
86 except: 86 except:
87 # try to get any account and connect it 87 # try to get any account and connect it
88 account = cgaim.GaimAccountsFindAny(accountname, protocolname) 88 account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
89 gaim.GaimAccountSetStatusVargs(account, "online", 1) 89 purple.PurpleAccountSetStatusVargs(account, "online", 1)
90 gaim.GaimAccountConnect(account) 90 purple.PurpleAccountConnect(account)
91 return account 91 return account
92 92
93 93
94 def execute(uri): 94 def execute(uri):
95 match = re.match(urlregexp, uri) 95 match = re.match(urlregexp, uri)
108 108
109 accountname = params.get("account", "") 109 accountname = params.get("account", "")
110 110
111 if command == "goim": 111 if command == "goim":
112 account = findaccount(accountname, protocol) 112 account = findaccount(accountname, protocol)
113 conversation = cgaim.GaimConversationNew(1, account, params["screenname"]) 113 conversation = cpurple.PurpleConversationNew(1, account, params["screenname"])
114 if "message" in params: 114 if "message" in params:
115 im = cgaim.GaimConversationGetImData(conversation) 115 im = cpurple.PurpleConversationGetImData(conversation)
116 gaim.GaimConvImSend(im, params["message"]) 116 purple.PurpleConvImSend(im, params["message"])
117 return None 117 return None
118 118
119 elif command == "gochat": 119 elif command == "gochat":
120 account = findaccount(accountname, protocol) 120 account = findaccount(accountname, protocol)
121 connection = cgaim.GaimAccountGetConnection(account) 121 connection = cpurple.PurpleAccountGetConnection(account)
122 return gaim.ServJoinChat(connection, params) 122 return purple.ServJoinChat(connection, params)
123 123
124 elif command == "addbuddy": 124 elif command == "addbuddy":
125 account = findaccount(accountname, protocol) 125 account = findaccount(accountname, protocol)
126 return cgaim.GaimBlistRequestAddBuddy(account, params["screenname"], 126 return cpurple.PurpleBlistRequestAddBuddy(account, params["screenname"],
127 params.get("group", ""), "") 127 params.get("group", ""), "")
128 128
129 elif command == "setstatus": 129 elif command == "setstatus":
130 current = gaim.GaimSavedstatusGetCurrent() 130 current = purple.PurpleSavedstatusGetCurrent()
131 131
132 if "status" in params: 132 if "status" in params:
133 status_id = params["status"] 133 status_id = params["status"]
134 status_type = gaim.GaimPrimitiveGetTypeFromId(status_id) 134 status_type = purple.PurplePrimitiveGetTypeFromId(status_id)
135 else: 135 else:
136 status_type = gaim.GaimSavedstatusGetType(current) 136 status_type = purple.PurpleSavedstatusGetType(current)
137 status_id = gaim.GaimPrimitiveGetIdFromType(status_type) 137 status_id = purple.PurplePrimitiveGetIdFromType(status_type)
138 138
139 if "message" in params: 139 if "message" in params:
140 message = params["message"]; 140 message = params["message"];
141 else: 141 else:
142 message = gaim.GaimSavedstatusGetMessage(current) 142 message = purple.PurpleSavedstatusGetMessage(current)
143 143
144 if "account" in params: 144 if "account" in params:
145 accounts = [cgaim.GaimAccountsFindAny(accountname, protocol)] 145 accounts = [cpurple.PurpleAccountsFindAny(accountname, protocol)]
146 146
147 for account in accounts: 147 for account in accounts:
148 status = gaim.GaimAccountGetStatus(account, status_id) 148 status = purple.PurpleAccountGetStatus(account, status_id)
149 type = gaim.GaimStatusGetType(status) 149 type = purple.PurpleStatusGetType(status)
150 gaim.GaimSavedstatusSetSubstatus(current, account, type, message) 150 purple.PurpleSavedstatusSetSubstatus(current, account, type, message)
151 gaim.GaimSavedstatusActivateForAccount(current, account) 151 purple.PurpleSavedstatusActivateForAccount(current, account)
152 else: 152 else:
153 accounts = gaim.GaimAccountsGetAllActive() 153 accounts = purple.PurpleAccountsGetAllActive()
154 saved = gaim.GaimSavedstatusNew("", status_type) 154 saved = purple.PurpleSavedstatusNew("", status_type)
155 gaim.GaimSavedstatusSetMessage(saved, message) 155 purple.PurpleSavedstatusSetMessage(saved, message)
156 gaim.GaimSavedstatusActivate(saved) 156 purple.PurpleSavedstatusActivate(saved)
157 157
158 return None 158 return None
159 159
160 elif command == "getinfo": 160 elif command == "getinfo":
161 account = findaccount(accountname, protocol) 161 account = findaccount(accountname, protocol)
162 connection = cgaim.GaimAccountGetConnection(account) 162 connection = cpurple.PurpleAccountGetConnection(account)
163 return gaim.ServGetInfo(connection, params["screenname"]) 163 return purple.ServGetInfo(connection, params["screenname"])
164 164
165 elif command == "quit": 165 elif command == "quit":
166 return gaim.GaimCoreQuit() 166 return purple.PurpleCoreQuit()
167 167
168 elif command == "uri": 168 elif command == "uri":
169 return None 169 return None
170 170
171 else: 171 else:
178 else: 178 else:
179 args = argstr.split(",") 179 args = argstr.split(",")
180 fargs = [] 180 fargs = []
181 for arg in args: 181 for arg in args:
182 fargs.append(convert(arg.strip())) 182 fargs.append(convert(arg.strip()))
183 return gaim.__getattr__(name)(*fargs) 183 return purple.__getattr__(name)(*fargs)
184 else: 184 else:
185 # introspect the object to get parameter names and types 185 # introspect the object to get parameter names and types
186 # this is slow because the entire introspection info must be downloaded 186 # this is slow because the entire introspection info must be downloaded
187 data = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable").\ 187 data = dbus.Interface(obj, "org.freedesktop.DBus.Introspectable").\
188 Introspect() 188 Introspect()
198 methodparams.append(value) 198 methodparams.append(value)
199 elif type == "i": 199 elif type == "i":
200 methodparams.append(int(value)) 200 methodparams.append(int(value))
201 else: 201 else:
202 raise "Don't know how to handle type \"%s\"" % type 202 raise "Don't know how to handle type \"%s\"" % type
203 return gaim.__getattr__(command)(*methodparams) 203 return purple.__getattr__(command)(*methodparams)
204 show_help() 204 show_help()
205 raise "Unknown command: %s" % command 205 raise "Unknown command: %s" % command
206 206
207 if len(sys.argv) == 1: 207 if len(sys.argv) == 1:
208 show_help() 208 show_help()