Mercurial > pidgin
changeset 23420:0c66344d0ed5
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.
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Thu, 03 Jul 2008 17:19:46 +0000 |
parents | 0565c227608d |
children | 668b62240235 |
files | libpurple/purple-url-handler |
diffstat | 1 files changed, 25 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/purple-url-handler Thu Jul 03 15:38:49 2008 +0000 +++ b/libpurple/purple-url-handler Thu Jul 03 17:19:46 2008 +0000 @@ -58,20 +58,39 @@ 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):