pidgin: 5bf806cf: Give findaccount an option 'matcher' cal...
resiak at pidgin.im
resiak at pidgin.im
Thu Jul 3 13:41:50 EDT 2008
-----------------------------------------------------------------
Revision: 5bf806cffab0dd258fb031a859123fdbd5f63198
Ancestor: ecca56677b874f6fc528aa97dc3bb49118c6483e
Author: resiak at pidgin.im
Date: 2008-07-03T17:19:46
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5bf806cffab0dd258fb031a859123fdbd5f63198
Modified files:
libpurple/purple-url-handler
ChangeLog:
Give findaccount an option 'matcher' callback parameter, to match arbitrary
account properties. In passing, fix bringing offline accounts online: there's
no such method as PurpleAccountSetStatusVargs.
-------------- next part --------------
============================================================
--- libpurple/purple-url-handler 6f3d8d3629829318c883f9e1168c1554d8a7eade
+++ libpurple/purple-url-handler fed3e84d2b12137899fb4a2218792323b231ddfa
@@ -58,20 +58,39 @@ def convert(value):
except:
return value
-def findaccount(protocolname, accountname=""):
+def account_not_found():
+ print "No matching account found."
+ sys.exit(1)
+
+def bring_account_online(account):
+ if not cpurple.PurpleAccountIsConnected(account):
+ # The last argument is meant to be a GList * but the D-Bus binding
+ # generator thing just wants a UInt32, which is pretty failing.
+ # Happily, passing a 0 to mean an empty list turns out to work anyway.
+ purple.PurpleAccountSetStatusList(account, "online", 1, 0)
+ purple.PurpleAccountConnect(account)
+
+def findaccount(protocolname, accountname="", matcher=None):
+ if matcher:
+ for account in cpurple.PurpleAccountsGetAll():
+ if accountname != "" and accountname != cpurple.PurpleAccountGetUsername(a):
+ continue
+ if matcher(account):
+ bring_account_online(account)
+ return account
+ account_not_found()
+
# prefer connected accounts
account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
if (account != 0):
- return account
+ return account
# try to get any account and connect it
account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
if (account == 0):
- print "No matching account found."
- sys.exit(1)
+ account_not_found()
- purple.PurpleAccountSetStatusVargs(account, "online", 1)
- purple.PurpleAccountConnect(account)
+ bring_account_online(account)
return account
def goim(account, screenname, message=None):
More information about the Commits
mailing list