Mercurial > pidgin.yaz
comparison libpurple/purple-url-handler @ 23422: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 |
comparison
equal
deleted
inserted
replaced
23421:0565c227608d | 23422:0c66344d0ed5 |
---|---|
56 try: | 56 try: |
57 return int(value) | 57 return int(value) |
58 except: | 58 except: |
59 return value | 59 return value |
60 | 60 |
61 def findaccount(protocolname, accountname=""): | 61 def account_not_found(): |
62 print "No matching account found." | |
63 sys.exit(1) | |
64 | |
65 def bring_account_online(account): | |
66 if not cpurple.PurpleAccountIsConnected(account): | |
67 # The last argument is meant to be a GList * but the D-Bus binding | |
68 # generator thing just wants a UInt32, which is pretty failing. | |
69 # Happily, passing a 0 to mean an empty list turns out to work anyway. | |
70 purple.PurpleAccountSetStatusList(account, "online", 1, 0) | |
71 purple.PurpleAccountConnect(account) | |
72 | |
73 def findaccount(protocolname, accountname="", matcher=None): | |
74 if matcher: | |
75 for account in cpurple.PurpleAccountsGetAll(): | |
76 if accountname != "" and accountname != cpurple.PurpleAccountGetUsername(a): | |
77 continue | |
78 if matcher(account): | |
79 bring_account_online(account) | |
80 return account | |
81 account_not_found() | |
82 | |
62 # prefer connected accounts | 83 # prefer connected accounts |
63 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) | 84 account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) |
64 if (account != 0): | 85 if (account != 0): |
65 return account | 86 return account |
66 | 87 |
67 # try to get any account and connect it | 88 # try to get any account and connect it |
68 account = cpurple.PurpleAccountsFindAny(accountname, protocolname) | 89 account = cpurple.PurpleAccountsFindAny(accountname, protocolname) |
69 if (account == 0): | 90 if (account == 0): |
70 print "No matching account found." | 91 account_not_found() |
71 sys.exit(1) | 92 |
72 | 93 bring_account_online(account) |
73 purple.PurpleAccountSetStatusVargs(account, "online", 1) | |
74 purple.PurpleAccountConnect(account) | |
75 return account | 94 return account |
76 | 95 |
77 def goim(account, screenname, message=None): | 96 def goim(account, screenname, message=None): |
78 # XXX: 1 == PURPLE_CONV_TYPE_IM | 97 # XXX: 1 == PURPLE_CONV_TYPE_IM |
79 conversation = cpurple.PurpleConversationNew(1, account, screenname) | 98 conversation = cpurple.PurpleConversationNew(1, account, screenname) |