| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | class AccountManager: |
|---|
| 10 | """I am responsible for managing a user's accounts. |
|---|
| 11 | |
|---|
| 12 | That is, remembering what accounts are available, their settings, |
|---|
| 13 | adding and removal of accounts, etc. |
|---|
| 14 | |
|---|
| 15 | @ivar accounts: A collection of available accounts. |
|---|
| 16 | @type accounts: mapping of strings to L{Account<interfaces.IAccount>}s. |
|---|
| 17 | """ |
|---|
| 18 | def __init__(self): |
|---|
| 19 | self.accounts = {} |
|---|
| 20 | |
|---|
| 21 | def getSnapShot(self): |
|---|
| 22 | """A snapshot of all the accounts and their status. |
|---|
| 23 | |
|---|
| 24 | @returns: A list of tuples, each of the form |
|---|
| 25 | (string:accountName, boolean:isOnline, |
|---|
| 26 | boolean:autoLogin, string:gatewayType) |
|---|
| 27 | """ |
|---|
| 28 | data = [] |
|---|
| 29 | for account in self.accounts.values(): |
|---|
| 30 | data.append((account.accountName, account.isOnline(), |
|---|
| 31 | account.autoLogin, account.gatewayType)) |
|---|
| 32 | return data |
|---|
| 33 | |
|---|
| 34 | def isEmpty(self): |
|---|
| 35 | return len(self.accounts) == 0 |
|---|
| 36 | |
|---|
| 37 | def getConnectionInfo(self): |
|---|
| 38 | connectioninfo = [] |
|---|
| 39 | for account in self.accounts.values(): |
|---|
| 40 | connectioninfo.append(account.isOnline()) |
|---|
| 41 | return connectioninfo |
|---|
| 42 | |
|---|
| 43 | def addAccount(self, account): |
|---|
| 44 | self.accounts[account.accountName] = account |
|---|
| 45 | |
|---|
| 46 | def delAccount(self, accountName): |
|---|
| 47 | del self.accounts[accountName] |
|---|
| 48 | |
|---|
| 49 | def connect(self, accountName, chatui): |
|---|
| 50 | """ |
|---|
| 51 | @returntype: Deferred L{interfaces.IClient} |
|---|
| 52 | """ |
|---|
| 53 | return self.accounts[accountName].logOn(chatui) |
|---|
| 54 | |
|---|
| 55 | def disconnect(self, accountName): |
|---|
| 56 | pass |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | def quit(self): |
|---|
| 60 | pass |
|---|
| 61 | |
|---|
| 62 | |
|---|